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/modules/restaurants/controllers/restaurants.controller.ts b/src/modules/restaurants/controllers/restaurants.controller.ts index 360fb9f..f2c7979 100644 --- a/src/modules/restaurants/controllers/restaurants.controller.ts +++ b/src/modules/restaurants/controllers/restaurants.controller.ts @@ -90,6 +90,15 @@ export class RestaurantsController { return this.restaurantsService.findOneBySubscriptionId(subscriptionId); } + @UseGuards(SuperAdminAuthGuard) + @ApiBearerAuth() + @ApiOperation({ summary: 'Get restaurant by ID' }) + @ApiParam({ name: 'id', required: true, description: 'Restaurant ID' }) + @Get('super-admin/restaurants/:id') + findOneById(@Param('id') id: string) { + return this.restaurantsService.findOne(id); + } + @UseGuards(SuperAdminAuthGuard) @ApiBearerAuth() @ApiOperation({ summary: 'Update a restaurant by ID' }) diff --git a/src/modules/restaurants/providers/restaurants.service.ts b/src/modules/restaurants/providers/restaurants.service.ts index bd12d11..3018aef 100644 --- a/src/modules/restaurants/providers/restaurants.service.ts +++ b/src/modules/restaurants/providers/restaurants.service.ts @@ -13,6 +13,8 @@ import { Admin } from '../../admin/entities/admin.entity'; import { AdminRole } from '../../admin/entities/adminRole.entity'; import { Role } from '../../roles/entities/role.entity'; import { normalizePhone } from 'src/modules/utils/phone.util'; +import { NotificationPreference } from '../../notifications/entities/notification-preference.entity'; +import { notificationPreferencesData } from '../../../seeders/data/notification-preferences.data'; @Injectable() export class RestaurantsService { @@ -59,8 +61,8 @@ export class RestaurantsService { if (!admin) { admin = em.create(Admin, { phone: normalizedPhone, - firstName: 'نام مدیر', - lastName: 'نام خانوادگی مدیر', + firstName: '[نام]', + lastName: '[نام خانوادگی]', }); } @@ -71,8 +73,17 @@ export class RestaurantsService { restaurant, }); + // Create notification preferences for the restaurant + const notificationPreferences = notificationPreferencesData.map(preferenceData => + em.create(NotificationPreference, { + restaurant, + title: preferenceData.title, + channels: preferenceData.channels, + }) + ); + // Persist all entities - em.persist([restaurant, admin, adminRole]); + em.persist([restaurant, admin, adminRole, ...notificationPreferences]); await em.flush(); return restaurant; diff --git a/src/modules/users/providers/user.service.ts b/src/modules/users/providers/user.service.ts index 94c8a3f..bbc2972 100644 --- a/src/modules/users/providers/user.service.ts +++ b/src/modules/users/providers/user.service.ts @@ -37,7 +37,7 @@ export class UserService { // firstName is required on the entity; use phone as a sensible default const _raw = { phone: normalizedPhone, - firstName: new Date().toISOString(), + firstName: '[نام]', // keep dates undefined (no value) — cast through unknown to satisfy TS typing birthDate: undefined, marriageDate: undefined, 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: 'مدیر ( پلن ویژه)',