Skip to content

Commit

Permalink
Merge pull request #60 from VentionCapstone/booking-list
Browse files Browse the repository at this point in the history
Booking list
  • Loading branch information
mirsadikov authored Jan 23, 2024
2 parents b19e99d + d410faa commit 2781541
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/booking/booking.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,28 +192,40 @@ export class BookingService {
}
}

async getUserBookings(user: AuthUser, options: PaginationDto) {
const { page, limit } = options;
async getUserBookings(user: AuthUser, options: PaginationDto & { status?: Status }) {
const { page, limit, status } = options;
try {
const [bookings, totalCount] = await this.prismaService.$transaction([
this.prismaService.booking.findMany({
where: {
userId: user.id,
status: status,
},
include: {
accommodation: {
select: {
title: true,
thumbnailUrl: true,
previewImgUrl: true,
price: true,
},
},
},
skip: (page! - 1) * limit!,
take: limit,
}),
this.prismaService.booking.count({
where: {
userId: user.id,
status: status,
},
}),
]);

return {
bookings,
totalCount,
success: true,
data: bookings,
totalCount: totalCount,
};
} catch (error) {
if (error instanceof HttpException) throw error;
Expand Down

0 comments on commit 2781541

Please sign in to comment.