This commit is contained in:
2025-12-10 09:58:18 +03:30
parent 2e12cdb529
commit 525362dce1
2 changed files with 17 additions and 2 deletions
+3
View File
@@ -24,6 +24,7 @@ export class PagerController {
@ApiBody({ type: CreatePagerDto })
async create(
@Body() createPagerDto: CreatePagerDto,
@Req() request: FastifyRequest,
@Res() reply: FastifyReply,
@RestSlug() slug: string,
@RestId() restId?: string,
@@ -32,10 +33,12 @@ export class PagerController {
// Convert empty strings to undefined for cleaner validation
const normalizedRestId = restId || undefined;
const normalizedUserId = userId || undefined;
const userCookieId = request.cookies['pagerId'] || undefined;
const pager = await this.pagerService.create(createPagerDto, {
restId: normalizedRestId,
userId: normalizedUserId,
userCookieId,
slug,
});
reply.setCookie('pagerId', pager.cookieId, {
+14 -2
View File
@@ -17,8 +17,11 @@ export class PagerService {
private readonly pagerGateway: PagerGateway,
) {}
async create(createPagerDto: CreatePagerDto, params: { restId?: string; userId?: string; slug: string }) {
const { restId, userId, slug } = params;
async create(
createPagerDto: CreatePagerDto,
params: { restId?: string; userId?: string; slug: string; userCookieId?: string },
) {
const { restId, userId, slug, userCookieId } = params;
let restaurant: Restaurant | null = null;
let user: User | null = null;
if (!restId && !userId && !slug) {
@@ -42,6 +45,15 @@ export class PagerService {
throw new NotFoundException('Restaurant not found');
}
}
const cookieId = userCookieId || ulid().toString();
const existingPager = await this.em.findOne(Pager, {
restaurant: { id: restaurant!.id },
status: PagerStatus.Pending,
cookieId,
});
if (existingPager) {
throw new BadRequestException('Pager already exists');
}
const pager = this.em.create(Pager, {
...createPagerDto,