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