Merge branch 'production'

This commit is contained in:
2026-01-05 11:28:41 +03:30
8 changed files with 52 additions and 13 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 { 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')
@@ -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<NotificationPreference> {
async create(restaurantId: string, dto: CreatePreferenceDto): Promise<NotificationPreference> {
const restaurant = await this.em.findOne(Restaurant, { id: restaurantId });
if (!restaurant) {
throw new NotFoundException('Restaurant not found');
@@ -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')
@@ -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' })
@@ -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' })
@@ -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;
+1 -1
View File
@@ -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,
+6 -2
View File
@@ -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: 'مدیر ( پلن ویژه)',