diff --git a/src/controllers/employee-controller.ts b/src/controllers/employee-controller.ts index e46973b..eb3f62b 100644 --- a/src/controllers/employee-controller.ts +++ b/src/controllers/employee-controller.ts @@ -210,12 +210,31 @@ export class EmployeeController extends Controller { } @Get("stats/gender") - async getEmployeeStatsGender(@Query() customerBranchId?: string) { + async getEmployeeStatsGender( + @Query() customerBranchId?: string, + @Query() status?: Status, + @Query() query: string = "", + ) { + const filterStatus = (val?: Status) => { + if (!val) return {}; + + return val !== Status.CREATED && val !== Status.ACTIVE + ? { status: val } + : { OR: [{ status: Status.CREATED }, { status: Status.ACTIVE }] }; + }; + return await prisma.employee .groupBy({ _count: true, by: ["gender"], - where: { customerBranchId }, + where: { + OR: [ + { firstName: { contains: query }, customerBranchId, ...filterStatus(status) }, + { firstNameEN: { contains: query }, customerBranchId, ...filterStatus(status) }, + { lastName: { contains: query }, customerBranchId, ...filterStatus(status) }, + { lastNameEN: { contains: query }, customerBranchId, ...filterStatus(status) }, + ], + }, }) .then((res) => res.reduce>((a, c) => {