Loading backend/src/place/entities/place.entity.ts +3 −0 Original line number Diff line number Diff line Loading @@ -64,4 +64,7 @@ export class Place { @Column({ nullable: false }) closeAt: number; @Column({ nullable: false, default: true }) active: boolean; } backend/src/place/place.controller.ts +15 −0 Original line number Diff line number Diff line Loading @@ -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'; Loading Loading @@ -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; } } } backend/src/place/place.service.ts +9 −0 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading @@ -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 Loading Loading @@ -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({ Loading @@ -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); } } web/src/core/utils/Messages.ts +6 −9 Original line number Diff line number Diff line Loading @@ -11,14 +11,11 @@ export const showErrorAxios = (error: AxiosError) => { // Determine the error message based on the error code switch (error.code) { case(axios.AxiosError.ERR_BAD_REQUEST): message = "Acceso no autorizado"; // Unauthorized access break; case(axios.AxiosError.ERR_NETWORK): case axios.AxiosError.ERR_NETWORK: message = "Conexión con el servidor fallida"; // Server connection failed break; default: message = error.message; // Default to the error message provided by Axios message = (error.response?.data as any).message || "Error de servidor"; // Default to the error message provided by Axios break; } Loading @@ -31,6 +28,6 @@ export const showErrorAxios = (error: AxiosError) => { pauseOnHover: false, // Do not pause the toast on hover draggable: true, // Allow the toast to be draggable progress: undefined, // Use the default progress bar behavior theme: "colored" // Use the colored theme for the toast theme: "colored", // Use the colored theme for the toast }); } No newline at end of file }; web/src/data/datasource/api/place_datasource.ts +1 −1 Original line number Diff line number Diff line Loading @@ -132,6 +132,6 @@ export class PlaceDatasourceProd implements PlaceDatasourceInf { * @returns A promise that resolves when the place is deleted. */ async deletePlace(idPlace: number): Promise<void> { //await axios.patch(APIUrl + `/place/${idPlace}`) await axios.delete(APIUrl + `/place/${idPlace}`) } } Loading
backend/src/place/entities/place.entity.ts +3 −0 Original line number Diff line number Diff line Loading @@ -64,4 +64,7 @@ export class Place { @Column({ nullable: false }) closeAt: number; @Column({ nullable: false, default: true }) active: boolean; }
backend/src/place/place.controller.ts +15 −0 Original line number Diff line number Diff line Loading @@ -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'; Loading Loading @@ -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; } } }
backend/src/place/place.service.ts +9 −0 Original line number Diff line number Diff line Loading @@ -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 { Loading Loading @@ -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 Loading Loading @@ -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({ Loading @@ -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); } }
web/src/core/utils/Messages.ts +6 −9 Original line number Diff line number Diff line Loading @@ -11,14 +11,11 @@ export const showErrorAxios = (error: AxiosError) => { // Determine the error message based on the error code switch (error.code) { case(axios.AxiosError.ERR_BAD_REQUEST): message = "Acceso no autorizado"; // Unauthorized access break; case(axios.AxiosError.ERR_NETWORK): case axios.AxiosError.ERR_NETWORK: message = "Conexión con el servidor fallida"; // Server connection failed break; default: message = error.message; // Default to the error message provided by Axios message = (error.response?.data as any).message || "Error de servidor"; // Default to the error message provided by Axios break; } Loading @@ -31,6 +28,6 @@ export const showErrorAxios = (error: AxiosError) => { pauseOnHover: false, // Do not pause the toast on hover draggable: true, // Allow the toast to be draggable progress: undefined, // Use the default progress bar behavior theme: "colored" // Use the colored theme for the toast theme: "colored", // Use the colored theme for the toast }); } No newline at end of file };
web/src/data/datasource/api/place_datasource.ts +1 −1 Original line number Diff line number Diff line Loading @@ -132,6 +132,6 @@ export class PlaceDatasourceProd implements PlaceDatasourceInf { * @returns A promise that resolves when the place is deleted. */ async deletePlace(idPlace: number): Promise<void> { //await axios.patch(APIUrl + `/place/${idPlace}`) await axios.delete(APIUrl + `/place/${idPlace}`) } }