refactor: change field name
This commit is contained in:
parent
d565a29a75
commit
624f4f2fd7
4 changed files with 32 additions and 15 deletions
|
|
@ -0,0 +1,9 @@
|
||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- You are about to drop the column `telephoneHq` on the `Branch` table. All the data in the column will be lost.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Branch" DROP COLUMN "telephoneHq",
|
||||||
|
ADD COLUMN "telephoneNo" TEXT;
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
/*
|
||||||
|
Warnings:
|
||||||
|
|
||||||
|
- Made the column `telephoneNo` on table `Branch` required. This step will fail if there are existing NULL values in that column.
|
||||||
|
|
||||||
|
*/
|
||||||
|
-- AlterTable
|
||||||
|
ALTER TABLE "Branch" ALTER COLUMN "telephoneNo" SET NOT NULL;
|
||||||
|
|
@ -182,7 +182,7 @@ model Branch {
|
||||||
nameEN String
|
nameEN String
|
||||||
address String
|
address String
|
||||||
addressEN String
|
addressEN String
|
||||||
telephoneHq String
|
telephoneNo String
|
||||||
|
|
||||||
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
|
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
|
||||||
provinceId String?
|
provinceId String?
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,8 @@ type BranchCreate = {
|
||||||
zipCode: string;
|
zipCode: string;
|
||||||
email: string;
|
email: string;
|
||||||
contactName: string;
|
contactName: string;
|
||||||
telephoneHq: string;
|
contact: string | string[];
|
||||||
telephoneNo: string | string[];
|
telephoneNo: string;
|
||||||
lineId: string;
|
lineId: string;
|
||||||
longitude: string;
|
longitude: string;
|
||||||
latitude: string;
|
latitude: string;
|
||||||
|
|
@ -57,9 +57,9 @@ type BranchUpdate = {
|
||||||
address?: string;
|
address?: string;
|
||||||
zipCode?: string;
|
zipCode?: string;
|
||||||
email?: string;
|
email?: string;
|
||||||
|
telephoneNo: string;
|
||||||
contactName?: string;
|
contactName?: string;
|
||||||
telephoneHq: string;
|
contact?: string | string[];
|
||||||
telephoneNo?: string | string[];
|
|
||||||
lineId?: string;
|
lineId?: string;
|
||||||
longitude?: string;
|
longitude?: string;
|
||||||
latitude?: string;
|
latitude?: string;
|
||||||
|
|
@ -245,7 +245,7 @@ export class BranchController extends Controller {
|
||||||
"missing_or_invalid_parameter",
|
"missing_or_invalid_parameter",
|
||||||
);
|
);
|
||||||
|
|
||||||
const { provinceId, districtId, subDistrictId, headOfficeId, telephoneNo, ...rest } = body;
|
const { provinceId, districtId, subDistrictId, headOfficeId, contact, ...rest } = body;
|
||||||
|
|
||||||
const year = new Date().getFullYear();
|
const year = new Date().getFullYear();
|
||||||
|
|
||||||
|
|
@ -286,12 +286,12 @@ export class BranchController extends Controller {
|
||||||
|
|
||||||
this.setStatus(HttpStatus.CREATED);
|
this.setStatus(HttpStatus.CREATED);
|
||||||
|
|
||||||
if (record && telephoneNo) {
|
if (record && contact) {
|
||||||
await prisma.branchContact.createMany({
|
await prisma.branchContact.createMany({
|
||||||
data:
|
data:
|
||||||
typeof telephoneNo === "string"
|
typeof contact === "string"
|
||||||
? [{ telephoneNo, branchId: record.id }]
|
? [{ telephoneNo: contact, branchId: record.id }]
|
||||||
: telephoneNo.map((v) => ({ telephoneNo: v, branchId: record.id })),
|
: contact.map((v) => ({ telephoneNo: v, branchId: record.id })),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -358,7 +358,7 @@ export class BranchController extends Controller {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const { provinceId, districtId, subDistrictId, headOfficeId, telephoneNo, ...rest } = body;
|
const { provinceId, districtId, subDistrictId, headOfficeId, contact, ...rest } = body;
|
||||||
|
|
||||||
if (!(await prisma.branch.findUnique({ where: { id: branchId } }))) {
|
if (!(await prisma.branch.findUnique({ where: { id: branchId } }))) {
|
||||||
throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.", "data_not_found");
|
throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.", "data_not_found");
|
||||||
|
|
@ -390,13 +390,13 @@ export class BranchController extends Controller {
|
||||||
where: { id: branchId },
|
where: { id: branchId },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (record && telephoneNo) {
|
if (record && contact) {
|
||||||
await prisma.branchContact.deleteMany({ where: { branchId } });
|
await prisma.branchContact.deleteMany({ where: { branchId } });
|
||||||
await prisma.branchContact.createMany({
|
await prisma.branchContact.createMany({
|
||||||
data:
|
data:
|
||||||
typeof telephoneNo === "string"
|
typeof contact === "string"
|
||||||
? [{ telephoneNo, branchId }]
|
? [{ telephoneNo: contact, branchId }]
|
||||||
: telephoneNo.map((v) => ({ telephoneNo: v, branchId })),
|
: contact.map((v) => ({ telephoneNo: v, branchId })),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue