feat: customer permission
This commit is contained in:
parent
26b21209d4
commit
6926d9367c
1 changed files with 40 additions and 2 deletions
|
|
@ -78,10 +78,36 @@ function imageLocation(id: string) {
|
|||
export class CustomerController extends Controller {
|
||||
@Get("type-stats")
|
||||
@Security("keycloak")
|
||||
async stat() {
|
||||
async stat(@Request() req: RequestWithUser) {
|
||||
const list = await prisma.customer.groupBy({
|
||||
by: "customerType",
|
||||
_count: true,
|
||||
where: {
|
||||
registeredBranch: isSystem(req.user)
|
||||
? undefined
|
||||
: {
|
||||
OR: [
|
||||
{
|
||||
user: { some: { userId: req.user.sub } },
|
||||
},
|
||||
{
|
||||
branch: globalAllow(req.user)
|
||||
? { some: { user: { some: { userId: req.user.sub } } } }
|
||||
: undefined,
|
||||
},
|
||||
{
|
||||
headOffice: globalAllow(req.user)
|
||||
? { branch: { some: { user: { some: { userId: req.user.sub } } } } }
|
||||
: undefined,
|
||||
},
|
||||
{
|
||||
headOffice: globalAllow(req.user)
|
||||
? { user: { some: { userId: req.user.sub } } }
|
||||
: undefined,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return list.reduce<Record<CustomerType, number>>(
|
||||
|
|
@ -126,12 +152,24 @@ export class CustomerController extends Controller {
|
|||
? undefined
|
||||
: {
|
||||
OR: [
|
||||
{ user: { some: { userId: req.user.sub } } },
|
||||
{
|
||||
user: { some: { userId: req.user.sub } },
|
||||
},
|
||||
{
|
||||
branch: globalAllow(req.user)
|
||||
? { some: { user: { some: { userId: req.user.sub } } } }
|
||||
: undefined,
|
||||
},
|
||||
{
|
||||
headOffice: globalAllow(req.user)
|
||||
? { branch: { some: { user: { some: { userId: req.user.sub } } } } }
|
||||
: undefined,
|
||||
},
|
||||
{
|
||||
headOffice: globalAllow(req.user)
|
||||
? { user: { some: { userId: req.user.sub } } }
|
||||
: undefined,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue