update permissions

This commit is contained in:
2026-01-04 23:24:31 +03:30
parent 2f4356e8da
commit 76a7e54192
5 changed files with 28 additions and 9 deletions
@@ -1,4 +1,4 @@
import { Controller, Get, Body, Param, UseGuards, Query, Patch, Put } from '@nestjs/common'; import { Controller, Get, Body, Param, UseGuards, Query, Patch, Put, Post } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam, ApiQuery, ApiHeader } from '@nestjs/swagger'; import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam, ApiQuery, ApiHeader } from '@nestjs/swagger';
import { NotificationService } from '../services/notification.service'; import { NotificationService } from '../services/notification.service';
import { NotificationPreferenceService } from '../services/notification-preference.service'; import { NotificationPreferenceService } from '../services/notification-preference.service';
@@ -7,6 +7,7 @@ import { UserId } from '../../../common/decorators/user-id.decorator';
import { AdminAuthGuard } from '../../auth/guards/adminAuth.guard'; import { AdminAuthGuard } from '../../auth/guards/adminAuth.guard';
import { RestId } from '../../../common/decorators/rest-id.decorator'; import { RestId } from '../../../common/decorators/rest-id.decorator';
import { UpdatePreferenceDto } from '../dto/update-preference.dto'; import { UpdatePreferenceDto } from '../dto/update-preference.dto';
import { CreatePreferenceDto } from '../dto/create-preference.dto';
import { AdminId } from 'src/common/decorators/admin-id.decorator'; import { AdminId } from 'src/common/decorators/admin-id.decorator';
import { API_HEADER_SLUG } from 'src/common/constants/index'; import { API_HEADER_SLUG } from 'src/common/constants/index';
import { NotificationMessage } from 'src/common/enums/message.enum'; import { NotificationMessage } from 'src/common/enums/message.enum';
@@ -106,7 +107,7 @@ export class NotificationsController {
@UseGuards(AdminAuthGuard) @UseGuards(AdminAuthGuard)
@ApiBearerAuth() @ApiBearerAuth()
@Get('admin/notifications/unseen-count') @Get('admin/notifications/unseen-count')
@ApiOperation({ summary: 'Get unseen notifications count for admin' }) @ApiOperation({ summary: 'Get unseen notifications count for admin' })
async getAdminUnseenCount(@AdminId() adminId: string, @RestId() restaurantId: string) { async getAdminUnseenCount(@AdminId() adminId: string, @RestId() restaurantId: string) {
const count = await this.notificationService.countUnseenByRestaurant(adminId, restaurantId); const count = await this.notificationService.countUnseenByRestaurant(adminId, restaurantId);
@@ -155,6 +156,20 @@ export class NotificationsController {
return this.preferenceService.updatePreference(preferenceId, restaurantId, dto); return this.preferenceService.updatePreference(preferenceId, restaurantId, dto);
} }
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@Permissions(Permission.MANAGE_SETTINGS)
@Post('admin/notification-preferences')
@ApiOperation({ summary: 'Create notification preference' })
async createPreference(
@RestId() restaurantId: string,
@Body() dto: CreatePreferenceDto,
) {
return this.preferenceService.create(restaurantId, dto);
}
//here
// @UseGuards(SuperAdminAuthGuard) // @UseGuards(SuperAdminAuthGuard)
@ApiBearerAuth() @ApiBearerAuth()
@Get('super-admin/notifications/sms-count') @Get('super-admin/notifications/sms-count')
@@ -8,9 +8,9 @@ import { NotifTitleEnum } from '../interfaces/notification.interface';
@Injectable() @Injectable()
export class NotificationPreferenceService { export class NotificationPreferenceService {
constructor(private readonly em: EntityManager) {} constructor(private readonly em: EntityManager) { }
async createOrUpdate(restaurantId: string, dto: CreatePreferenceDto): Promise<NotificationPreference> { async create(restaurantId: string, dto: CreatePreferenceDto): Promise<NotificationPreference> {
const restaurant = await this.em.findOne(Restaurant, { id: restaurantId }); const restaurant = await this.em.findOne(Restaurant, { id: restaurantId });
if (!restaurant) { if (!restaurant) {
throw new NotFoundException('Restaurant not found'); throw new NotFoundException('Restaurant not found');
@@ -102,7 +102,7 @@ export class OrdersController {
} }
@UseGuards(AdminAuthGuard) @UseGuards(AdminAuthGuard)
@Permissions(Permission.MANAGE_ORDERS) @Permissions(Permission.VIEW_REPORTS)
@ApiOperation({ summary: 'Get Stats for report page' }) @ApiOperation({ summary: 'Get Stats for report page' })
@Get('admin/orders/stats') @Get('admin/orders/stats')
findStats(@RestId() restId: string) { findStats(@RestId() restId: string) {
@@ -110,7 +110,7 @@ export class OrdersController {
} }
@UseGuards(AdminAuthGuard) @UseGuards(AdminAuthGuard)
@Permissions(Permission.MANAGE_ORDERS) @Permissions(Permission.VIEW_REPORTS)
@ApiOperation({ summary: 'Get food sales pie chart data for last month' }) @ApiOperation({ summary: 'Get food sales pie chart data for last month' })
@ApiHeader(API_HEADER_SLUG) @ApiHeader(API_HEADER_SLUG)
@Get('admin/orders/food-sales-pie-chart') @Get('admin/orders/food-sales-pie-chart')
@@ -132,7 +132,7 @@ export class PaymentsController {
} }
@UseGuards(AdminAuthGuard) @UseGuards(AdminAuthGuard)
@Permissions(Permission.MANAGE_PAYMENTS) @Permissions(Permission.VIEW_REPORTS)
@ApiBearerAuth() @ApiBearerAuth()
@Get('admin/payments/chart') @Get('admin/payments/chart')
@ApiOperation({ summary: 'Get payment chart data with date and period filters' }) @ApiOperation({ summary: 'Get payment chart data with date and period filters' })
+6 -2
View File
@@ -12,12 +12,16 @@ export const rolesData: RoleConfig[] = [
isSystem: false, isSystem: false,
permissionFilter: (name: Permission) => permissionFilter: (name: Permission) =>
name === Permission.MANAGE_FOODS || name === Permission.MANAGE_FOODS ||
name === Permission.MANAGE_CATEGORIES || name === Permission.MANAGE_CATEGORIES ||
name === Permission.MANAGE_SCHEDULES || name === Permission.MANAGE_SCHEDULES ||
name === Permission.MANAGE_PAGER || name === Permission.MANAGE_PAGER ||
name === Permission.MANAGE_CONTACTS || name === Permission.MANAGE_CONTACTS ||
name === Permission.MANAGE_ROLES || name === Permission.MANAGE_ROLES ||
name === Permission.MANAGE_SETTINGS
name === Permission.MANAGE_SETTINGS ||
name === Permission.MANAGE_ADMINS ||
name == Permission.VIEW_REPORTS ||
name == Permission.UPDATE_RESTAURANT
}, },
{ {
name: 'مدیر ( پلن ویژه)', name: 'مدیر ( پلن ویژه)',