Prisma Transaction sometime not update all properties

A function is declare in the next.js 14 server action when I call this function with the verified=”approve” ,id=1, data={payload:”bankAccount”,id:1} it does not update the bank account while all thing working and updating other tables, while it is in transaction why this happening, what is the problem may answer it.

export const verifiedPartnerDepositionPayment = createServerAction(

async ({ id, verified, data }) => {

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>let VerifiedPartnerDeposition;
const session = await auth();
let actions = {};
if (verified === "approved") {
actions = {
ppwd_approval: { connect: { u_id: Number(session?.user?.id) } },
};
}
if (verified === "verified") {
actions = {
ppwd_verifier: { connect: { u_id: Number(session?.user?.id) } },
};
}
if (verified !== "approved" && !!!data) {
VerifiedPartnerDeposition =
await prisma.payment_partner_withdrawals_deposition.update({
where: { ppwd_id: id * 1 },
data: { ppwd_status: verified, ...actions },
include: { ppwd_partner_with: { select: { pwd_gnt_id: true } } },
});
if (verified === "verified" && session?.user?.role !== "admin") {
const adnotfiy = await AddNotification({
resourceTitle: "Partner Deposition Payment",
action: verified,
user: session,
resource: VerifiedPartnerDeposition.ppwd_partner_with?.pwd_gnt_id,
department: "fi",
link: "fi/partner_fund",
});
}
} else {
const payment = await prisma.$transaction(async (tx) => {
// Find Partner Deposition
const findPartnerDepositionPayment =
await tx.payment_partner_withdrawals_deposition.findUnique({
where: { ppwd_id: id * 1 },
include: {
ppwd_partner_with: {
select: {
pwd_gnt_id: true,
pwd_id: true,
},
},
// sm_project: { select: { pj_id: true, pj_gnt_id: true } },
},
});
if (!findPartnerDepositionPayment)
throw new ServerActionError("Partner Deposition Payement not found");
const partnerDeposit =
await tx.partners_withdrawals_deposition.findUnique({
where: {
pwd_id: findPartnerDepositionPayment.ppwd_partner_with?.pwd_id,
},
select: {
pwd_payment: { select: { ppwd_amount: true, ppwd_status: true } },
pwd_gnt_id: true,
},
});
const totalDeposit = partnerDeposit?.pwd_payment
.filter((el) => el.ppwd_status === "approved")
.reduce((prev, cur) => prev + cur.ppwd_amount, 0);
if (totalDeposit === undefined)
throw new ServerActionError(
"Partner Deposition Amount Left not found"
);
// PAYMENT FOR HQ OR MAIN OFFICE
if (data.payload === "bankAccount") {
// Find Bank account Type
const findAccount = await tx.bank_accounts.findUnique({
where: { ba_id: data.id },
});
if (!findAccount)
throw new ServerActionError("Bank Account not found");
// Check for ‌Budget Type amount
</code>
<code>let VerifiedPartnerDeposition; const session = await auth(); let actions = {}; if (verified === "approved") { actions = { ppwd_approval: { connect: { u_id: Number(session?.user?.id) } }, }; } if (verified === "verified") { actions = { ppwd_verifier: { connect: { u_id: Number(session?.user?.id) } }, }; } if (verified !== "approved" && !!!data) { VerifiedPartnerDeposition = await prisma.payment_partner_withdrawals_deposition.update({ where: { ppwd_id: id * 1 }, data: { ppwd_status: verified, ...actions }, include: { ppwd_partner_with: { select: { pwd_gnt_id: true } } }, }); if (verified === "verified" && session?.user?.role !== "admin") { const adnotfiy = await AddNotification({ resourceTitle: "Partner Deposition Payment", action: verified, user: session, resource: VerifiedPartnerDeposition.ppwd_partner_with?.pwd_gnt_id, department: "fi", link: "fi/partner_fund", }); } } else { const payment = await prisma.$transaction(async (tx) => { // Find Partner Deposition const findPartnerDepositionPayment = await tx.payment_partner_withdrawals_deposition.findUnique({ where: { ppwd_id: id * 1 }, include: { ppwd_partner_with: { select: { pwd_gnt_id: true, pwd_id: true, }, }, // sm_project: { select: { pj_id: true, pj_gnt_id: true } }, }, }); if (!findPartnerDepositionPayment) throw new ServerActionError("Partner Deposition Payement not found"); const partnerDeposit = await tx.partners_withdrawals_deposition.findUnique({ where: { pwd_id: findPartnerDepositionPayment.ppwd_partner_with?.pwd_id, }, select: { pwd_payment: { select: { ppwd_amount: true, ppwd_status: true } }, pwd_gnt_id: true, }, }); const totalDeposit = partnerDeposit?.pwd_payment .filter((el) => el.ppwd_status === "approved") .reduce((prev, cur) => prev + cur.ppwd_amount, 0); if (totalDeposit === undefined) throw new ServerActionError( "Partner Deposition Amount Left not found" ); // PAYMENT FOR HQ OR MAIN OFFICE if (data.payload === "bankAccount") { // Find Bank account Type const findAccount = await tx.bank_accounts.findUnique({ where: { ba_id: data.id }, }); if (!findAccount) throw new ServerActionError("Bank Account not found"); // Check for ‌Budget Type amount </code>
let VerifiedPartnerDeposition;


const session = await auth();





let actions = {};


if (verified === "approved") {


  actions = {


    ppwd_approval: { connect: { u_id: Number(session?.user?.id) } },


  };


}


if (verified === "verified") {


  actions = {


    ppwd_verifier: { connect: { u_id: Number(session?.user?.id) } },


  };


}





if (verified !== "approved" && !!!data) {


  VerifiedPartnerDeposition =


    await prisma.payment_partner_withdrawals_deposition.update({


      where: { ppwd_id: id * 1 },


      data: { ppwd_status: verified, ...actions },


      include: { ppwd_partner_with: { select: { pwd_gnt_id: true } } },


    });


  if (verified === "verified" && session?.user?.role !== "admin") {


    const adnotfiy = await AddNotification({


      resourceTitle: "Partner Deposition Payment",


      action: verified,


      user: session,


      resource: VerifiedPartnerDeposition.ppwd_partner_with?.pwd_gnt_id,


      department: "fi",


      link: "fi/partner_fund",


    });


  }


} else {


  const payment = await prisma.$transaction(async (tx) => {


    // Find Partner Deposition


    const findPartnerDepositionPayment =


      await tx.payment_partner_withdrawals_deposition.findUnique({


        where: { ppwd_id: id * 1 },


        include: {


          ppwd_partner_with: {


            select: {


              pwd_gnt_id: true,


              pwd_id: true,


            },


          },


          // sm_project: { select: { pj_id: true, pj_gnt_id: true } },


        },


      });


    if (!findPartnerDepositionPayment)


      throw new ServerActionError("Partner Deposition Payement not found");


    const partnerDeposit =


      await tx.partners_withdrawals_deposition.findUnique({


        where: {


          pwd_id: findPartnerDepositionPayment.ppwd_partner_with?.pwd_id,


        },


        select: {


          pwd_payment: { select: { ppwd_amount: true, ppwd_status: true } },


          pwd_gnt_id: true,


        },


      });


    const totalDeposit = partnerDeposit?.pwd_payment


      .filter((el) => el.ppwd_status === "approved")


      .reduce((prev, cur) => prev + cur.ppwd_amount, 0);





    if (totalDeposit === undefined)


      throw new ServerActionError(


        "Partner Deposition Amount Left not found"


      );





    // PAYMENT FOR HQ OR MAIN OFFICE


    if (data.payload === "bankAccount") {


      // Find Bank account Type


      const findAccount = await tx.bank_accounts.findUnique({


        where: { ba_id: data.id },


      });





      if (!findAccount)


        throw new ServerActionError("Bank Account not found");


      // Check for ‌Budget Type amount

if (findAccount.ba_amount < data.pcl_amount) {

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> throw new ServerActionError(
Bank Account No:${findAccount.ba_account_number?.toUpperCase()} does't enough amount
);
}
const updateBankAccount = await tx.bank_accounts.update({
where: { ba_id: findAccount.ba_id },
data: {
ba_amount: {
increment: findPartnerDepositionPayment.ppwd_amount,
},
},
});
// Create withdraw from bank withdrawal
const lastRow = await prisma.bank_infos.findFirst({
select: {
bi_id: true,
},
orderBy: {
bi_id: "desc",
},
});
const gnt_id = generateModernId(
${systemId}-D-,
lastRow ? lastRow.bi_id + 1 : 1
);
const addWithdrawal = await tx.bank_infos.create({
data: {
bi_gnt_id: gnt_id,
bi_amount: findPartnerDepositionPayment.ppwd_amount,
bi_type: "deposit",
bi_description: Partner Deposition payment (${partnerDeposit?.pwd_gnt_id?.toUpperCase()}),
bi_bank: { connect: { ba_id: findAccount.ba_id } },
bi_open_balance: updateBankAccount.ba_amount,
bi_user: { connect: { u_id: Number(session?.user?.id) } },
},
});
// Create Partner Deposition Logs
</code>
<code> throw new ServerActionError( Bank Account No:${findAccount.ba_account_number?.toUpperCase()} does't enough amount ); } const updateBankAccount = await tx.bank_accounts.update({ where: { ba_id: findAccount.ba_id }, data: { ba_amount: { increment: findPartnerDepositionPayment.ppwd_amount, }, }, }); // Create withdraw from bank withdrawal const lastRow = await prisma.bank_infos.findFirst({ select: { bi_id: true, }, orderBy: { bi_id: "desc", }, }); const gnt_id = generateModernId( ${systemId}-D-, lastRow ? lastRow.bi_id + 1 : 1 ); const addWithdrawal = await tx.bank_infos.create({ data: { bi_gnt_id: gnt_id, bi_amount: findPartnerDepositionPayment.ppwd_amount, bi_type: "deposit", bi_description: Partner Deposition payment (${partnerDeposit?.pwd_gnt_id?.toUpperCase()}), bi_bank: { connect: { ba_id: findAccount.ba_id } }, bi_open_balance: updateBankAccount.ba_amount, bi_user: { connect: { u_id: Number(session?.user?.id) } }, }, }); // Create Partner Deposition Logs </code>
        throw new ServerActionError(


          Bank Account No:${findAccount.ba_account_number?.toUpperCase()} does't enough amount


        );


      }


      const updateBankAccount = await tx.bank_accounts.update({


        where: { ba_id: findAccount.ba_id },


        data: {


          ba_amount: {


            increment: findPartnerDepositionPayment.ppwd_amount,


          },


        },


      });





      // Create withdraw from bank withdrawal


      const lastRow = await prisma.bank_infos.findFirst({


        select: {


          bi_id: true,


        },


        orderBy: {


          bi_id: "desc",


        },


      });





      const gnt_id = generateModernId(


        ${systemId}-D-,


        lastRow ? lastRow.bi_id + 1 : 1


      );


      const addWithdrawal = await tx.bank_infos.create({


        data: {


          bi_gnt_id: gnt_id,


          bi_amount: findPartnerDepositionPayment.ppwd_amount,


          bi_type: "deposit",


          bi_description: Partner Deposition payment (${partnerDeposit?.pwd_gnt_id?.toUpperCase()}),


          bi_bank: { connect: { ba_id: findAccount.ba_id } },


          bi_open_balance: updateBankAccount.ba_amount,


          bi_user: { connect: { u_id: Number(session?.user?.id) } },


        },


      });


      // Create Partner Deposition Logs

const PartnerDepositionLogs =

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> await tx.payment_partner_withdrawals_deposition.update({
data: {
ppwd_status: verified,
ppwd_bank_acount: { connect: { ba_id: findAccount.ba_id } },
...actions,
},
where: { ppwd_id: findPartnerDepositionPayment.ppwd_id },
include: {
ppwd_partner_with: { select: { pwd_gnt_id: true } },
},
});
if (verified === "approved" && session?.user?.role !== "admin") {
const adnotfiy = await AddNotification({
resourceTitle: "Partner Deposition Payment",
action: verified,
user: session,
resource: PartnerDepositionLogs.ppwd_partner_with?.pwd_gnt_id,
department: "fi",
link: "fi/partner_fund",
});
}
return { addWithdrawal };
}
});
return { payment };
}
revalidatePath("/dashboard/fi/loan_fund");
return { VerifiedPartnerDeposition };
</code>
<code> await tx.payment_partner_withdrawals_deposition.update({ data: { ppwd_status: verified, ppwd_bank_acount: { connect: { ba_id: findAccount.ba_id } }, ...actions, }, where: { ppwd_id: findPartnerDepositionPayment.ppwd_id }, include: { ppwd_partner_with: { select: { pwd_gnt_id: true } }, }, }); if (verified === "approved" && session?.user?.role !== "admin") { const adnotfiy = await AddNotification({ resourceTitle: "Partner Deposition Payment", action: verified, user: session, resource: PartnerDepositionLogs.ppwd_partner_with?.pwd_gnt_id, department: "fi", link: "fi/partner_fund", }); } return { addWithdrawal }; } }); return { payment }; } revalidatePath("/dashboard/fi/loan_fund"); return { VerifiedPartnerDeposition }; </code>
        await tx.payment_partner_withdrawals_deposition.update({


          data: {


            ppwd_status: verified,


            ppwd_bank_acount: { connect: { ba_id: findAccount.ba_id } },


            ...actions,


          },


          where: { ppwd_id: findPartnerDepositionPayment.ppwd_id },


          include: {


            ppwd_partner_with: { select: { pwd_gnt_id: true } },


          },


        });


      if (verified === "approved" && session?.user?.role !== "admin") {


        const adnotfiy = await AddNotification({


          resourceTitle: "Partner Deposition Payment",


          action: verified,


          user: session,


          resource: PartnerDepositionLogs.ppwd_partner_with?.pwd_gnt_id,


          department: "fi",


          link: "fi/partner_fund",


        });


      }


      return { addWithdrawal };


    }


  });


  return { payment };


}


revalidatePath("/dashboard/fi/loan_fund");


return { VerifiedPartnerDeposition };

}

);

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật