feat: add parameter to accept shared product

This commit is contained in:
Methapon Metanipat 2024-11-05 07:20:26 +07:00
parent 1a31a29680
commit b758067e14

View file

@ -121,6 +121,7 @@ export class ProductController extends Controller {
async getProduct(
@Request() req: RequestWithUser,
@Query() status?: Status,
@Query() shared?: boolean,
@Query() productGroupId?: string,
@Query() query: string = "",
@Query() page: number = 1,
@ -134,22 +135,41 @@ export class ProductController extends Controller {
]),
AND: {
...filterStatus(status),
productGroupId,
OR: isSystem(req.user)
? undefined
: [
{
productGroup: {
registeredBranch: { OR: permissionCond(req.user) },
OR: [
...(productGroupId
? [
shared
? {
OR: [
{ productGroupId },
{
productGroup: {
shared: true,
registeredBranch: { OR: permissionCondCompany(req.user) },
},
},
],
}
: { productGroupId },
]
: []),
...(isSystem(req.user)
? []
: [
{
shared: true,
productGroup: {
registeredBranch: { OR: permissionCondCompany(req.user) },
},
},
},
{
shared: true,
productGroup: {
registeredBranch: { OR: permissionCondCompany(req.user) },
{
productGroup: {
shared: true,
registeredBranch: { OR: permissionCondCompany(req.user) },
},
},
},
],
]),
],
},
} satisfies Prisma.ProductWhereInput;