feat: add address fields

This commit is contained in:
Methapon Metanipat 2024-09-11 15:06:27 +07:00
parent 730ebd6907
commit a7cafd25d0
8 changed files with 209 additions and 206 deletions

View file

@ -0,0 +1,40 @@
/*
Warnings:
- You are about to drop the column `zipCode` on the `Branch` table. All the data in the column will be lost.
- You are about to drop the column `zipCode` on the `User` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "Branch" DROP COLUMN "zipCode",
ADD COLUMN "moo" TEXT,
ADD COLUMN "mooEN" TEXT,
ADD COLUMN "soi" TEXT,
ADD COLUMN "soiEN" TEXT,
ADD COLUMN "street" TEXT,
ADD COLUMN "streetEN" TEXT;
-- AlterTable
ALTER TABLE "CustomerBranch" ADD COLUMN "moo" TEXT,
ADD COLUMN "mooEN" TEXT,
ADD COLUMN "soi" TEXT,
ADD COLUMN "soiEN" TEXT,
ADD COLUMN "street" TEXT,
ADD COLUMN "streetEN" TEXT;
-- AlterTable
ALTER TABLE "Employee" ADD COLUMN "moo" TEXT,
ADD COLUMN "mooEN" TEXT,
ADD COLUMN "soi" TEXT,
ADD COLUMN "soiEN" TEXT,
ADD COLUMN "street" TEXT,
ADD COLUMN "streetEN" TEXT;
-- AlterTable
ALTER TABLE "User" DROP COLUMN "zipCode",
ADD COLUMN "moo" TEXT,
ADD COLUMN "mooEN" TEXT,
ADD COLUMN "soi" TEXT,
ADD COLUMN "soiEN" TEXT,
ADD COLUMN "street" TEXT,
ADD COLUMN "streetEN" TEXT;

View file

@ -190,10 +190,18 @@ model Branch {
taxNo String taxNo String
name String name String
nameEN String nameEN String
address String
addressEN String
telephoneNo String telephoneNo String
address String
addressEN String
soi String?
soiEN String?
moo String?
mooEN String?
street String?
streetEN String?
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull) province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
provinceId String? provinceId String?
@ -203,8 +211,6 @@ model Branch {
subDistrict SubDistrict? @relation(fields: [subDistrictId], references: [id], onDelete: SetNull) subDistrict SubDistrict? @relation(fields: [subDistrictId], references: [id], onDelete: SetNull)
subDistrictId String? subDistrictId String?
zipCode String
email String email String
contactName String? contactName String?
lineId String? lineId String?
@ -304,6 +310,13 @@ model User {
address String address String
addressEN String addressEN String
soi String?
soiEN String?
moo String?
mooEN String?
street String?
streetEN String?
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull) province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
provinceId String? provinceId String?
@ -313,8 +326,6 @@ model User {
subDistrict SubDistrict? @relation(fields: [subDistrictId], references: [id], onDelete: SetNull) subDistrict SubDistrict? @relation(fields: [subDistrictId], references: [id], onDelete: SetNull)
subDistrictId String? subDistrictId String?
zipCode String
email String email String
telephoneNo String telephoneNo String
@ -329,6 +340,10 @@ model User {
userType UserType userType UserType
userRole String userRole String
// citizenId String?
// citizenIssue DateTime? @db.Date
// citizenExpire DateTime? @db.Date
discountCondition String? discountCondition String?
licenseNo String? licenseNo String?
@ -451,6 +466,13 @@ model CustomerBranch {
address String address String
addressEN String addressEN String
soi String?
soiEN String?
moo String?
mooEN String?
street String?
streetEN String?
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull) province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
provinceId String? provinceId String?
@ -509,6 +531,13 @@ model Employee {
address String? address String?
addressEN String? addressEN String?
soi String?
soiEN String?
moo String?
mooEN String?
street String?
streetEN String?
province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull) province Province? @relation(fields: [provinceId], references: [id], onDelete: SetNull)
provinceId String? provinceId String?

View file

@ -51,7 +51,6 @@ const APP_PORT = +(process.env.APP_PORT || 3000);
gender: "", gender: "",
address: "", address: "",
addressEN: "", addressEN: "",
zipCode: "",
userType: "USER", userType: "USER",
userRole: "system", userRole: "system",
telephoneNo: "", telephoneNo: "",

View file

@ -25,8 +25,8 @@ import {
createPermCondition, createPermCondition,
} from "../services/permission"; } from "../services/permission";
import { filterStatus } from "../services/prisma"; import { filterStatus } from "../services/prisma";
import { connectOrDisconnect, connectOrNot } from "../utils/relation"; import { connectOrDisconnect, connectOrNot, whereAddressQuery } from "../utils/relation";
import { notFoundError } from "../utils/error"; import { notFoundError, relationError } from "../utils/error";
if (!process.env.MINIO_BUCKET) { if (!process.env.MINIO_BUCKET) {
throw Error("Require MinIO bucket."); throw Error("Require MinIO bucket.");
@ -46,7 +46,12 @@ type BranchCreate = {
name: string; name: string;
addressEN: string; addressEN: string;
address: string; address: string;
zipCode: string; soi?: string | null;
soiEN?: string | null;
moo?: string | null;
mooEN?: string | null;
street?: string | null;
streetEN?: string | null;
email: string; email: string;
contactName?: string | null; contactName?: string | null;
webUrl?: string | null; webUrl?: string | null;
@ -80,7 +85,12 @@ type BranchUpdate = {
name?: string; name?: string;
addressEN?: string; addressEN?: string;
address?: string; address?: string;
zipCode?: string; soi?: string | null;
soiEN?: string | null;
moo?: string | null;
mooEN?: string | null;
street?: string | null;
streetEN?: string | null;
email?: string; email?: string;
telephoneNo?: string; telephoneNo?: string;
contactName?: string; contactName?: string;
@ -202,7 +212,6 @@ export class BranchController extends Controller {
@Security("keycloak") @Security("keycloak")
async getBranch( async getBranch(
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Query() zipCode?: string,
@Query() filter?: "head" | "sub", @Query() filter?: "head" | "sub",
@Query() headOfficeId?: string, @Query() headOfficeId?: string,
@Query() includeHead?: boolean, @Query() includeHead?: boolean,
@ -215,7 +224,6 @@ export class BranchController extends Controller {
const where = { const where = {
AND: { AND: {
...filterStatus(status), ...filterStatus(status),
zipCode,
headOfficeId: headOfficeId ?? (filter === "head" || tree ? null : undefined), headOfficeId: headOfficeId ?? (filter === "head" || tree ? null : undefined),
NOT: { headOfficeId: filter === "sub" && !headOfficeId ? null : undefined }, NOT: { headOfficeId: filter === "sub" && !headOfficeId ? null : undefined },
OR: permissionCond(req.user, true), OR: permissionCond(req.user, true),
@ -225,6 +233,20 @@ export class BranchController extends Controller {
{ name: { contains: query } }, { name: { contains: query } },
{ email: { contains: query } }, { email: { contains: query } },
{ telephoneNo: { contains: query } }, { telephoneNo: { contains: query } },
...whereAddressQuery(query),
{
branch: {
some: {
OR: [
{ nameEN: { contains: query } },
{ name: { contains: query } },
{ email: { contains: query } },
{ telephoneNo: { contains: query } },
...whereAddressQuery(query),
],
},
},
},
], ],
} satisfies Prisma.BranchWhereInput; } satisfies Prisma.BranchWhereInput;
@ -247,6 +269,15 @@ export class BranchController extends Controller {
: false, : false,
branch: tree branch: tree
? { ? {
where: {
OR: [
{ nameEN: { contains: query } },
{ name: { contains: query } },
{ email: { contains: query } },
{ telephoneNo: { contains: query } },
...whereAddressQuery(query),
],
},
include: { include: {
province: true, province: true,
district: true, district: true,
@ -312,30 +343,10 @@ export class BranchController extends Controller {
prisma.subDistrict.findFirst({ where: { id: body.subDistrictId || undefined } }), prisma.subDistrict.findFirst({ where: { id: body.subDistrictId || undefined } }),
prisma.branch.findFirst({ where: { id: body.headOfficeId || undefined } }), prisma.branch.findFirst({ where: { id: body.headOfficeId || undefined } }),
]); ]);
if (body.provinceId && !province) if (body.provinceId && !province) throw relationError("Province");
throw new HttpError( if (body.districtId && !district) throw relationError("District");
HttpStatus.BAD_REQUEST, if (body.subDistrictId && !subDistrict) throw relationError("SubDistrict");
"Province cannot be found.", if (body.headOfficeId && !head) throw relationError("HQ");
"relationProvinceNotFound",
);
if (body.districtId && !district)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"District cannot be found.",
"relationDistrictNotFound",
);
if (body.subDistrictId && !subDistrict)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Sub-district cannot be found.",
"relationSubDistrictNotFound",
);
if (body.headOfficeId && !head)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Headquaters cannot be found.",
"relationHQNotFound",
);
const { provinceId, districtId, subDistrictId, headOfficeId, bank, contact, code, ...rest } = const { provinceId, districtId, subDistrictId, headOfficeId, bank, contact, code, ...rest } =
body; body;
@ -447,30 +458,10 @@ export class BranchController extends Controller {
prisma.subDistrict.findFirst({ where: { id: body.subDistrictId || undefined } }), prisma.subDistrict.findFirst({ where: { id: body.subDistrictId || undefined } }),
prisma.branch.findFirst({ where: { id: body.headOfficeId || undefined } }), prisma.branch.findFirst({ where: { id: body.headOfficeId || undefined } }),
]); ]);
if (body.provinceId && !province) if (body.provinceId && !province) throw relationError("Province");
throw new HttpError( if (body.districtId && !district) throw relationError("District");
HttpStatus.BAD_REQUEST, if (body.subDistrictId && !subDistrict) throw relationError("SubDistrict");
"Province cannot be found.", if (body.headOfficeId && !branch) throw relationError("HQ");
"relationProvinceNotFound",
);
if (body.districtId && !district)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"District cannot be found.",
"relationDistrictNotFound",
);
if (body.subDistrictId && !subDistrict)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Sub-district cannot be found.",
"relationSubDistrictNotFound",
);
if (body.headOfficeId && !branch)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Headquaters cannot be found.",
"relationHQNotFound",
);
} }
const { provinceId, districtId, subDistrictId, headOfficeId, bank, contact, ...rest } = body; const { provinceId, districtId, subDistrictId, headOfficeId, bank, contact, ...rest } = body;

View file

@ -98,10 +98,11 @@ export class UserBranchController extends Controller {
@Query() pageSize: number = 30, @Query() pageSize: number = 30,
) { ) {
const where = { const where = {
OR: [ AND: {
{ branch: { name: { contains: query }, zipCode }, userId }, branch: { subDistrict: { zipCode } },
{ branch: { nameEN: { contains: query }, zipCode }, userId }, userId,
], },
OR: [{ branch: { name: { contains: query } } }, { branch: { nameEN: { contains: query } } }],
} satisfies Prisma.BranchUserWhereInput; } satisfies Prisma.BranchUserWhereInput;
const [result, total] = await prisma.$transaction([ const [result, total] = await prisma.$transaction([
@ -147,13 +148,17 @@ export class BranchUserController extends Controller {
@Query() pageSize: number = 30, @Query() pageSize: number = 30,
) { ) {
const where = { const where = {
AND: {
user: { subDistrict: { zipCode } },
branchId,
},
OR: [ OR: [
{ user: { firstName: { contains: query }, zipCode }, branchId }, { user: { firstName: { contains: query } } },
{ user: { firstNameEN: { contains: query }, zipCode }, branchId }, { user: { firstNameEN: { contains: query } } },
{ user: { lastName: { contains: query }, zipCode }, branchId }, { user: { lastName: { contains: query } } },
{ user: { lastNameEN: { contains: query }, zipCode }, branchId }, { user: { lastNameEN: { contains: query } } },
{ user: { email: { contains: query }, zipCode }, branchId }, { user: { email: { contains: query } } },
{ user: { telephoneNo: { contains: query }, zipCode }, branchId }, { user: { telephoneNo: { contains: query } } },
], ],
} satisfies Prisma.BranchUserWhereInput; } satisfies Prisma.BranchUserWhereInput;

View file

@ -36,7 +36,7 @@ import {
createPermCheck, createPermCheck,
createPermCondition, createPermCondition,
} from "../services/permission"; } from "../services/permission";
import { connectOrDisconnect, connectOrNot } from "../utils/relation"; import { connectOrDisconnect, connectOrNot, whereAddressQuery } from "../utils/relation";
if (!process.env.MINIO_BUCKET) { if (!process.env.MINIO_BUCKET) {
throw Error("Require MinIO bucket."); throw Error("Require MinIO bucket.");
@ -84,7 +84,12 @@ type UserCreate = {
address: string; address: string;
addressEN: string; addressEN: string;
zipCode: string; soi?: string | null;
soiEN?: string | null;
moo?: string | null;
mooEN?: string | null;
street?: string | null;
streetEN?: string | null;
email: string; email: string;
telephoneNo: string; telephoneNo: string;
@ -131,7 +136,12 @@ type UserUpdate = {
address?: string; address?: string;
addressEN?: string; addressEN?: string;
zipCode?: string; soi?: string | null;
soiEN?: string | null;
moo?: string | null;
mooEN?: string | null;
street?: string | null;
streetEN?: string | null;
email?: string; email?: string;
telephoneNo?: string; telephoneNo?: string;
@ -223,7 +233,6 @@ export class UserController extends Controller {
async getUser( async getUser(
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Query() userType?: UserType, @Query() userType?: UserType,
@Query() zipCode?: string,
@Query() includeBranch: boolean = false, @Query() includeBranch: boolean = false,
@Query() query: string = "", @Query() query: string = "",
@Query() page: number = 1, @Query() page: number = 1,
@ -238,10 +247,10 @@ export class UserController extends Controller {
{ lastNameEN: { contains: query } }, { lastNameEN: { contains: query } },
{ email: { contains: query } }, { email: { contains: query } },
{ telephoneNo: { contains: query } }, { telephoneNo: { contains: query } },
...whereAddressQuery(query),
], ],
AND: { AND: {
userRole: { not: "system" }, userRole: { not: "system" },
zipCode,
userType, userType,
...filterStatus(status), ...filterStatus(status),
branch: isSystem(req.user) branch: isSystem(req.user)

View file

@ -17,10 +17,16 @@ import { RequestWithUser } from "../interfaces/user";
import prisma from "../db"; import prisma from "../db";
import HttpStatus from "../interfaces/http-status"; import HttpStatus from "../interfaces/http-status";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import minio from "../services/minio"; import minio, { deleteFolder } from "../services/minio";
import { isSystem } from "../utils/keycloak"; import { isSystem } from "../utils/keycloak";
import { branchRelationPermInclude, createPermCheck } from "../services/permission"; import {
branchRelationPermInclude,
createPermCheck,
createPermCondition,
} from "../services/permission";
import { filterStatus } from "../services/prisma"; import { filterStatus } from "../services/prisma";
import { connectOrDisconnect, connectOrNot, whereAddressQuery } from "../utils/relation";
import { notFoundError, relationError } from "../utils/error";
if (!process.env.MINIO_BUCKET) { if (!process.env.MINIO_BUCKET) {
throw Error("Require MinIO bucket."); throw Error("Require MinIO bucket.");
@ -42,6 +48,7 @@ function globalAllow(user: RequestWithUser["user"]) {
return allowList.some((v) => user.roles?.includes(v)); return allowList.some((v) => user.roles?.includes(v));
} }
const permissionCond = createPermCondition(globalAllow);
const permissionCheck = createPermCheck(globalAllow); const permissionCheck = createPermCheck(globalAllow);
function imageLocation(id: string) { function imageLocation(id: string) {
@ -74,6 +81,12 @@ export type CustomerBranchCreate = (
workplaceEN: string; workplaceEN: string;
address: string; address: string;
addressEN: string; addressEN: string;
soi?: string | null;
soiEN?: string | null;
moo?: string | null;
mooEN?: string | null;
street?: string | null;
streetEN?: string | null;
email: string; email: string;
contactName: string; contactName: string;
@ -116,6 +129,12 @@ export type CustomerBranchUpdate = (
workplaceEN: string; workplaceEN: string;
address: string; address: string;
addressEN: string; addressEN: string;
soi?: string | null;
soiEN?: string | null;
moo?: string | null;
mooEN?: string | null;
street?: string | null;
streetEN?: string | null;
email?: string; email?: string;
contactName?: string; contactName?: string;
@ -158,14 +177,7 @@ export class CustomerBranchController extends Controller {
{ registerNameEN: { contains: query } }, { registerNameEN: { contains: query } },
{ email: { contains: query } }, { email: { contains: query } },
{ code: { contains: query } }, { code: { contains: query } },
{ address: { contains: query } }, ...whereAddressQuery(query),
{ addressEN: { contains: query } },
{ province: { name: { contains: query } } },
{ province: { nameEN: { contains: query } } },
{ district: { name: { contains: query } } },
{ district: { nameEN: { contains: query } } },
{ subDistrict: { name: { contains: query } } },
{ subDistrict: { nameEN: { contains: query } } },
{ {
customer: { customer: {
OR: [ OR: [
@ -183,26 +195,7 @@ export class CustomerBranchController extends Controller {
? undefined ? undefined
: { : {
registeredBranch: { registeredBranch: {
OR: [ OR: permissionCond(req.user),
{
user: { some: { userId: req.user.sub } },
},
{
branch: globalAllow(req.user)
? { some: { user: { some: { userId: req.user.sub } } } }
: undefined,
},
{
headOffice: globalAllow(req.user)
? { branch: { some: { user: { some: { userId: req.user.sub } } } } }
: undefined,
},
{
headOffice: globalAllow(req.user)
? { user: { some: { userId: req.user.sub } } }
: undefined,
},
],
}, },
}, },
customerId, customerId,
@ -248,9 +241,7 @@ export class CustomerBranchController extends Controller {
where: { id: branchId }, where: { id: branchId },
}); });
if (!record) { if (!record) throw notFoundError("Branch");
throw new HttpError(HttpStatus.NOT_FOUND, "Branch cannot be found.", "branchNotFound");
}
return record; return record;
} }
@ -266,14 +257,6 @@ export class CustomerBranchController extends Controller {
@Query() page: number = 1, @Query() page: number = 1,
@Query() pageSize: number = 30, @Query() pageSize: number = 30,
) { ) {
const filterStatus = (val?: Status) => {
if (!val) return {};
return val !== Status.CREATED && val !== Status.ACTIVE
? { status: val }
: { OR: [{ status: Status.CREATED }, { status: Status.ACTIVE }] };
};
const where = { const where = {
OR: [ OR: [
{ firstName: { contains: query } }, { firstName: { contains: query } },
@ -281,6 +264,7 @@ export class CustomerBranchController extends Controller {
{ lastName: { contains: query } }, { lastName: { contains: query } },
{ lastNameEN: { contains: query } }, { lastNameEN: { contains: query } },
{ passportNumber: { contains: query } }, { passportNumber: { contains: query } },
...whereAddressQuery(query),
], ],
AND: { AND: {
...filterStatus(status), ...filterStatus(status),
@ -344,32 +328,14 @@ export class CustomerBranchController extends Controller {
}, },
}), }),
]); ]);
if (body.provinceId && !province) if (body.provinceId && !province) throw relationError("Province");
throw new HttpError( if (body.districtId && !district) throw relationError("District");
HttpStatus.BAD_REQUEST, if (body.subDistrictId && !subDistrict) throw relationError("SubDistrict");
"Province cannot be found.", if (!customer) throw relationError("Customer");
"relationProvinceNotFound",
);
if (body.districtId && !district)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"District cannot be found.",
"relationDistrictNotFound",
);
if (body.subDistrictId && !subDistrict)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Sub-district cannot be found.",
"relationSubDistrictNotFound",
);
if (!customer)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Customer cannot be found.",
"relationCustomerNotFound",
);
await permissionCheck(req.user, customer.registeredBranch); let company = await permissionCheck(req.user, customer.registeredBranch).then(
(v) => (v.headOffice || v).code,
);
const { provinceId, districtId, subDistrictId, customerId, ...rest } = body; const { provinceId, districtId, subDistrictId, customerId, ...rest } = body;
@ -381,11 +347,11 @@ export class CustomerBranchController extends Controller {
let runningKey = ""; let runningKey = "";
if (headofficeCode) { if (headofficeCode) {
runningKey = `CUSTOMER_BRANCH_${headofficeCode}`; runningKey = `CUSTOMER_BRANCH_${company}_${headofficeCode}`;
} else if ("citizenId" in body) { } else if ("citizenId" in body) {
runningKey = `CUSTOMER_BRANCH_${body.citizenId}`; runningKey = `CUSTOMER_BRANCH_${company}_${body.citizenId}`;
} else { } else {
runningKey = `CUSTOMER_BRANCH_${body.legalPersonNo}`; runningKey = `CUSTOMER_BRANCH_${company}_${body.legalPersonNo}`;
} }
const last = await tx.runningNo.upsert({ const last = await tx.runningNo.upsert({
@ -478,30 +444,10 @@ export class CustomerBranchController extends Controller {
}, },
}), }),
]); ]);
if (body.provinceId && !province) if (body.provinceId && !province) throw relationError("Province");
throw new HttpError( if (body.districtId && !district) throw relationError("District");
HttpStatus.BAD_REQUEST, if (body.subDistrictId && !subDistrict) throw relationError("SubDistrict");
"Province cannot be found.", if (!customer) throw relationError("Customer");
"relationProvinceNotFound",
);
if (body.districtId && !district)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"District cannot be found.",
"relationDistrictNotFound",
);
if (body.subDistrictId && !subDistrict)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Sub-district cannot be found.",
"relationSubDistrictNotFound",
);
if (!customer)
throw new HttpError(
HttpStatus.BAD_REQUEST,
"Customer cannot be found.",
"relationCustomerNotFound",
);
await permissionCheck(req.user, customer.registeredBranch); await permissionCheck(req.user, customer.registeredBranch);
} }
@ -519,19 +465,10 @@ export class CustomerBranchController extends Controller {
data: { data: {
...rest, ...rest,
statusOrder: +(rest.status === "INACTIVE"), statusOrder: +(rest.status === "INACTIVE"),
customer: { connect: customerId ? { id: customerId } : undefined }, customer: connectOrNot(customerId),
province: { province: connectOrDisconnect(provinceId),
connect: provinceId ? { id: provinceId } : undefined, district: connectOrDisconnect(districtId),
disconnect: provinceId === null || undefined, subDistrict: connectOrDisconnect(subDistrictId),
},
district: {
connect: districtId ? { id: districtId } : undefined,
disconnect: districtId === null || undefined,
},
subDistrict: {
connect: subDistrictId ? { id: subDistrictId } : undefined,
disconnect: subDistrictId === null || undefined,
},
updatedBy: { connect: { id: req.user.sub } }, updatedBy: { connect: { id: req.user.sub } },
}, },
}); });
@ -553,13 +490,7 @@ export class CustomerBranchController extends Controller {
}, },
}); });
if (!record) { if (!record) throw notFoundError("Customer Branch");
throw new HttpError(
HttpStatus.NOT_FOUND,
"Customer branch cannot be found.",
"customerBranchNotFound",
);
}
await permissionCheck(req.user, record.customer.registeredBranch); await permissionCheck(req.user, record.customer.registeredBranch);
@ -577,22 +508,7 @@ export class CustomerBranchController extends Controller {
where: { id: branchId }, where: { id: branchId },
}) })
.then((v) => { .then((v) => {
new Promise<string[]>((resolve, reject) => { deleteFolder(MINIO_BUCKET, `${attachmentLocation(record.customerId, branchId)}/`);
const item: string[] = [];
const stream = minio.listObjectsV2(
MINIO_BUCKET,
`${attachmentLocation(record.customerId, branchId)}/`,
);
stream.on("data", (v) => v && v.name && item.push(v.name));
stream.on("end", () => resolve(item));
stream.on("error", () => reject(new Error("MinIO error.")));
}).then((list) => {
list.map(async (v) => {
await minio.removeObject(MINIO_BUCKET, v, { forceDelete: true });
});
});
return v; return v;
}); });
} }

View file

@ -24,7 +24,7 @@ import {
createPermCheck, createPermCheck,
createPermCondition, createPermCondition,
} from "../services/permission"; } from "../services/permission";
import { connectOrDisconnect, connectOrNot } from "../utils/relation"; import { connectOrDisconnect, connectOrNot, whereAddressQuery } from "../utils/relation";
import { notFoundError, relationError } from "../utils/error"; import { notFoundError, relationError } from "../utils/error";
import { deleteFile, fileLocation, getFile, listFile, setFile } from "../utils/minio"; import { deleteFile, fileLocation, getFile, listFile, setFile } from "../utils/minio";
@ -70,6 +70,12 @@ type EmployeeCreate = {
addressEN: string; addressEN: string;
address: string; address: string;
soi?: string | null;
soiEN?: string | null;
moo?: string | null;
mooEN?: string | null;
street?: string | null;
streetEN?: string | null;
passportType: string; passportType: string;
passportNumber: string; passportNumber: string;
@ -156,6 +162,12 @@ type EmployeeUpdate = {
addressEN?: string; addressEN?: string;
address?: string; address?: string;
soi?: string | null;
soiEN?: string | null;
moo?: string | null;
mooEN?: string | null;
street?: string | null;
streetEN?: string | null;
passportType?: string; passportType?: string;
passportNumber?: string; passportNumber?: string;
@ -253,6 +265,7 @@ export class EmployeeController extends Controller {
{ firstNameEN: { contains: query } }, { firstNameEN: { contains: query } },
{ lastName: { contains: query } }, { lastName: { contains: query } },
{ lastNameEN: { contains: query } }, { lastNameEN: { contains: query } },
...whereAddressQuery(query),
], ],
AND: { AND: {
...filterStatus(status), ...filterStatus(status),
@ -294,6 +307,7 @@ export class EmployeeController extends Controller {
{ lastName: { contains: query } }, { lastName: { contains: query } },
{ lastNameEN: { contains: query } }, { lastNameEN: { contains: query } },
{ passportNumber: { contains: query } }, { passportNumber: { contains: query } },
...whereAddressQuery(query),
], ],
AND: { AND: {
...filterStatus(status), ...filterStatus(status),