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