feat: get branch endpoint

This commit is contained in:
Methapon2001 2024-04-02 09:29:20 +07:00
parent 3a53397745
commit 59a79a3374

View file

@ -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 },
});
}
}