change entity names

This commit is contained in:
2026-02-08 09:18:20 +03:30
parent 6be6a66079
commit 9a7010dcea
180 changed files with 2751 additions and 2513 deletions
@@ -1,13 +1,13 @@
import { Controller, Get, Post, Body, UseGuards, Res, Req, Patch, Param } from '@nestjs/common';
import { PagerService } from '../providers/pager.service';
import { CreatePagerDto } from '../dto/create-pager.dto';
import { OptionalAuthGuard } from '../../auth/guards/optinalAuth.guard';
import { OptionalAuthGuard } from '../../../auth/guards/optinalAuth.guard';
import { RestId } from 'src/common/decorators/rest-id.decorator';
import { UserId } from 'src/common/decorators/user-id.decorator';
import { RestSlug } from 'src/common/decorators/rest-slug.decorator';
import { ApiTags, ApiOperation, ApiBody, ApiHeader, ApiBearerAuth, ApiParam } from '@nestjs/swagger';
import type { FastifyReply, FastifyRequest } from 'fastify';
import { AdminAuthGuard } from '../../auth/guards/adminAuth.guard';
import { AdminAuthGuard } from '../../../auth/guards/adminAuth.guard';
import { AdminId } from 'src/common/decorators/admin-id.decorator';
import { UpdatePagerStatusDto } from '../dto/update-pager.dto';
import { PagerMessage } from 'src/common/enums/message.enum';
@@ -23,7 +23,7 @@ export class PagerController {
@UseGuards(OptionalAuthGuard)
@Post('public/pager')
@ApiOperation({ summary: 'Create a new pager request' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Shop slug identifier' })
@ApiHeader({ name: 'Authorization', required: false, description: 'Bearer token (optional authentication)' })
@ApiBody({ type: CreatePagerDto })
async create(
@@ -78,7 +78,7 @@ export class PagerController {
@Permissions(Permission.MANAGE_PAGER)
@ApiBearerAuth()
@Get('admin/pager')
@ApiOperation({ summary: 'Get all pager requests for the restaurant' })
@ApiOperation({ summary: 'Get all pager requests for the shop' })
async findAllAdmin(@RestId() restId: string) {
return this.pagerService.findAllByRestaurantId(restId);
}
@@ -3,12 +3,12 @@ import { createParamDecorator } from '@nestjs/common';
import type { AuthenticatedSocket } from '../guards/ws-admin-auth.guard';
/**
* Extract restaurant ID from authenticated WebSocket client
* Extract shop ID from authenticated WebSocket client
* Use this decorator in WebSocket handlers to get the restId from the authenticated admin
*
* @example
* ```typescript
* @SubscribeMessage('join:restaurant')
* @SubscribeMessage('join:shop')
* handleJoinRestaurant(@WsRestId() restId: string) {
* // restId is automatically extracted from authenticated admin
* }
@@ -19,7 +19,7 @@ export const WsRestId = createParamDecorator((data: unknown, ctx: ExecutionConte
const restId = client.restId;
if (!restId) {
throw new Error('Restaurant ID not found. Ensure WsAdminAuthGuard is applied.');
throw new Error('Shop ID not found. Ensure WsAdminAuthGuard is applied.');
}
return restId;
@@ -54,7 +54,7 @@ export interface PagerSocketConnectionConfig {
*/
export enum PagerSocketEvents {
// Client to Server Events
JOIN_RESTAURANT = 'join:restaurant',
JOIN_RESTAURANT = 'join:shop',
LEAVE_ROOM = 'leave:room',
GET_PAGERS = 'get:pagers',
UPDATE_PAGER_STATUS = 'update:pager:status',
@@ -72,7 +72,7 @@ export enum PagerSocketEvents {
}
/**
* Payload for joining restaurant room
* Payload for joining shop room
* Note: restId is automatically extracted from JWT token, no need to send it
*/
export type JoinRestaurantPayload = Record<string, never>;
+5 -5
View File
@@ -1,7 +1,7 @@
import { Entity, ManyToOne, Property, Enum } from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { User } from '../../users/entities/user.entity';
import { Restaurant } from '../../restaurants/entities/restaurant.entity';
import { BaseEntity } from '../../../../common/entities/base.entity';
import { User } from '../../../users/entities/user.entity';
import { Shop } from ../../..shops/entities/shop.entity';
import { PagerStatus } from '../interface/pager';
import { Admin } from 'src/modules/admin/entities/admin.entity';
@@ -10,8 +10,8 @@ export class Pager extends BaseEntity {
@Property({ type: 'string' })
cookieId!: string;
@ManyToOne(() => Restaurant)
restaurant!: Restaurant;
@ManyToOne(() => Shop)
shop!: Shop;
@Property({ type: 'string' })
tableNumber!: string;
@@ -3,7 +3,7 @@ import { WsException } from '@nestjs/websockets';
import { Socket } from 'socket.io';
import { JwtService } from '@nestjs/jwt';
import { ConfigService } from '@nestjs/config';
import { IAdminTokenPayload } from '../../auth/interfaces/IToken-payload';
import { IAdminTokenPayload } from '../../../auth/interfaces/IToken-payload';
export interface AuthenticatedSocket extends Socket {
adminId?: string;
@@ -45,7 +45,7 @@ export class PagerListeners {
icon: `/assets/images/logo.png`,
action: {
type: NotifTitleEnum.PAGER_CREATED,
url: `/restaurants/${event.restaurantId}/pagers`,
url: `/shops/${event.restaurantId}/pagers`,
},
},
},
+19 -19
View File
@@ -1,12 +1,12 @@
import { BadRequestException, Injectable, NotFoundException, Inject, forwardRef } from '@nestjs/common';
import { CreatePagerDto } from '../dto/create-pager.dto';
import { User } from '../../users/entities/user.entity';
import { User } from '../../../users/entities/user.entity';
import { EntityManager } from '@mikro-orm/postgresql';
import { Restaurant } from '../../restaurants/entities/restaurant.entity';
import { Shop } from ../../..shops/entities/shop.entity';
import { Pager } from '../entities/pager.entity';
import { PagerStatus } from '../interface/pager';
import { ulid } from 'ulid';
import { Admin } from '../../admin/entities/admin.entity';
import { Admin } from '../../../admin/entities/admin.entity';
import { PagerCreatedEvent } from '../events/pager.events';
import { EventEmitter2 } from '@nestjs/event-emitter';
@@ -24,15 +24,15 @@ export class PagerService {
params: { restId?: string; userId?: string; slug: string; userCookieId?: string },
) {
const { restId, userId, slug, userCookieId } = params;
let restaurant: Restaurant | null = null;
let shop: Shop | null = null;
let user: User | null = null;
if (!restId && !userId && !slug) {
throw new BadRequestException('Invalid parameters');
}
if (restId) {
restaurant = await this.em.findOne(Restaurant, { id: restId });
if (!restaurant) {
throw new NotFoundException('Restaurant not found');
shop = await this.em.findOne(Shop, { id: restId });
if (!shop) {
throw new NotFoundException('Shop not found');
}
}
if (userId) {
@@ -41,15 +41,15 @@ export class PagerService {
throw new NotFoundException('User not found');
}
}
if (!restaurant && slug) {
restaurant = await this.em.findOne(Restaurant, { slug });
if (!restaurant) {
throw new NotFoundException('Restaurant not found');
if (!shop && slug) {
shop = await this.em.findOne(Shop, { slug });
if (!shop) {
throw new NotFoundException('Shop not found');
}
}
const cookieId = userCookieId || ulid().toString();
// const existingPager = await this.em.findOne(Pager, {
// restaurant: { id: restaurant!.id },
// shop: { id: shop!.id },
// status: PagerStatus.Pending,
// cookieId,
// });
@@ -59,7 +59,7 @@ export class PagerService {
const pager = this.em.create(Pager, {
...createPagerDto,
restaurant: restaurant!,
shop: shop!,
user,
cookieId: ulid().toString(),
status: PagerStatus.Pending,
@@ -68,9 +68,9 @@ export class PagerService {
await this.em.persistAndFlush(pager);
// Populate relations before emitting
await this.em.populate(pager, ['restaurant']);
await this.em.populate(pager, ['shop']);
// Emit socket event for new pager
this.eventEmitter.emit(PagerCreatedEvent.name, new PagerCreatedEvent(pager.restaurant.id, pager.tableNumber));
this.eventEmitter.emit(PagerCreatedEvent.name, new PagerCreatedEvent(pager.shop.id, pager.tableNumber));
return pager;
}
@@ -81,15 +81,15 @@ export class PagerService {
}
async findAllByRestaurantId(restId: string) {
const pagers = await this.em.find(Pager, { restaurant: { id: restId } }, { populate: ['user'] });
const pagers = await this.em.find(Pager, { shop: { id: restId } }, { populate: ['user'] });
return pagers;
}
async updateStatus(pagerId: string, restId: string, staffId: string, status: PagerStatus) {
const pager = await this.em.findOne(
Pager,
{ id: pagerId, restaurant: { id: restId } },
{ populate: ['restaurant'] },
{ id: pagerId, shop: { id: restId } },
{ populate: ['shop'] },
);
if (!pager) {
throw new NotFoundException('Pager not found *');
@@ -105,7 +105,7 @@ export class PagerService {
await this.em.persistAndFlush(pager);
// Populate relations before emitting
await this.em.populate(pager, ['restaurant', 'staff', 'user']);
await this.em.populate(pager, ['shop', 'staff', 'user']);
// Emit socket event for status update
// this.pagerGateway.emitPagerStatusUpdated(pager);