bug
This commit is contained in:
@@ -24,6 +24,7 @@ export class PagerController {
|
|||||||
@ApiBody({ type: CreatePagerDto })
|
@ApiBody({ type: CreatePagerDto })
|
||||||
async create(
|
async create(
|
||||||
@Body() createPagerDto: CreatePagerDto,
|
@Body() createPagerDto: CreatePagerDto,
|
||||||
|
@Req() request: FastifyRequest,
|
||||||
@Res() reply: FastifyReply,
|
@Res() reply: FastifyReply,
|
||||||
@RestSlug() slug: string,
|
@RestSlug() slug: string,
|
||||||
@RestId() restId?: string,
|
@RestId() restId?: string,
|
||||||
@@ -32,10 +33,12 @@ export class PagerController {
|
|||||||
// Convert empty strings to undefined for cleaner validation
|
// Convert empty strings to undefined for cleaner validation
|
||||||
const normalizedRestId = restId || undefined;
|
const normalizedRestId = restId || undefined;
|
||||||
const normalizedUserId = userId || undefined;
|
const normalizedUserId = userId || undefined;
|
||||||
|
const userCookieId = request.cookies['pagerId'] || undefined;
|
||||||
|
|
||||||
const pager = await this.pagerService.create(createPagerDto, {
|
const pager = await this.pagerService.create(createPagerDto, {
|
||||||
restId: normalizedRestId,
|
restId: normalizedRestId,
|
||||||
userId: normalizedUserId,
|
userId: normalizedUserId,
|
||||||
|
userCookieId,
|
||||||
slug,
|
slug,
|
||||||
});
|
});
|
||||||
reply.setCookie('pagerId', pager.cookieId, {
|
reply.setCookie('pagerId', pager.cookieId, {
|
||||||
|
|||||||
@@ -17,8 +17,11 @@ export class PagerService {
|
|||||||
private readonly pagerGateway: PagerGateway,
|
private readonly pagerGateway: PagerGateway,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async create(createPagerDto: CreatePagerDto, params: { restId?: string; userId?: string; slug: string }) {
|
async create(
|
||||||
const { restId, userId, slug } = params;
|
createPagerDto: CreatePagerDto,
|
||||||
|
params: { restId?: string; userId?: string; slug: string; userCookieId?: string },
|
||||||
|
) {
|
||||||
|
const { restId, userId, slug, userCookieId } = params;
|
||||||
let restaurant: Restaurant | null = null;
|
let restaurant: Restaurant | null = null;
|
||||||
let user: User | null = null;
|
let user: User | null = null;
|
||||||
if (!restId && !userId && !slug) {
|
if (!restId && !userId && !slug) {
|
||||||
@@ -42,6 +45,15 @@ export class PagerService {
|
|||||||
throw new NotFoundException('Restaurant not found');
|
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, {
|
const pager = this.em.create(Pager, {
|
||||||
...createPagerDto,
|
...createPagerDto,
|
||||||
|
|||||||
Reference in New Issue
Block a user