feat: add support for active only service

resolves https://github.com/Frappet/jws-frontend/issues/148
This commit is contained in:
Methapon2001 2024-12-18 17:50:15 +07:00
parent a62d729ce6
commit b05d2fe9d4

View file

@ -154,6 +154,7 @@ export class ServiceController extends Controller {
@Query() status?: Status,
@Query() productGroupId?: string,
@Query() fullDetail?: boolean,
@Query() activeOnly?: boolean,
) {
const where = {
OR: queryOrNot<Prisma.ServiceWhereInput[]>(query, [
@ -162,20 +163,31 @@ export class ServiceController extends Controller {
{ code: { contains: query, mode: "insensitive" } },
]),
AND: {
...filterStatus(status),
...filterStatus(activeOnly ? Status.ACTIVE : status),
productGroupId,
productGroup: {
status: activeOnly ? { not: Status.INACTIVE } : undefined,
registeredBranch: activeOnly
? {
OR: [
{ headOffice: { status: { not: Status.INACTIVE } } },
{ headOffice: null, status: { not: Status.INACTIVE } },
],
}
: undefined,
},
OR: isSystem(req.user)
? undefined
: [
{
productGroup: {
registeredBranch: { OR: permissionCond(req.user) },
registeredBranch: { OR: permissionCond(req.user, { activeOnly }) },
},
},
{
shared: true,
productGroup: {
registeredBranch: { OR: permissionCondShared(req.user) },
registeredBranch: { OR: permissionCondShared(req.user, { activeOnly }) },
},
},
],