feat: add count gender by query
This commit is contained in:
parent
bd00bcbbe1
commit
d23e404196
1 changed files with 21 additions and 2 deletions
|
|
@ -210,12 +210,31 @@ export class EmployeeController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get("stats/gender")
|
@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
|
return await prisma.employee
|
||||||
.groupBy({
|
.groupBy({
|
||||||
_count: true,
|
_count: true,
|
||||||
by: ["gender"],
|
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) =>
|
.then((res) =>
|
||||||
res.reduce<Record<string, number>>((a, c) => {
|
res.reduce<Record<string, number>>((a, c) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue