From 7c185c8decb7e7531955b04b2a0ba8ca6f9631da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Thu, 14 Nov 2024 20:56:33 -0600 Subject: [PATCH] delete place --- backend/src/place/entities/place.entity.ts | 3 +++ backend/src/place/place.controller.ts | 15 +++++++++++++++ backend/src/place/place.service.ts | 9 +++++++++ 3 files changed, 27 insertions(+) diff --git a/backend/src/place/entities/place.entity.ts b/backend/src/place/entities/place.entity.ts index ea48f3f0..6f5a3d38 100644 --- a/backend/src/place/entities/place.entity.ts +++ b/backend/src/place/entities/place.entity.ts @@ -64,4 +64,7 @@ export class Place { @Column({ nullable: false }) closeAt: number; + + @Column({ nullable: false, default: true }) + active: boolean; } diff --git a/backend/src/place/place.controller.ts b/backend/src/place/place.controller.ts index 4af70479..77b24221 100644 --- a/backend/src/place/place.controller.ts +++ b/backend/src/place/place.controller.ts @@ -11,6 +11,7 @@ import { Req, Patch, UseGuards, + Delete, } from '@nestjs/common'; import { PlaceService } from './place.service'; import { CreatePlaceDateTradDto } from './dto/create-place-date.dto'; @@ -107,4 +108,18 @@ export class PlaceController { async findOpenPlaces(@Param('idTown') idTown: number, @Param('lang') lang: string, @Req() req: CustomUserRequest) { return await this.placeService.findPlacesNotVisitedByUserAndOpenResponse(req.user.email, lang as LANGUAGES, idTown); } + + @Delete(':idPlace') + @UseGuards(AuthAdminGuard) + @Roles([ALL_ROLES.ADMIN]) + @ApiBearerAuth('jwt') + @ApiParam({ name: 'idPlace', type: Number }) + async remove(@Param('idPlace') idPlace: number) { + try { + await this.placeService.remove(idPlace); + return { message: 'Place removed successfully' }; + } catch (e) { + throw e; + } + } } diff --git a/backend/src/place/place.service.ts b/backend/src/place/place.service.ts index a480ddd3..0880244f 100644 --- a/backend/src/place/place.service.ts +++ b/backend/src/place/place.service.ts @@ -96,6 +96,7 @@ export class PlaceService { .where('place.idTown = :idTown', { idTown: idTown }) .andWhere('placeTrad.language = :language', { language: lang }) .andWhere('category.language = :language', { language: lang }) + .andWhere('place.active = :active', { active: true }) .getMany(); const places: GetPlaceDto[] = res.map((place): GetPlaceDto => { return { @@ -226,6 +227,7 @@ export class PlaceService { .createQueryBuilder('visited') .leftJoinAndSelect('visited.place', 'place') .where('visited.user = :email', { email }) + .andWhere('place.active = :active', { active: true }) .getMany(); const visitedIds: number[] = visited.map((visit) => visit.place.idPlace); // podemos hacerlo en la query @@ -261,6 +263,7 @@ export class PlaceService { .leftJoinAndSelect('visited.place', 'place') .where('visited.user = :email', { email }) .andWhere('place.idPlace = :idPlace', { idPlace: place.idPlace }) + .andWhere('place.active = :active', { active: true }) .getOne(); placesResponse.push({ @@ -270,4 +273,10 @@ export class PlaceService { } return placesResponse; } + + async remove(id: number) { + const place = await this.placeRepository.findOneByOrFail({ idPlace: id }); + place.active = false; + await this.placeRepository.save(place); + } } -- GitLab