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