mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 10:45:44 +00:00
fix: ( my booking ) add get passenger id from the iamuserid
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { Body, Controller, Delete, Get, Param, Post, Patch, UseGuards, Query, Req, BadRequestException } from '@nestjs/common';
|
import { Body, Controller, Delete, Get, Param, Post, Patch, UseGuards, Query, Req, BadRequestException, UnauthorizedException } from '@nestjs/common';
|
||||||
import { ApiTags, ApiOperation, ApiBearerAuth, ApiResponse, ApiQuery, ApiBody } from '@nestjs/swagger';
|
import { ApiTags, ApiOperation, ApiBearerAuth, ApiResponse, ApiQuery, ApiBody } from '@nestjs/swagger';
|
||||||
import { IsPublic } from '@tria-plc/api-common/modules/auth/decorators/public.decorator';
|
import { IsPublic } from '@tria-plc/api-common/modules/auth/decorators/public.decorator';
|
||||||
import { Throttle } from '@nestjs/throttler';
|
import { Throttle } from '@nestjs/throttler';
|
||||||
@@ -36,13 +36,13 @@ export class BookingsController {
|
|||||||
@Query('page') page?: string,
|
@Query('page') page?: string,
|
||||||
@Query('pageSize') pageSize?: string,
|
@Query('pageSize') pageSize?: string,
|
||||||
) {
|
) {
|
||||||
const passengerId = req.user?.passengerId;
|
const iamUserId = req.user?.id;
|
||||||
if (!passengerId) throw new Error('Passenger ID not found in token');
|
if (!iamUserId) throw new UnauthorizedException();
|
||||||
return this.service.findByPassengerId(passengerId, {
|
return this.service.findByIamUserId(iamUserId, {
|
||||||
search,
|
search,
|
||||||
status,
|
status,
|
||||||
page: page ? parseInt(page) : 1,
|
page: page ? parseInt(page) : 1,
|
||||||
pageSize: pageSize ? parseInt(pageSize) : 20
|
pageSize: pageSize ? parseInt(pageSize) : 20
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,11 @@ export class BookingsService {
|
|||||||
private readonly fareEngine: FareEngineService,
|
private readonly fareEngine: FareEngineService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
|
async findByIamUserId(iamUserId: string, filters: BookingFilters = {}) {
|
||||||
|
const passenger = await this.prisma.passenger.findUniqueOrThrow({ where: { iamUserId }, select: { id: true } });
|
||||||
|
return this.findByPassengerId(passenger.id, filters);
|
||||||
|
}
|
||||||
|
|
||||||
async findByPassengerId(passengerId: string, filters: BookingFilters = {}) {
|
async findByPassengerId(passengerId: string, filters: BookingFilters = {}) {
|
||||||
const { search, status, page = 1, pageSize = 20 } = filters;
|
const { search, status, page = 1, pageSize = 20 } = filters;
|
||||||
const skip = (page - 1) * pageSize;
|
const skip = (page - 1) * pageSize;
|
||||||
|
|||||||
Reference in New Issue
Block a user