diff --git a/src/modules/notifications/controllers/notifications.controller.ts b/src/modules/notifications/controllers/notifications.controller.ts index 1952192..934512e 100644 --- a/src/modules/notifications/controllers/notifications.controller.ts +++ b/src/modules/notifications/controllers/notifications.controller.ts @@ -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 { NotificationService } from '../services/notification.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 { RestId } from '../../../common/decorators/rest-id.decorator'; import { UpdatePreferenceDto } from '../dto/update-preference.dto'; +import { CreatePreferenceDto } from '../dto/create-preference.dto'; import { AdminId } from 'src/common/decorators/admin-id.decorator'; import { API_HEADER_SLUG } from 'src/common/constants/index'; import { NotificationMessage } from 'src/common/enums/message.enum'; @@ -106,7 +107,7 @@ export class NotificationsController { @UseGuards(AdminAuthGuard) @ApiBearerAuth() - @Get('admin/notifications/unseen-count') + @Get('admin/notifications/unseen-count') @ApiOperation({ summary: 'Get unseen notifications count for admin' }) async getAdminUnseenCount(@AdminId() adminId: string, @RestId() restaurantId: string) { const count = await this.notificationService.countUnseenByRestaurant(adminId, restaurantId); @@ -155,6 +156,20 @@ export class NotificationsController { 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) @ApiBearerAuth() @Get('super-admin/notifications/sms-count') diff --git a/src/modules/notifications/services/notification-preference.service.ts b/src/modules/notifications/services/notification-preference.service.ts index f5fbc57..afe4477 100644 --- a/src/modules/notifications/services/notification-preference.service.ts +++ b/src/modules/notifications/services/notification-preference.service.ts @@ -8,9 +8,9 @@ import { NotifTitleEnum } from '../interfaces/notification.interface'; @Injectable() export class NotificationPreferenceService { - constructor(private readonly em: EntityManager) {} + constructor(private readonly em: EntityManager) { } - async createOrUpdate(restaurantId: string, dto: CreatePreferenceDto): Promise { + async create(restaurantId: string, dto: CreatePreferenceDto): Promise { const restaurant = await this.em.findOne(Restaurant, { id: restaurantId }); if (!restaurant) { throw new NotFoundException('Restaurant not found'); diff --git a/src/modules/orders/controllers/orders.controller.ts b/src/modules/orders/controllers/orders.controller.ts index b10eb46..93515f5 100644 --- a/src/modules/orders/controllers/orders.controller.ts +++ b/src/modules/orders/controllers/orders.controller.ts @@ -102,7 +102,7 @@ export class OrdersController { } @UseGuards(AdminAuthGuard) - @Permissions(Permission.MANAGE_ORDERS) + @Permissions(Permission.VIEW_REPORTS) @ApiOperation({ summary: 'Get Stats for report page' }) @Get('admin/orders/stats') findStats(@RestId() restId: string) { @@ -110,7 +110,7 @@ export class OrdersController { } @UseGuards(AdminAuthGuard) - @Permissions(Permission.MANAGE_ORDERS) + @Permissions(Permission.VIEW_REPORTS) @ApiOperation({ summary: 'Get food sales pie chart data for last month' }) @ApiHeader(API_HEADER_SLUG) @Get('admin/orders/food-sales-pie-chart') diff --git a/src/modules/payments/controllers/payments.controller.ts b/src/modules/payments/controllers/payments.controller.ts index 5a03d47..a9d208e 100644 --- a/src/modules/payments/controllers/payments.controller.ts +++ b/src/modules/payments/controllers/payments.controller.ts @@ -132,7 +132,7 @@ export class PaymentsController { } @UseGuards(AdminAuthGuard) - @Permissions(Permission.MANAGE_PAYMENTS) + @Permissions(Permission.VIEW_REPORTS) @ApiBearerAuth() @Get('admin/payments/chart') @ApiOperation({ summary: 'Get payment chart data with date and period filters' }) diff --git a/src/seeders/data/roles.data.ts b/src/seeders/data/roles.data.ts index e83c256..312cae4 100644 --- a/src/seeders/data/roles.data.ts +++ b/src/seeders/data/roles.data.ts @@ -12,12 +12,16 @@ export const rolesData: RoleConfig[] = [ isSystem: false, permissionFilter: (name: Permission) => name === Permission.MANAGE_FOODS || - name === Permission.MANAGE_CATEGORIES || + name === Permission.MANAGE_CATEGORIES || name === Permission.MANAGE_SCHEDULES || name === Permission.MANAGE_PAGER || name === Permission.MANAGE_CONTACTS || 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: 'مدیر ( پلن ویژه)',