diff --git a/src/controllers/04-product-controller.ts b/src/controllers/04-product-controller.ts index 18fd275..fb80973 100644 --- a/src/controllers/04-product-controller.ts +++ b/src/controllers/04-product-controller.ts @@ -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;