diff --git a/src/controllers/customer-branch-controller.ts b/src/controllers/customer-branch-controller.ts index 4312eb6..e13984c 100644 --- a/src/controllers/customer-branch-controller.ts +++ b/src/controllers/customer-branch-controller.ts @@ -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) {