feat: get branch endpoint
This commit is contained in:
parent
3a53397745
commit
59a79a3374
1 changed files with 43 additions and 0 deletions
|
|
@ -22,4 +22,47 @@ import { RequestWithUser } from "../../interfaces/user";
|
|||
@Tags("Branch")
|
||||
@Security("keycloak")
|
||||
export class BranchController extends Controller {
|
||||
@Get()
|
||||
async getBranch(
|
||||
@Query() zipCode?: string,
|
||||
@Query() query: string = "",
|
||||
@Query() page: number = 1,
|
||||
@Query() pageSize: number = 30,
|
||||
) {
|
||||
const where = {
|
||||
OR: [
|
||||
{ nameEN: { contains: query }, zipCode },
|
||||
{ nameTH: { contains: query }, zipCode },
|
||||
{ email: { contains: query }, zipCode },
|
||||
],
|
||||
} satisfies Prisma.BranchWhereInput;
|
||||
|
||||
const [result, total] = await prisma.$transaction([
|
||||
prisma.branch.findMany({
|
||||
include: {
|
||||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
},
|
||||
where,
|
||||
take: pageSize,
|
||||
skip: (page - 1) * pageSize,
|
||||
}),
|
||||
prisma.branch.count({ where }),
|
||||
]);
|
||||
|
||||
return { result, page, pageSize, total };
|
||||
}
|
||||
|
||||
@Get("{branchId}")
|
||||
async getBranchById(@Path() branchId: string) {
|
||||
return await prisma.branch.findFirst({
|
||||
include: {
|
||||
province: true,
|
||||
district: true,
|
||||
subDistrict: true,
|
||||
},
|
||||
where: { id: branchId },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue