feat: get employee of customer branch
This commit is contained in:
parent
910c8b50e4
commit
620a57c6c6
1 changed files with 50 additions and 0 deletions
|
|
@ -121,6 +121,56 @@ export class CustomerBranchController extends Controller {
|
||||||
return { result, page, pageSize, total };
|
return { result, page, pageSize, total };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get("{branchId}/employee")
|
||||||
|
async listEmployee(
|
||||||
|
@Path() branchId: string,
|
||||||
|
@Query() zipCode?: string,
|
||||||
|
@Query() query: string = "",
|
||||||
|
@Query() page: number = 1,
|
||||||
|
@Query() pageSize: number = 30,
|
||||||
|
) {
|
||||||
|
const where = {
|
||||||
|
AND: { customerBranchId: branchId },
|
||||||
|
OR: [
|
||||||
|
{ firstName: { contains: query }, zipCode },
|
||||||
|
{ firstNameEN: { contains: query }, zipCode },
|
||||||
|
{ lastName: { contains: query }, zipCode },
|
||||||
|
{ lastNameEN: { contains: query }, zipCode },
|
||||||
|
{ email: { contains: query }, zipCode },
|
||||||
|
],
|
||||||
|
} satisfies Prisma.EmployeeWhereInput;
|
||||||
|
|
||||||
|
const [result, total] = await prisma.$transaction([
|
||||||
|
prisma.employee.findMany({
|
||||||
|
include: {
|
||||||
|
province: true,
|
||||||
|
district: true,
|
||||||
|
subDistrict: true,
|
||||||
|
},
|
||||||
|
where,
|
||||||
|
take: pageSize,
|
||||||
|
skip: (page - 1) * pageSize,
|
||||||
|
}),
|
||||||
|
prisma.employee.count({ where }),
|
||||||
|
]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
result: await Promise.all(
|
||||||
|
result.map(async (v) => ({
|
||||||
|
...v,
|
||||||
|
profileImageUrl: await minio.presignedGetObject(
|
||||||
|
MINIO_BUCKET,
|
||||||
|
imageLocation(v.id),
|
||||||
|
12 * 60 * 60,
|
||||||
|
),
|
||||||
|
})),
|
||||||
|
),
|
||||||
|
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