init to statistics and manage pos type users
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
// src/common/guards/permissions.guard.ts
|
||||
import { ITokenPayload } from '@/modules/auth/auth.utils'
|
||||
import { PrismaService } from '@/prisma/prisma.service'
|
||||
import { ExecutionContext, ForbiddenException, Injectable } from '@nestjs/common'
|
||||
import {
|
||||
ExecutionContext,
|
||||
ForbiddenException,
|
||||
Injectable,
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common'
|
||||
import { Request as ExpressRequest } from 'express'
|
||||
|
||||
@Injectable()
|
||||
@@ -12,8 +17,12 @@ export class ConsumerGuard {
|
||||
tokenPayload: ITokenPayload,
|
||||
context: ExecutionContext,
|
||||
): Promise<boolean> {
|
||||
if (!tokenPayload || tokenPayload.type !== 'CONSUMER') {
|
||||
throw new ForbiddenException('شما دسترسی لازم را ندارید.')
|
||||
if (
|
||||
!tokenPayload ||
|
||||
tokenPayload.type !== 'CONSUMER' ||
|
||||
tokenPayload.role !== 'OWNER'
|
||||
) {
|
||||
throw new UnauthorizedException()
|
||||
}
|
||||
|
||||
const consumer = await this.prisma.consumer.findFirst({
|
||||
|
||||
@@ -62,7 +62,7 @@ export class JwtAuthGuard implements CanActivate {
|
||||
if (req.url.startsWith('/api/v1/consumer')) {
|
||||
await this.consumerGuard.canActivate(tokenPayload, context)
|
||||
} else if (req.url.startsWith('/api/v1/pos')) {
|
||||
await this.consumerGuard.canActivate(tokenPayload, context)
|
||||
// await this.consumerGuard.canActivate(tokenPayload, context)
|
||||
await this.posGuard.canActivate(tokenPayload, context)
|
||||
} else if (tokenPayload.type != 'ADMIN') {
|
||||
throw new ForbiddenException('شما دسترسی لازم را ندارید')
|
||||
|
||||
Reference in New Issue
Block a user