From 15947f942cde5902d01f89e8f574a232f8f1f025 Mon Sep 17 00:00:00 2001 From: Joao Ramos Date: Wed, 13 Dec 2023 17:08:26 +0000 Subject: [PATCH] Fixed issue with payment records on update --- src/interfaces/paypal.ts | 2 +- src/pages/api/users/update.ts | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/interfaces/paypal.ts b/src/interfaces/paypal.ts index 4305b960..2278e284 100644 --- a/src/interfaces/paypal.ts +++ b/src/interfaces/paypal.ts @@ -31,5 +31,5 @@ export interface Payment { currency: string; value: number; isPaid: boolean; - date: Date; + date: Date | string; } diff --git a/src/pages/api/users/update.ts b/src/pages/api/users/update.ts index c75ae980..7d3de267 100644 --- a/src/pages/api/users/update.ts +++ b/src/pages/api/users/update.ts @@ -22,13 +22,14 @@ export default withIronSessionApiRoute(handler, sessionOptions); // because the id is not a par of the hash and payment expects date to be of type Date // but if it is not inserted as a string, some UI components will not work (Invalid Date) const addPaymentRecord = async (data: any) => { - const shortUID = new ShortUniqueId(); - await setDoc(doc(db, "payments", shortUID.randomUUID(8)), data); + await setDoc(doc(db, "payments", data.id), data); } const managePaymentRecords = async (user: User, userId: string | undefined): Promise => { try { if(user.type === 'corporate' && userId) { - const data = { + const shortUID = new ShortUniqueId(); + const data: Payment = { + id: shortUID.randomUUID(8), corporate: userId, agent: user.corporateInformation.referralAgent, agentCommission: user.corporateInformation.payment!.commission,