Fixed issue with payment records on update

This commit is contained in:
Joao Ramos
2023-12-13 17:08:26 +00:00
parent 1cff6fe242
commit 15947f942c
2 changed files with 5 additions and 4 deletions

View File

@@ -31,5 +31,5 @@ export interface Payment {
currency: string;
value: number;
isPaid: boolean;
date: Date;
date: Date | string;
}

View File

@@ -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<boolean> => {
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,