feat: update contact to be nullable when request

This commit is contained in:
Methapon2001 2024-04-19 09:33:05 +07:00
parent 030aa687e1
commit b814537083

View file

@ -36,7 +36,7 @@ type BranchCreate = {
zipCode: string; zipCode: string;
email: string; email: string;
contactName?: string | null; contactName?: string | null;
contact: string | string[]; contact?: string | string[] | null;
telephoneNo: string; telephoneNo: string;
lineId?: string | null; lineId?: string | null;
longitude: string; longitude: string;
@ -59,7 +59,7 @@ type BranchUpdate = {
email?: string; email?: string;
telephoneNo: string; telephoneNo: string;
contactName?: string; contactName?: string;
contact?: string | string[]; contact?: string | string[] | null;
lineId?: string; lineId?: string;
longitude?: string; longitude?: string;
latitude?: string; latitude?: string;
@ -382,14 +382,15 @@ export class BranchController extends Controller {
where: { id: branchId }, where: { id: branchId },
}); });
if (record && contact) { if (record && contact !== undefined) {
await prisma.branchContact.deleteMany({ where: { branchId } }); await prisma.branchContact.deleteMany({ where: { branchId } });
await prisma.branchContact.createMany({ contact &&
data: (await prisma.branchContact.createMany({
typeof contact === "string" data:
? [{ telephoneNo: contact, branchId }] typeof contact === "string"
: contact.map((v) => ({ telephoneNo: v, branchId })), ? [{ telephoneNo: contact, branchId }]
}); : contact.map((v) => ({ telephoneNo: v, branchId })),
}));
} }
return Object.assign(record, { return Object.assign(record, {