jws-backend/src/controllers/03-customer-branch-controller.ts

829 lines
25 KiB
TypeScript
Raw Normal View History

2024-04-05 11:37:40 +07:00
import { Prisma, Status } from "@prisma/client";
import {
Body,
Controller,
Delete,
Get,
2024-10-22 10:43:20 +07:00
Head,
2024-04-05 11:37:40 +07:00
Path,
Post,
Put,
Query,
Request,
Route,
Security,
Tags,
} from "tsoa";
import { RequestWithUser } from "../interfaces/user";
import prisma from "../db";
import HttpStatus from "../interfaces/http-status";
2024-09-05 15:06:23 +07:00
import { isSystem } from "../utils/keycloak";
2024-09-11 15:06:27 +07:00
import {
branchActiveOnlyCond,
2024-09-11 15:06:27 +07:00
branchRelationPermInclude,
createPermCheck,
createPermCondition,
} from "../services/permission";
2024-09-09 14:51:17 +07:00
import { filterStatus } from "../services/prisma";
import {
connectOrDisconnect,
connectOrNot,
queryOrNot,
whereAddressQuery,
2025-04-17 13:41:22 +07:00
whereDateQuery,
} from "../utils/relation";
import { isUsedError, notFoundError, relationError } from "../utils/error";
2024-10-22 10:43:20 +07:00
import {
deleteFile,
deleteFolder,
fileLocation,
getFile,
getPresigned,
listFile,
setFile,
} from "../utils/minio";
2024-04-05 11:37:40 +07:00
const MANAGE_ROLES = [
"system",
"head_of_admin",
"admin",
"head_of_accountant",
"accountant",
"head_of_sale",
2024-09-09 11:13:53 +07:00
"sale",
];
2024-09-04 16:51:42 +07:00
function globalAllow(user: RequestWithUser["user"]) {
const allowList = ["system", "head_of_admin", "head_of_accountant", "head_of_sale"];
2024-09-04 16:51:42 +07:00
return allowList.some((v) => user.roles?.includes(v));
}
2024-04-05 11:37:40 +07:00
const permissionCondCompany = createPermCondition((_) => true);
2024-09-11 15:06:27 +07:00
const permissionCond = createPermCondition(globalAllow);
2024-10-28 10:51:51 +07:00
const permissionCheckCompany = createPermCheck((_) => true);
const permissionCheck = createPermCheck(globalAllow);
2024-09-16 14:37:03 +07:00
export type CustomerBranchCreate = {
2024-04-05 11:42:03 +07:00
customerId: string;
2024-09-16 14:37:03 +07:00
// NOTE: About (Natural Person)
citizenId?: string;
namePrefix?: string;
firstName?: string;
firstNameEN?: string;
lastName?: string;
lastNameEN?: string;
gender?: string;
birthDate?: Date;
// NOTE: About (Legal Entity)
legalPersonNo?: string;
registerName?: string;
registerNameEN?: string;
registerDate?: Date;
authorizedCapital?: string;
authorizedName?: string;
authorizedNameEN?: string;
customerName?: string;
2024-04-05 11:42:03 +07:00
2024-09-16 11:03:34 +07:00
telephoneNo: string;
2024-04-05 11:42:03 +07:00
status?: Status;
2024-09-16 11:03:34 +07:00
homeCode: string;
employmentOffice: string;
employmentOfficeEN: string;
2024-04-05 11:42:03 +07:00
address: string;
2024-08-20 16:17:41 +07:00
addressEN: string;
2024-09-11 15:06:27 +07:00
soi?: string | null;
soiEN?: string | null;
moo?: string | null;
mooEN?: string | null;
street?: string | null;
streetEN?: string | null;
2024-08-20 16:17:41 +07:00
2024-04-05 11:42:03 +07:00
email: string;
2024-09-16 11:03:34 +07:00
contactTel: string;
officeTel: string;
2024-08-21 16:52:59 +07:00
contactName: string;
2024-10-28 10:51:51 +07:00
agentUserId?: string;
2024-04-05 11:42:03 +07:00
2024-08-20 16:17:41 +07:00
businessType: string;
2024-04-23 18:09:08 +07:00
jobPosition: string;
jobDescription: string;
2024-09-16 11:03:34 +07:00
payDate: string;
payDateEN: string;
2024-06-07 14:02:31 +07:00
wageRate: number;
2024-09-16 11:03:34 +07:00
wageRateText: string;
2024-04-23 18:09:08 +07:00
2024-04-05 11:42:03 +07:00
subDistrictId?: string | null;
districtId?: string | null;
provinceId?: string | null;
};
2024-09-16 17:34:34 +07:00
export type CustomerBranchUpdate = {
customerId: string;
// NOTE: About (Natural Person)
citizenId?: string;
namePrefix?: string;
firstName?: string;
firstNameEN?: string;
lastName?: string;
lastNameEN?: string;
gender?: string;
birthDate?: Date;
// NOTE: About (Legal Entity)
legalPersonNo?: string;
registerName?: string;
registerNameEN?: string;
registerDate?: Date;
authorizedCapital?: string;
authorizedName?: string;
authorizedNameEN?: string;
2024-09-16 13:31:47 +07:00
customerName?: string;
2024-04-05 11:42:03 +07:00
2024-09-16 11:03:34 +07:00
telephoneNo: string;
2024-09-16 17:34:34 +07:00
status?: Status;
2024-04-05 11:42:03 +07:00
2024-09-16 11:03:34 +07:00
homeCode?: string;
2024-09-16 17:34:34 +07:00
employmentOffice?: string;
employmentOfficeEN?: string;
2024-09-16 11:03:34 +07:00
address?: string;
addressEN?: string;
2024-09-11 15:06:27 +07:00
soi?: string | null;
soiEN?: string | null;
moo?: string | null;
mooEN?: string | null;
street?: string | null;
streetEN?: string | null;
2024-04-05 11:42:03 +07:00
email?: string;
2024-09-16 11:03:34 +07:00
contactTel?: string;
officeTel?: string;
2024-08-21 16:52:59 +07:00
contactName?: string;
2024-10-28 10:51:51 +07:00
agentUserId?: string;
2024-04-05 11:42:03 +07:00
2024-08-21 12:56:39 +07:00
businessType?: string;
2024-04-23 18:09:08 +07:00
jobPosition?: string;
jobDescription?: string;
2024-09-16 11:03:34 +07:00
payDate?: string;
payDateEN?: string;
2024-06-10 15:24:06 +07:00
wageRate?: number;
2024-09-16 11:03:34 +07:00
wageRateText?: string;
2024-04-23 18:09:08 +07:00
2024-04-05 11:42:03 +07:00
subDistrictId?: string | null;
districtId?: string | null;
provinceId?: string | null;
};
2024-06-06 09:42:02 +07:00
@Route("api/v1/customer-branch")
2024-04-05 11:37:40 +07:00
@Tags("Customer Branch")
export class CustomerBranchController extends Controller {
2024-04-05 14:55:24 +07:00
@Get()
@Security("keycloak")
2024-04-05 14:55:24 +07:00
async list(
2024-09-05 16:14:03 +07:00
@Request() req: RequestWithUser,
2024-04-05 14:55:24 +07:00
@Query() zipCode?: string,
@Query() company?: boolean,
@Query() customerId?: string,
2024-10-02 16:03:49 +07:00
@Query() registeredBranchId?: string,
2024-06-13 17:21:22 +07:00
@Query() status?: Status,
@Query() includeCustomer?: boolean,
2024-04-05 14:55:24 +07:00
@Query() query: string = "",
@Query() page: number = 1,
@Query() pageSize: number = 30,
@Query() activeRegisBranchOnly?: boolean,
2025-04-17 13:41:22 +07:00
@Query() startDate?: Date,
@Query() endDate?: Date,
2024-04-05 14:55:24 +07:00
) {
const where = {
OR: queryOrNot<Prisma.CustomerBranchWhereInput[]>(query, [
2025-04-09 11:54:52 +07:00
{ customerName: { contains: query, mode: "insensitive" } },
{ registerName: { contains: query, mode: "insensitive" } },
{ registerNameEN: { contains: query, mode: "insensitive" } },
{ email: { contains: query, mode: "insensitive" } },
{ code: { contains: query, mode: "insensitive" } },
{ firstName: { contains: query, mode: "insensitive" } },
{ firstNameEN: { contains: query, mode: "insensitive" } },
{ lastName: { contains: query, mode: "insensitive" } },
{ lastNameEN: { contains: query, mode: "insensitive" } },
...whereAddressQuery(query),
]),
2024-09-05 16:14:03 +07:00
AND: {
customer: isSystem(req.user)
? {
registeredBranchId,
registeredBranch: branchActiveOnlyCond(activeRegisBranchOnly),
2024-12-18 16:29:48 +07:00
...filterStatus(activeRegisBranchOnly ? Status.ACTIVE : status),
}
2024-09-05 16:14:03 +07:00
: {
2024-12-18 16:29:48 +07:00
...filterStatus(activeRegisBranchOnly ? Status.ACTIVE : status),
2024-09-05 16:14:03 +07:00
registeredBranch: {
2024-10-02 16:03:49 +07:00
AND: { id: registeredBranchId },
OR: company
? permissionCondCompany(req.user, { activeOnly: activeRegisBranchOnly })
: permissionCond(req.user, { activeOnly: activeRegisBranchOnly }),
2024-09-05 16:14:03 +07:00
},
},
customerId,
subDistrict: zipCode ? { zipCode } : undefined,
2024-12-18 16:29:48 +07:00
...filterStatus(activeRegisBranchOnly ? Status.ACTIVE : status),
2024-09-05 16:14:03 +07:00
},
2025-04-17 13:41:22 +07:00
...whereDateQuery(startDate, endDate),
} satisfies Prisma.CustomerBranchWhereInput;
2024-04-05 14:55:24 +07:00
const [result, total] = await prisma.$transaction([
prisma.customerBranch.findMany({
2024-09-26 11:54:59 +07:00
orderBy: [{ code: "asc" }, { statusOrder: "asc" }, { createdAt: "asc" }],
2024-04-05 14:55:24 +07:00
include: {
customer: includeCustomer,
2024-04-05 14:55:24 +07:00
province: true,
district: true,
subDistrict: true,
2024-07-01 14:38:07 +07:00
createdBy: true,
updatedBy: true,
_count: true,
2024-04-05 14:55:24 +07:00
},
where,
take: pageSize,
skip: (page - 1) * pageSize,
}),
prisma.customerBranch.count({ where }),
]);
return { result, page, pageSize, total };
}
2024-04-05 15:09:44 +07:00
@Get("{branchId}")
@Security("keycloak")
2024-04-05 15:09:44 +07:00
async getById(@Path() branchId: string) {
const record = await prisma.customerBranch.findFirst({
include: {
2024-08-27 18:14:50 +07:00
customer: true,
2024-04-05 15:09:44 +07:00
province: true,
district: true,
subDistrict: true,
2024-07-01 14:38:07 +07:00
createdBy: true,
updatedBy: true,
2024-04-05 15:09:44 +07:00
},
where: { id: branchId },
});
2024-09-11 15:06:27 +07:00
if (!record) throw notFoundError("Branch");
2024-04-05 15:09:44 +07:00
return record;
}
2024-04-05 15:07:29 +07:00
@Get("{branchId}/employee")
@Security("keycloak")
2024-04-05 15:07:29 +07:00
async listEmployee(
@Path() branchId: string,
@Query() zipCode?: string,
2024-08-22 11:44:44 +07:00
@Query() gender?: string,
@Query() status?: Status,
2024-04-05 15:07:29 +07:00
@Query() query: string = "",
2024-10-17 17:12:39 +07:00
@Query() passport?: boolean,
@Query() visa?: boolean,
2024-04-05 15:07:29 +07:00
@Query() page: number = 1,
@Query() pageSize: number = 30,
2025-04-17 13:41:22 +07:00
@Query() startDate?: Date,
@Query() endDate?: Date,
2024-04-05 15:07:29 +07:00
) {
const where = {
OR: queryOrNot<Prisma.EmployeeWhereInput[]>(query, [
2025-04-09 11:54:52 +07:00
{ firstName: { contains: query, mode: "insensitive" } },
{ firstNameEN: { contains: query, mode: "insensitive" } },
{ lastName: { contains: query, mode: "insensitive" } },
{ lastNameEN: { contains: query, mode: "insensitive" } },
2024-09-11 15:06:27 +07:00
...whereAddressQuery(query),
]),
2024-08-22 11:44:44 +07:00
AND: {
...filterStatus(status),
customerBranchId: branchId,
subDistrict: zipCode ? { zipCode } : undefined,
gender,
},
2025-04-17 13:41:22 +07:00
...whereDateQuery(startDate, endDate),
2024-04-05 15:07:29 +07:00
} satisfies Prisma.EmployeeWhereInput;
const [result, total] = await prisma.$transaction([
prisma.employee.findMany({
2024-04-09 08:51:22 +07:00
orderBy: { createdAt: "asc" },
2024-04-05 15:07:29 +07:00
include: {
province: true,
district: true,
subDistrict: true,
2024-10-17 17:12:39 +07:00
employeePassport: passport,
employeeVisa: visa,
2024-07-01 14:38:07 +07:00
createdBy: true,
updatedBy: true,
2024-04-05 15:07:29 +07:00
},
where,
take: pageSize,
skip: (page - 1) * pageSize,
}),
prisma.employee.count({ where }),
]);
return {
2024-09-16 17:20:51 +07:00
result,
2024-04-05 15:07:29 +07:00
page,
pageSize,
total,
};
}
2024-04-05 13:51:36 +07:00
@Post()
@Security("keycloak", MANAGE_ROLES)
2024-04-05 13:51:36 +07:00
async create(@Request() req: RequestWithUser, @Body() body: CustomerBranchCreate) {
2024-10-28 10:51:51 +07:00
const [province, district, subDistrict, customer, agent] = await prisma.$transaction([
prisma.province.findFirst({ where: { id: body.provinceId || undefined } }),
prisma.district.findFirst({ where: { id: body.districtId || undefined } }),
prisma.subDistrict.findFirst({ where: { id: body.subDistrictId || undefined } }),
prisma.customer.findFirst({
where: { id: body.customerId || undefined },
include: {
2024-09-05 15:06:23 +07:00
registeredBranch: {
include: branchRelationPermInclude(req.user),
2024-09-05 15:06:23 +07:00
},
branch: {
take: 1,
orderBy: { createdAt: "asc" },
},
},
}),
2024-10-28 10:51:51 +07:00
prisma.user.findFirst({
2024-10-28 13:00:40 +07:00
where: { id: body.agentUserId || undefined },
2024-10-28 10:51:51 +07:00
include: {
branch: {
include: { branch: { include: branchRelationPermInclude(req.user) } },
},
},
}),
]);
2024-09-11 15:06:27 +07:00
if (body.provinceId && !province) throw relationError("Province");
if (body.districtId && !district) throw relationError("District");
if (body.subDistrictId && !subDistrict) throw relationError("SubDistrict");
2024-10-28 10:51:51 +07:00
if (body.agentUserId && !agent) throw relationError("User");
2024-09-11 15:06:27 +07:00
if (!customer) throw relationError("Customer");
2024-10-28 10:51:51 +07:00
if (agent) {
await Promise.all(agent.branch.map(({ branch }) => permissionCheckCompany(req.user, branch)));
}
await permissionCheck(req.user, customer.registeredBranch);
2024-04-05 13:51:36 +07:00
2024-09-11 15:06:27 +07:00
let company = await permissionCheck(req.user, customer.registeredBranch).then(
(v) => (v.headOffice || v).code,
);
2024-09-05 15:06:23 +07:00
2024-10-28 10:51:51 +07:00
const { provinceId, districtId, subDistrictId, customerId, agentUserId, ...rest } = body;
2024-04-05 13:51:36 +07:00
2024-04-23 18:09:08 +07:00
const record = await prisma.$transaction(
async (tx) => {
const headoffice = customer.branch.at(0);
const headofficeCode = headoffice?.code.slice(0, -3);
2024-08-20 16:17:41 +07:00
let runningKey = "";
if (headofficeCode) {
2024-09-11 15:06:27 +07:00
runningKey = `CUSTOMER_BRANCH_${company}_${headofficeCode}`;
} else if ("citizenId" in body) {
2024-09-11 15:06:27 +07:00
runningKey = `CUSTOMER_BRANCH_${company}_${body.citizenId}`;
2024-08-20 16:17:41 +07:00
} else {
2024-09-11 15:06:27 +07:00
runningKey = `CUSTOMER_BRANCH_${company}_${body.legalPersonNo}`;
2024-08-20 16:17:41 +07:00
}
const last = await tx.runningNo.upsert({
where: { key: runningKey },
create: {
key: runningKey,
value: 1,
},
update: { value: { increment: 1 } },
});
if (headoffice) {
await tx.customerBranch.updateMany({
where: {
id: headoffice.id,
status: "CREATED",
},
data: { status: "ACTIVE" },
});
}
2024-08-20 16:17:41 +07:00
return await tx.customerBranch.create({
include: {
province: true,
district: true,
subDistrict: true,
createdBy: true,
updatedBy: true,
},
data: {
...rest,
2024-10-28 10:51:51 +07:00
code: `${runningKey.replace(`CUSTOMER_BRANCH_${company}_`, "")}-${`${last.value - 1}`.padStart(2, "0")}`,
codeCustomer: runningKey.replace(`CUSTOMER_BRANCH_${company}_`, ""),
2024-08-20 16:17:41 +07:00
customer: { connect: { id: customerId } },
2024-10-28 10:51:51 +07:00
agentUser: connectOrNot(agentUserId),
province: connectOrNot(provinceId),
district: connectOrNot(districtId),
subDistrict: connectOrNot(subDistrictId),
2024-08-20 16:17:41 +07:00
createdBy: { connect: { id: req.user.sub } },
updatedBy: { connect: { id: req.user.sub } },
},
});
2024-04-05 13:51:36 +07:00
},
2024-04-23 18:09:08 +07:00
{ isolationLevel: Prisma.TransactionIsolationLevel.Serializable },
);
2024-04-05 13:51:36 +07:00
this.setStatus(HttpStatus.CREATED);
return record;
}
2024-04-05 14:15:38 +07:00
@Put("{branchId}")
@Security("keycloak", MANAGE_ROLES)
2024-04-05 14:15:38 +07:00
async editById(
@Request() req: RequestWithUser,
@Body() body: CustomerBranchUpdate,
@Path() branchId: string,
) {
const branch = await prisma.customerBranch.findUnique({
where: { id: branchId },
include: {
customer: {
include: {
registeredBranch: {
include: branchRelationPermInclude(req.user),
},
},
},
},
});
if (!branch) throw notFoundError("Customer Branch");
await permissionCheck(req.user, branch.customer.registeredBranch);
2024-09-05 15:06:23 +07:00
if (!body.customerId) body.customerId = branch.customerId;
2024-04-05 14:15:38 +07:00
if (body.provinceId || body.districtId || body.subDistrictId || body.customerId) {
2024-10-28 10:51:51 +07:00
const [province, district, subDistrict, customer, agent] = await prisma.$transaction([
2024-04-05 14:15:38 +07:00
prisma.province.findFirst({ where: { id: body.provinceId || undefined } }),
prisma.district.findFirst({ where: { id: body.districtId || undefined } }),
prisma.subDistrict.findFirst({ where: { id: body.subDistrictId || undefined } }),
2024-09-05 15:06:23 +07:00
prisma.customer.findFirst({
where: { id: body.customerId || undefined },
include: {
registeredBranch: {
include: branchRelationPermInclude(req.user),
2024-09-05 15:06:23 +07:00
},
},
}),
2024-10-28 10:51:51 +07:00
prisma.user.findFirst({
2024-10-28 13:00:40 +07:00
where: { id: body.agentUserId || undefined },
2024-10-28 10:51:51 +07:00
include: {
branch: {
include: { branch: { include: branchRelationPermInclude(req.user) } },
},
},
}),
2024-04-05 14:15:38 +07:00
]);
2024-09-11 15:06:27 +07:00
if (body.provinceId && !province) throw relationError("Province");
if (body.districtId && !district) throw relationError("District");
if (body.subDistrictId && !subDistrict) throw relationError("SubDistrict");
2024-10-28 10:51:51 +07:00
if (body.agentUserId && !agent) throw relationError("User");
2024-09-11 15:06:27 +07:00
if (!customer) throw relationError("Customer");
2024-10-28 10:51:51 +07:00
if (agent) {
await Promise.all(
agent.branch.map(({ branch }) => permissionCheckCompany(req.user, branch)),
);
}
await permissionCheck(req.user, customer.registeredBranch);
2024-04-05 14:15:38 +07:00
}
2024-10-28 10:51:51 +07:00
const { provinceId, districtId, subDistrictId, customerId, agentUserId, ...rest } = body;
2024-08-20 16:17:41 +07:00
return await prisma.customerBranch.update({
where: { id: branchId },
include: {
province: true,
district: true,
subDistrict: true,
createdBy: true,
updatedBy: true,
},
data: {
...rest,
statusOrder: +(rest.status === "INACTIVE"),
2024-10-28 10:51:51 +07:00
agentUser: connectOrNot(agentUserId),
2024-09-11 15:06:27 +07:00
customer: connectOrNot(customerId),
province: connectOrDisconnect(provinceId),
district: connectOrDisconnect(districtId),
subDistrict: connectOrDisconnect(subDistrictId),
2024-08-20 16:17:41 +07:00
updatedBy: { connect: { id: req.user.sub } },
},
});
2024-04-05 14:15:38 +07:00
}
2024-04-05 15:13:33 +07:00
@Delete("{branchId}")
@Security("keycloak", MANAGE_ROLES)
2024-09-05 15:06:23 +07:00
async delete(@Request() req: RequestWithUser, @Path() branchId: string) {
2024-06-07 10:44:40 +07:00
const record = await prisma.customerBranch.findFirst({
where: { id: branchId },
2024-09-05 15:06:23 +07:00
include: {
customer: {
include: {
registeredBranch: {
include: branchRelationPermInclude(req.user),
2024-09-05 15:06:23 +07:00
},
},
},
},
2024-06-07 10:44:40 +07:00
});
2024-04-05 15:13:33 +07:00
2024-09-11 15:06:27 +07:00
if (!record) throw notFoundError("Customer Branch");
2024-04-05 15:13:33 +07:00
await permissionCheck(req.user, record.customer.registeredBranch);
2024-09-05 15:06:23 +07:00
if (record.status !== Status.CREATED) throw isUsedError("Customer Branch");
2024-04-05 15:13:33 +07:00
return await prisma.$transaction(async (tx) => {
if (record.code.endsWith("00")) {
await Promise.all([
tx.customer.delete({
where: { id: record.customerId },
}),
tx.runningNo.delete({
where: { key: record.code.slice(0, -3) },
}),
]);
}
return await prisma.customerBranch
.delete({
include: { createdBy: true, updatedBy: true },
where: { id: branchId },
})
.then((v) =>
Promise.all([
deleteFolder(fileLocation.customerBranch.attachment(branchId)),
deleteFolder(fileLocation.customerBranch.citizen(branchId)),
deleteFolder(fileLocation.customerBranch.powerOfAttorney(branchId)),
deleteFolder(fileLocation.customerBranch.vatRegistration(branchId)),
deleteFolder(fileLocation.customerBranch.houseRegistration(branchId)),
deleteFolder(fileLocation.customerBranch.commercialRegistration(branchId)),
]).then(() => v),
);
});
2024-06-07 10:44:40 +07:00
}
}
2024-09-16 17:20:51 +07:00
@Route("api/v1/customer-branch/{branchId}")
export class CustomerBranchFileController extends Controller {
private async checkPermission(user: RequestWithUser["user"], id: string) {
const data = await prisma.customerBranch.findFirst({
where: { id },
include: {
customer: {
include: {
registeredBranch: {
include: branchRelationPermInclude(user),
},
},
},
},
2024-06-07 10:44:40 +07:00
});
2024-09-16 17:20:51 +07:00
if (!data) throw notFoundError("Customer Branch");
await permissionCheck(user, data.customer.registeredBranch);
}
2024-06-07 10:44:40 +07:00
2024-09-16 17:20:51 +07:00
@Get("attachment")
@Security("keycloak")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch")
2024-09-16 17:20:51 +07:00
async listAttachment(@Request() req: RequestWithUser, @Path() branchId: string) {
await this.checkPermission(req.user, branchId);
return await listFile(fileLocation.customerBranch.attachment(branchId));
}
2024-06-07 10:44:40 +07:00
2024-09-16 17:20:51 +07:00
@Get("attachment/{name}")
@Security("keycloak")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch")
2024-09-16 17:20:51 +07:00
async getAttachment(@Path() branchId: string, @Path() name: string) {
return await getFile(fileLocation.customerBranch.attachment(branchId, name));
}
2024-06-07 10:44:40 +07:00
2024-10-22 10:43:20 +07:00
@Head("attachment/{name}")
@Security("keycloak")
@Tags("Customer Branch")
async headAttachment(@Path() branchId: string, @Path() name: string) {
return await getPresigned("head", fileLocation.customerBranch.attachment(branchId, name));
}
2024-09-16 17:20:51 +07:00
@Put("attachment/{name}")
@Security("keycloak")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch")
2024-09-16 17:20:51 +07:00
async putAttachment(
@Request() req: RequestWithUser,
@Path() branchId: string,
@Path() name: string,
) {
await this.checkPermission(req.user, branchId);
return await setFile(fileLocation.customerBranch.attachment(branchId, name));
2024-06-07 10:44:40 +07:00
}
2024-09-16 17:20:51 +07:00
@Delete("attachment/{name}")
@Security("keycloak")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch")
2024-09-16 17:20:51 +07:00
async delAttachment(
@Request() req: RequestWithUser,
@Path() branchId: string,
2024-09-16 17:20:51 +07:00
@Path() name: string,
) {
2024-09-16 17:20:51 +07:00
await this.checkPermission(req.user, branchId);
return await deleteFile(fileLocation.customerBranch.attachment(branchId, name));
}
2024-09-16 17:20:51 +07:00
@Get("file-citizen")
@Security("keycloak")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch Citizen")
2024-09-16 17:20:51 +07:00
async listCitizen(@Request() req: RequestWithUser, @Path() branchId: string) {
await this.checkPermission(req.user, branchId);
2025-02-18 15:38:54 +07:00
return await listFile(fileLocation.customerBranch.citizen(branchId));
2024-09-16 17:20:51 +07:00
}
@Get("file-citizen/{id}")
@Security("keycloak")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch Citizen")
2024-09-16 17:20:51 +07:00
async getCitizen(@Path() branchId: string, @Path() id: string) {
2025-02-18 15:38:54 +07:00
return await getFile(fileLocation.customerBranch.citizen(branchId, id));
2024-09-16 17:20:51 +07:00
}
@Put("file-citizen/{id}")
@Security("keycloak")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch Citizen")
2024-09-16 17:20:51 +07:00
async putCitizen(@Request() req: RequestWithUser, @Path() branchId: string, @Path() id: string) {
await this.checkPermission(req.user, branchId);
2025-02-18 15:38:54 +07:00
return req.res?.redirect(await setFile(fileLocation.customerBranch.citizen(branchId, id)));
2024-09-16 17:20:51 +07:00
}
@Delete("file-citizen/{id}")
@Security("keycloak")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch Citizen")
2024-09-16 17:20:51 +07:00
async delCitizen(@Request() req: RequestWithUser, @Path() branchId: string, @Path() id: string) {
await this.checkPermission(req.user, branchId);
return await deleteFile(fileLocation.customerBranch.citizen(branchId, id));
}
@Get("file-power-of-attorney")
@Security("keycloak")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch Power of Attorney")
2024-09-16 17:20:51 +07:00
async listPoa(@Request() req: RequestWithUser, @Path() branchId: string) {
await this.checkPermission(req.user, branchId);
return await listFile(fileLocation.customerBranch.powerOfAttorney(branchId));
}
@Get("file-power-of-attorney/{id}")
@Security("keycloak")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch Power of Attorney")
2024-09-16 17:20:51 +07:00
async getPoa(@Path() branchId: string, @Path() id: string) {
return await getFile(fileLocation.customerBranch.powerOfAttorney(branchId, id));
}
2024-09-16 17:20:51 +07:00
@Put("file-power-of-attorney/{id}")
@Security("keycloak")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch Power of Attorney")
2024-09-16 17:20:51 +07:00
async putPoa(@Request() req: RequestWithUser, @Path() branchId: string, @Path() id: string) {
await this.checkPermission(req.user, branchId);
return req.res?.redirect(
await setFile(fileLocation.customerBranch.powerOfAttorney(branchId, id)),
);
}
2024-09-16 17:20:51 +07:00
@Delete("file-power-of-attorney/{id}")
@Security("keycloak")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch Power of Attorney")
2024-09-16 17:20:51 +07:00
async delPoa(@Request() req: RequestWithUser, @Path() branchId: string, @Path() id: string) {
await this.checkPermission(req.user, branchId);
return await deleteFile(fileLocation.customerBranch.powerOfAttorney(branchId, id));
}
@Get("file-house-registration")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch House Registration")
2024-09-16 17:20:51 +07:00
@Security("keycloak")
async listHouseRegis(@Request() req: RequestWithUser, @Path() branchId: string) {
await this.checkPermission(req.user, branchId);
return await listFile(fileLocation.customerBranch.houseRegistration(branchId));
}
@Get("file-house-registration/{id}")
@Security("keycloak")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch House Registration")
2024-09-16 17:20:51 +07:00
async getHouseRegis(@Path() branchId: string, @Path() id: string) {
return await getFile(fileLocation.customerBranch.houseRegistration(branchId, id));
}
@Put("file-house-registration/{id}")
@Security("keycloak")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch House Registration")
2024-09-16 17:20:51 +07:00
async putHouseRegis(
@Request() req: RequestWithUser,
@Path() branchId: string,
2024-09-16 17:20:51 +07:00
@Path() id: string,
) {
2024-09-16 17:20:51 +07:00
await this.checkPermission(req.user, branchId);
return req.res?.redirect(
await setFile(fileLocation.customerBranch.houseRegistration(branchId, id)),
);
}
2024-06-07 10:44:40 +07:00
2024-09-16 17:20:51 +07:00
@Delete("file-house-registration/{id}")
@Security("keycloak")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch House Registration")
2024-09-16 17:20:51 +07:00
async delHouseRegis(
@Request() req: RequestWithUser,
@Path() branchId: string,
@Path() id: string,
) {
await this.checkPermission(req.user, branchId);
return await deleteFile(fileLocation.customerBranch.houseRegistration(branchId, id));
}
@Get("file-commercial-registration")
@Security("keycloak")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch Commercial Registration")
2024-09-16 17:20:51 +07:00
async listCommercialRegis(@Request() req: RequestWithUser, @Path() branchId: string) {
await this.checkPermission(req.user, branchId);
return await listFile(fileLocation.customerBranch.commercialRegistration(branchId));
}
2024-06-07 10:44:40 +07:00
2024-09-16 17:20:51 +07:00
@Get("file-commercial-registration/{id}")
@Security("keycloak")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch Commercial Registration")
2024-09-16 17:20:51 +07:00
async getCommercialRegis(@Path() branchId: string, @Path() id: string) {
return await getFile(fileLocation.customerBranch.commercialRegistration(branchId, id));
}
@Put("file-commercial-registration/{id}")
@Security("keycloak")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch Commercial Registration")
2024-09-16 17:20:51 +07:00
async putCommercialRegis(
@Request() req: RequestWithUser,
@Path() branchId: string,
@Path() id: string,
) {
await this.checkPermission(req.user, branchId);
return req.res?.redirect(
2024-09-16 17:20:51 +07:00
await setFile(fileLocation.customerBranch.commercialRegistration(branchId, id)),
2024-06-07 10:44:40 +07:00
);
}
2024-09-16 17:20:51 +07:00
@Delete("file-commercial-registration/{id}")
@Security("keycloak")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch Commercial Registration")
2024-09-16 17:20:51 +07:00
async delCommercialRegis(
@Request() req: RequestWithUser,
@Path() branchId: string,
@Path() id: string,
) {
await this.checkPermission(req.user, branchId);
return await deleteFile(fileLocation.customerBranch.commercialRegistration(branchId, id));
}
2024-06-07 10:44:40 +07:00
2024-09-16 17:20:51 +07:00
@Get("file-vat-registration")
@Security("keycloak")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch Vat Registration")
2024-09-16 17:20:51 +07:00
async listVatRegis(@Request() req: RequestWithUser, @Path() branchId: string) {
await this.checkPermission(req.user, branchId);
return await listFile(fileLocation.customerBranch.vatRegistration(branchId));
}
@Get("file-vat-registration/{id}")
@Security("keycloak")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch Vat Registration")
2024-09-16 17:20:51 +07:00
async getVatRegis(@Path() branchId: string, @Path() id: string) {
return await getFile(fileLocation.customerBranch.vatRegistration(branchId, id));
}
2024-06-07 10:44:40 +07:00
2024-09-16 17:20:51 +07:00
@Put("file-vat-registration/{id}")
@Security("keycloak")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch Vat Registration")
2024-09-16 17:20:51 +07:00
async putVatRegis(@Request() req: RequestWithUser, @Path() branchId: string, @Path() id: string) {
await this.checkPermission(req.user, branchId);
return req.res?.redirect(
await setFile(fileLocation.customerBranch.vatRegistration(branchId, id)),
2024-06-07 10:44:40 +07:00
);
2024-04-05 15:13:33 +07:00
}
2024-09-16 17:20:51 +07:00
@Delete("file-vat-registration/{id}")
@Security("keycloak")
2024-09-17 08:54:47 +07:00
@Tags("Customer Branch Vat Registration")
2024-09-16 17:20:51 +07:00
async delVatRegis(@Request() req: RequestWithUser, @Path() branchId: string, @Path() id: string) {
await this.checkPermission(req.user, branchId);
return await deleteFile(fileLocation.customerBranch.vatRegistration(branchId, id));
}
2024-04-05 11:37:40 +07:00
}