refactor: change field name

This commit is contained in:
Methapon2001 2024-04-18 13:21:37 +07:00
parent d565a29a75
commit 624f4f2fd7
4 changed files with 32 additions and 15 deletions

View file

@ -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;

View file

@ -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;

View file

@ -182,7 +182,7 @@ model Branch {
nameEN String
address String
addressEN String
telephoneHq String
telephoneNo String
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
provinceId String?

View file

@ -36,8 +36,8 @@ type BranchCreate = {
zipCode: string;
email: string;
contactName: string;
telephoneHq: string;
telephoneNo: string | string[];
contact: string | string[];
telephoneNo: string;
lineId: string;
longitude: string;
latitude: string;
@ -57,9 +57,9 @@ type BranchUpdate = {
address?: string;
zipCode?: string;
email?: string;
telephoneNo: string;
contactName?: string;
telephoneHq: string;
telephoneNo?: string | string[];
contact?: string | string[];
lineId?: string;
longitude?: string;
latitude?: string;
@ -245,7 +245,7 @@ export class BranchController extends Controller {
"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();
@ -286,12 +286,12 @@ export class BranchController extends Controller {
this.setStatus(HttpStatus.CREATED);
if (record && telephoneNo) {
if (record && contact) {
await prisma.branchContact.createMany({
data:
typeof telephoneNo === "string"
? [{ telephoneNo, branchId: record.id }]
: telephoneNo.map((v) => ({ telephoneNo: v, branchId: record.id })),
typeof contact === "string"
? [{ telephoneNo: contact, 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 } }))) {
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 },
});
if (record && telephoneNo) {
if (record && contact) {
await prisma.branchContact.deleteMany({ where: { branchId } });
await prisma.branchContact.createMany({
data:
typeof telephoneNo === "string"
? [{ telephoneNo, branchId }]
: telephoneNo.map((v) => ({ telephoneNo: v, branchId })),
typeof contact === "string"
? [{ telephoneNo: contact, branchId }]
: contact.map((v) => ({ telephoneNo: v, branchId })),
});
}