init to statistics and manage pos type users

This commit is contained in:
2026-04-13 13:21:50 +03:30
parent 9cef733370
commit 388aa25de4
31 changed files with 385 additions and 251 deletions
+12 -3
View File
@@ -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({
+1 -1
View File
@@ -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('شما دسترسی لازم را ندارید')