Skip to content

Commit

Permalink
feat(full view accommodation): refactor media
Browse files Browse the repository at this point in the history
  • Loading branch information
JamshidMirzakhmedov committed Jan 21, 2024
1 parent 0faad73 commit e4d520e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 17 deletions.
13 changes: 3 additions & 10 deletions src/accommodation/accommodation.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -401,14 +401,6 @@ export class AccommodationController {
description: 'Accommodation with provided id',
type: MediaAllDto,
})
@ApiUnauthorizedResponse({
status: 401,
description: 'Unauthorized',
})
@ApiResponse({
status: 404,
description: 'Not found',
})
@ApiResponse({
status: 500,
description: 'Internal Server Error',
Expand All @@ -421,7 +413,8 @@ export class AccommodationController {
})
@Get('/:id/media')
async getMedia(@Param('id') id: string) {
const media = await this.accommodationService.getMedia(id);
return { succes: true, data: { ...media } };
const media = await this.accommodationService.getAllMedia(id);

return { succes: true, data: media };
}
}
11 changes: 4 additions & 7 deletions src/accommodation/accommodation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,15 @@ export class AccommodationService {
}
}

async getMedia(id: string) {
async getAllMedia(id: string) {
try {
const allMedia = await this.prisma.accommodation.findUnique({
where: { id },
select: {
media: true,
},
const allMedia = await this.prisma.media.findMany({
where: { accommodationId: id },
});

return allMedia;
} catch (error) {
throw new GlobalException(ErrorsTypes.ACCOMMODATION_FAILED_TO_GET, error.message);
throw new GlobalException(ErrorsTypes.ACCOMMODATION_FAILED_TO_GET_IMAGES, error.message);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/accommodation/dto/accommodation-media.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import MediaResponseDto from 'src/media/dto/media.dto';

export class MediaAllDto {
success: boolean;
media: MediaResponseDto[];
}
1 change: 1 addition & 0 deletions src/errors/errors.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ enum ErrorsTypes {
ACCOMMODATION_FAILED_TO_DELETE = 'ACCOMMODATION_FAILED_TO_DELETE',
ACCOMMODATION_FAILED_GET_DELETING = 'ACCOMMODATION_FAILED_GET_DELETING',
ACCOMMODATION_FAILED_TO_GET = 'ACCOMMODATION_FAILED_TO_GET',
ACCOMMODATION_FAILED_TO_GET_IMAGES = 'ACCOMMODATION_FAILED_TO_GET_IMAGES',
ACCOMMODATION_FAILED_TO_GET_LIST = 'ACCOMMODATION_FAILED_TO_GET_LIST',
ACCOMMODATION_FAILED_TO_GET_RESTORING = 'ACCOMMODATION_FAILED_TO_GET_RESTORING',
ACCOMMODATION_FAILED_TO_RESTORE = 'ACCOMMODATION_FAILED_TO_RESTORE',
Expand Down

0 comments on commit e4d520e

Please sign in to comment.