feat: add support for active only product
resolves https://github.com/Frappet/jws-frontend/issues/146
This commit is contained in:
parent
b05d2fe9d4
commit
978eb0eee2
1 changed files with 20 additions and 4 deletions
|
|
@ -130,6 +130,7 @@ export class ProductController extends Controller {
|
|||
@Query() pageSize: number = 30,
|
||||
@Query() orderField?: keyof Product,
|
||||
@Query() orderBy?: "asc" | "desc",
|
||||
@Query() activeOnly?: boolean,
|
||||
) {
|
||||
const where = {
|
||||
OR: queryOrNot<Prisma.ProductWhereInput[]>(query, [
|
||||
|
|
@ -138,7 +139,18 @@ export class ProductController extends Controller {
|
|||
{ code: { contains: query, mode: "insensitive" } },
|
||||
]),
|
||||
AND: {
|
||||
...filterStatus(status),
|
||||
...filterStatus(activeOnly ? Status.ACTIVE : status),
|
||||
productGroup: {
|
||||
status: activeOnly ? { not: Status.INACTIVE } : undefined,
|
||||
registeredBranch: activeOnly
|
||||
? {
|
||||
OR: [
|
||||
{ headOffice: { status: { not: Status.INACTIVE } } },
|
||||
{ headOffice: null, status: { not: Status.INACTIVE } },
|
||||
],
|
||||
}
|
||||
: undefined,
|
||||
},
|
||||
OR: [
|
||||
...(productGroupId
|
||||
? [
|
||||
|
|
@ -149,13 +161,17 @@ export class ProductController extends Controller {
|
|||
{
|
||||
shared: true,
|
||||
productGroup: {
|
||||
registeredBranch: { OR: permissionCondCompany(req.user) },
|
||||
registeredBranch: {
|
||||
OR: permissionCondCompany(req.user, { activeOnly }),
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
productGroup: {
|
||||
shared: true,
|
||||
registeredBranch: { OR: permissionCondCompany(req.user) },
|
||||
registeredBranch: {
|
||||
OR: permissionCondCompany(req.user, { activeOnly }),
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
|
|
@ -169,7 +185,7 @@ export class ProductController extends Controller {
|
|||
{
|
||||
productGroup: {
|
||||
id: productGroupId,
|
||||
registeredBranch: { OR: permissionCondCompany(req.user) },
|
||||
registeredBranch: { OR: permissionCondCompany(req.user, { activeOnly }) },
|
||||
},
|
||||
},
|
||||
]),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue