feat: list customer branch

This commit is contained in:
Methapon2001 2024-04-05 14:55:24 +07:00
parent 011d53d655
commit 910c8b50e4

View file

@ -89,6 +89,38 @@ type CustomerBranchUpdate = {
@Tags("Customer Branch")
@Security("keycloak")
export class CustomerBranchController extends Controller {
@Get()
async list(
@Query() zipCode?: string,
@Query() query: string = "",
@Query() page: number = 1,
@Query() pageSize: number = 30,
) {
const where = {
OR: [
{ nameEN: { contains: query }, zipCode },
{ name: { contains: query }, zipCode },
{ email: { contains: query }, zipCode },
],
} satisfies Prisma.BranchWhereInput;
const [result, total] = await prisma.$transaction([
prisma.customerBranch.findMany({
include: {
province: true,
district: true,
subDistrict: true,
},
where,
take: pageSize,
skip: (page - 1) * pageSize,
}),
prisma.customerBranch.count({ where }),
]);
return { result, page, pageSize, total };
}
@Post()
async create(@Request() req: RequestWithUser, @Body() body: CustomerBranchCreate) {
if (body.provinceId || body.districtId || body.subDistrictId || body.customerId) {