From 4fe4c196e8d63125152856ee2fdde1a85c9962c6 Mon Sep 17 00:00:00 2001 From: Zach13131 <125944644+Zach13131@users.noreply.github.com> Date: Thu, 25 Jan 2024 14:35:33 +0500 Subject: [PATCH] fix(update): response properties --- src/accommodation/accommodation.controller.ts | 4 ++-- src/accommodation/accommodation.service.ts | 7 ++++++- src/accommodation/dto/list-of-accommodations.dto.ts | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/accommodation/accommodation.controller.ts b/src/accommodation/accommodation.controller.ts index 737e46c..6047ee9 100644 --- a/src/accommodation/accommodation.controller.ts +++ b/src/accommodation/accommodation.controller.ts @@ -401,8 +401,8 @@ export class AccommodationController { @LangQuery() @Get('/:id') async findOne(@Param('id') id: string) { - const { accommodation, owner } = await this.accommodationService.getOneAccommodation(id); - return { success: true, data: { ...accommodation, owner } }; + const data = await this.accommodationService.getOneAccommodation(id); + return { success: true, data }; } @ApiOperation({ summary: 'get all media of single accommodation' }) diff --git a/src/accommodation/accommodation.service.ts b/src/accommodation/accommodation.service.ts index ab2e4db..932a0bc 100644 --- a/src/accommodation/accommodation.service.ts +++ b/src/accommodation/accommodation.service.ts @@ -204,7 +204,7 @@ export class AccommodationService { }, }); - return { accommodation, owner }; + return { ...accommodation, owner, amenities: accommodation.amenities[0] }; } catch (error) { throw new GlobalException(ErrorsTypes.ACCOMMODATION_FAILED_TO_GET, error.message); } @@ -364,6 +364,10 @@ export class AccommodationService { const totalPriceStatsQuery = this.prisma.accommodation.aggregate({ _min: { price: true }, _max: { price: true }, + where: { + available: true, + isDeleted: false, + }, }); const [accommodations, totalCount, curPriceStats, totalPriceStats] = await Promise.all([ @@ -501,6 +505,7 @@ export class AccommodationService { id: true, title: true, thumbnailUrl: true, + previewImgUrl: true, squareMeters: true, numberOfRooms: true, allowedNumberOfPeople: true, diff --git a/src/accommodation/dto/list-of-accommodations.dto.ts b/src/accommodation/dto/list-of-accommodations.dto.ts index b5c7ce7..33e8637 100644 --- a/src/accommodation/dto/list-of-accommodations.dto.ts +++ b/src/accommodation/dto/list-of-accommodations.dto.ts @@ -1,6 +1,7 @@ export class ListOfAccommodationsDto { id: string; thumbnailUrl: string; + previewImgUrl: string; squareMeters: number; numberOfRooms: number; allowedNumberOfPeople: number;