feat: list customer branch
This commit is contained in:
parent
011d53d655
commit
910c8b50e4
1 changed files with 32 additions and 0 deletions
|
|
@ -89,6 +89,38 @@ type CustomerBranchUpdate = {
|
||||||
@Tags("Customer Branch")
|
@Tags("Customer Branch")
|
||||||
@Security("keycloak")
|
@Security("keycloak")
|
||||||
export class CustomerBranchController extends Controller {
|
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()
|
@Post()
|
||||||
async create(@Request() req: RequestWithUser, @Body() body: CustomerBranchCreate) {
|
async create(@Request() req: RequestWithUser, @Body() body: CustomerBranchCreate) {
|
||||||
if (body.provinceId || body.districtId || body.subDistrictId || body.customerId) {
|
if (body.provinceId || body.districtId || body.subDistrictId || body.customerId) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue