From b1d80bb0e42d50de8dd61a111bb20000b2e5f327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Tue, 11 Jun 2024 17:55:09 -0600 Subject: [PATCH 1/6] eliminando metodos sin uso en controladores --- backend/src/admin/admin.controller.ts | 8 +------- backend/src/user/user.controller.ts | 12 +----------- 2 files changed, 2 insertions(+), 18 deletions(-) diff --git a/backend/src/admin/admin.controller.ts b/backend/src/admin/admin.controller.ts index fd2874a8..70a9d117 100644 --- a/backend/src/admin/admin.controller.ts +++ b/backend/src/admin/admin.controller.ts @@ -1,13 +1,7 @@ -import { Controller, Post, Body } from '@nestjs/common'; +import { Controller } from '@nestjs/common'; import { AdminService } from './admin.service'; -import { CreateAdminDto } from './dto/create-admin.dto'; @Controller('admin') export class AdminController { constructor(private readonly adminService: AdminService) {} - - @Post() - create(@Body() createAdminDto: CreateAdminDto) { - return this.adminService.create(createAdminDto); - } } diff --git a/backend/src/user/user.controller.ts b/backend/src/user/user.controller.ts index ac921025..b95b2314 100644 --- a/backend/src/user/user.controller.ts +++ b/backend/src/user/user.controller.ts @@ -1,17 +1,7 @@ -import { Controller, Post, Body } from '@nestjs/common'; +import { Controller } from '@nestjs/common'; import { UserService } from './user.service'; -import { CreateUserDto } from './dto/create-user.dto'; @Controller('user') export class UserController { constructor(private readonly userService: UserService) {} - - @Post() - create(@Body() createUserDto: CreateUserDto) { - try { - return this.userService.create(createUserDto); - } catch (error) { - return error; - } - } } -- GitLab From f3c2220c76a4171a4c79ffeb3313c3aba9d3d445 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Tue, 11 Jun 2024 18:07:35 -0600 Subject: [PATCH 2/6] creando dto para la req al crear un town --- backend/src/town/dto/createTownReq.dto.ts | 24 +++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 backend/src/town/dto/createTownReq.dto.ts diff --git a/backend/src/town/dto/createTownReq.dto.ts b/backend/src/town/dto/createTownReq.dto.ts new file mode 100644 index 00000000..9ee2cec1 --- /dev/null +++ b/backend/src/town/dto/createTownReq.dto.ts @@ -0,0 +1,24 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { Binary } from 'typeorm'; + +export class CreateTownReqDto { + @ApiProperty() + name: string; + + @ApiProperty({ + type: String, + description: 'Language content for Spanish (es)', + }) + descriptionES: string; + + @ApiProperty({ + type: String, + description: 'Language content for English (en)', + }) + descriptionEN: string; + + @ApiProperty({ type: 'string', format: 'binary' }) + image: Binary; + @ApiProperty() + state: number; +} -- GitLab From 2ba4adb5277485e150dd367f2c2ce87638602a80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Tue, 11 Jun 2024 18:07:55 -0600 Subject: [PATCH 3/6] actualizando docs para crear un town --- backend/src/town/dto/create-town.dto.ts | 14 -------------- backend/src/town/town.controller.ts | 14 +++++++++++--- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/backend/src/town/dto/create-town.dto.ts b/backend/src/town/dto/create-town.dto.ts index d4a20eec..461128ac 100644 --- a/backend/src/town/dto/create-town.dto.ts +++ b/backend/src/town/dto/create-town.dto.ts @@ -1,21 +1,7 @@ -import { ApiProperty } from '@nestjs/swagger'; - export class CreateTownDto { - @ApiProperty() name: string; - - @ApiProperty({ - type: String, - description: 'Language content for Spanish (es)', - }) descriptionES: string; - - @ApiProperty({ - type: String, - description: 'Language content for English (en)', - }) descriptionEN: string; imageName: string = 'default.jpg'; - @ApiProperty() state: number; } diff --git a/backend/src/town/town.controller.ts b/backend/src/town/town.controller.ts index f0028d14..a8c5119d 100644 --- a/backend/src/town/town.controller.ts +++ b/backend/src/town/town.controller.ts @@ -6,6 +6,7 @@ import { fileInterceptor } from 'src/shared/interceptors/file-save.interceptor'; import { CreateTownDto } from './dto/create-town.dto'; import { Roles } from 'src/auth/role.decorator'; import { SUPERADMIN_ROLES } from 'src/shared/enum/admin-role.enum'; +import { CreateTownReqDto } from './dto/createTownReq.dto'; @Controller() @ApiTags('Pueblos') export class TownController { @@ -13,19 +14,26 @@ export class TownController { @Roles(SUPERADMIN_ROLES) @ApiBearerAuth('jwt') - @ApiBody({ type: CreateTownDto }) + @ApiBody({ type: CreateTownReqDto }) @ApiConsumes('multipart/form-data') @Post('town') @UseInterceptors(fileInterceptor('image', 'static/towns/', ['.jpg', '.jpeg', '.png'])) - async create(@UploadedFile(new FileValidationPipe()) file, @Body() createTownDto: CreateTownDto) { + async create(@UploadedFile(new FileValidationPipe()) file, @Body() createTownReqDto: CreateTownReqDto) { try { - createTownDto.imageName = file.filename; + const createTownDto: CreateTownDto = { + name: createTownReqDto.name, + imageName: file.filename, + descriptionEN: createTownReqDto.descriptionEN, + descriptionES: createTownReqDto.descriptionES, + state: createTownReqDto.state, + }; await this.townService.create(createTownDto); return { message: 'Town created successfully' }; } catch (error) { throw error; } } + @ApiParam({ name: 'stateId', type: Number }) @ApiQuery({ name: 'lang', type: String }) @Get('state/:stateId/town') -- GitLab From 2a22adbbce103ad96b2844dde8623d37df76c1b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Thu, 13 Jun 2024 09:21:09 -0600 Subject: [PATCH 4/6] corrigiendo dtos para Town --- backend/src/town/dto/create-town-trad.dto.ts | 1 - backend/src/town/dto/update-town.dto.ts | 9 +++++---- backend/src/town/entities/town.entity.ts | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/backend/src/town/dto/create-town-trad.dto.ts b/backend/src/town/dto/create-town-trad.dto.ts index eb9058fc..deffbdef 100644 --- a/backend/src/town/dto/create-town-trad.dto.ts +++ b/backend/src/town/dto/create-town-trad.dto.ts @@ -3,6 +3,5 @@ import { LANGUAGES } from 'src/shared/enum/languages.enum'; export class CreateTownTraductionDto { townId: number; language: LANGUAGES; - name: string; description: string; } diff --git a/backend/src/town/dto/update-town.dto.ts b/backend/src/town/dto/update-town.dto.ts index 6982b689..5bd16630 100644 --- a/backend/src/town/dto/update-town.dto.ts +++ b/backend/src/town/dto/update-town.dto.ts @@ -1,4 +1,5 @@ -import { PartialType } from '@nestjs/swagger'; -import { CreateTownDto } from './create-town.dto'; - -export class UpdateTownDto extends PartialType(CreateTownDto) {} +export class UpdateTownDto { + name: string; + imageName: string; + state: number; +} diff --git a/backend/src/town/entities/town.entity.ts b/backend/src/town/entities/town.entity.ts index 9e9689ae..bfe8a378 100644 --- a/backend/src/town/entities/town.entity.ts +++ b/backend/src/town/entities/town.entity.ts @@ -7,7 +7,7 @@ export class Town { townId: number; @ManyToOne(() => State, (state) => state.stateId, { nullable: false }) - state: number; + state: State; @OneToMany(() => Place, (place) => place.idTown) places: Place[]; -- GitLab From 33b51e79b2b00d7ff1e6a14d58a807c9f484d6da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Thu, 13 Jun 2024 09:21:19 -0600 Subject: [PATCH 5/6] agregando update Town endpoint --- backend/src/town/town.controller.ts | 28 ++++++++++++++++++++++++++- backend/src/town/town.service.ts | 30 ++++++++++++++++++++++++++--- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/backend/src/town/town.controller.ts b/backend/src/town/town.controller.ts index a8c5119d..4e986796 100644 --- a/backend/src/town/town.controller.ts +++ b/backend/src/town/town.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get, Post, Param, UseInterceptors, UploadedFile, Body, Query } from '@nestjs/common'; +import { Controller, Get, Post, Param, UseInterceptors, UploadedFile, Body, Query, Patch } from '@nestjs/common'; import { TownService } from './town.service'; import { ApiBearerAuth, ApiBody, ApiConsumes, ApiParam, ApiQuery, ApiTags } from '@nestjs/swagger'; import { FileValidationPipe } from 'src/shared/pipe/file-validation.pipe'; @@ -45,4 +45,30 @@ export class TownController { throw error; } } + + @Roles(SUPERADMIN_ROLES) + @ApiBearerAuth('jwt') + @ApiBody({ type: CreateTownReqDto }) + @ApiConsumes('multipart/form-data') + @Patch('town/:idTown') + @UseInterceptors(fileInterceptor('image', 'static/towns/', ['.jpg', '.jpeg', '.png'])) + async update( + @Param('idTown') idTown: number, + @UploadedFile(new FileValidationPipe()) file, + @Body() createTownReqDto: CreateTownReqDto, + ) { + try { + const updateTownDto: CreateTownDto = { + name: createTownReqDto.name, + imageName: file.filename, + descriptionEN: createTownReqDto.descriptionEN, + descriptionES: createTownReqDto.descriptionES, + state: createTownReqDto.state, + }; + await this.townService.update(idTown, updateTownDto); + return { message: 'Town created successfully' }; + } catch (error) { + throw error; + } + } } diff --git a/backend/src/town/town.service.ts b/backend/src/town/town.service.ts index c4d5ef95..59fc928b 100644 --- a/backend/src/town/town.service.ts +++ b/backend/src/town/town.service.ts @@ -10,6 +10,7 @@ import { LANGUAGES } from 'src/shared/enum/languages.enum'; import { DataSource } from 'typeorm'; import { ServerConstants } from 'src/constants/server.contants'; import { TownResDto } from './dto/town-res.dto'; +import { UpdateTownDto } from './dto/update-town.dto'; @Injectable() export class TownService { @@ -24,18 +25,16 @@ export class TownService { async create(createTownDto: CreateTownDto) { const state = await this.state.findOne(createTownDto.state); if (!state) throw new BadRequestException('State does not exist'); - const town = await this.townRepository.save(createTownDto); + const town = await this.townRepository.save({ ...createTownDto, state }); const createTownTradDtoEN: CreateTownTraductionDto = { townId: town.townId, language: LANGUAGES.EN, - name: createTownDto.name, description: createTownDto.descriptionEN, }; const createTownTradDtoES: CreateTownTraductionDto = { townId: town.townId, language: LANGUAGES.ES, - name: createTownDto.name, description: createTownDto.descriptionES, }; @@ -69,4 +68,29 @@ export class TownService { stateId: item.stateId, })); } + + async update(townId: number, updateTownDto: CreateTownDto) { + const state = await this.state.findOne(updateTownDto.state); + if (!state) throw new BadRequestException('State does not exist'); + const updateTown: UpdateTownDto = { + name: updateTownDto.name, + imageName: updateTownDto.imageName, + state: state.stateId, + }; + await this.townRepository.update({ townId }, { ...updateTown, state: state }); + const createTownTradDtoEN: CreateTownTraductionDto = { + townId: townId, + language: LANGUAGES.EN, + description: updateTownDto.descriptionEN, + }; + + const createTownTradDtoES: CreateTownTraductionDto = { + townId: townId, + language: LANGUAGES.ES, + description: updateTownDto.descriptionES, + }; + + await this.townTradRepository.update({ townId, language: LANGUAGES.ES }, createTownTradDtoES); + await this.townTradRepository.update({ townId, language: LANGUAGES.EN }, createTownTradDtoEN); + } } -- GitLab From 69250a458d0f096af169ffe86950a3d9f118c46b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Thu, 13 Jun 2024 13:12:10 -0600 Subject: [PATCH 6/6] cambiando campo coords por dos campos latitude y longitude --- backend/src/place/dto/create-place-date.dto.ts | 8 ++++++-- backend/src/place/dto/create-place.dto.ts | 14 ++------------ backend/src/place/dto/get-place.dto.ts | 3 ++- backend/src/place/entities/place.entity.ts | 5 ++++- backend/src/place/place.service.ts | 15 ++++++++++----- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/backend/src/place/dto/create-place-date.dto.ts b/backend/src/place/dto/create-place-date.dto.ts index 5eb49233..7e3adcc5 100644 --- a/backend/src/place/dto/create-place-date.dto.ts +++ b/backend/src/place/dto/create-place-date.dto.ts @@ -19,8 +19,12 @@ export class CreatePlaceDateTradDto { @ApiProperty({ type: 'string', format: 'binary' }) image; - @ApiProperty({ example: '12.3456789-12.3456789' }) - coords: string; + @ApiProperty() + latitude: number; + + @ApiProperty() + longitude: number; + // 24-hour format @ApiProperty({ maximum: 24, minimum: 0 }) openAt: number; diff --git a/backend/src/place/dto/create-place.dto.ts b/backend/src/place/dto/create-place.dto.ts index cfb2aa2b..b37e0f41 100644 --- a/backend/src/place/dto/create-place.dto.ts +++ b/backend/src/place/dto/create-place.dto.ts @@ -1,23 +1,13 @@ -import { ApiProperty } from '@nestjs/swagger'; import { Available } from 'src/pointOfInterest/enum/available.enum'; import { Town } from 'src/town/entities/town.entity'; export class CreatePlaceDto { - @ApiProperty({ enum: Available, enumName: 'Available' }) available: Available; - @ApiProperty() name: string; - @ApiProperty() imageName: string; - - @ApiProperty({ type: 'number' }) idTown: Town; - @ApiProperty({ example: '12.3456789-12.3456789' }) - coords: string; - // 24-hour format - @ApiProperty({ maximum: 24, minimum: 0 }) + latitude: number; + longitude: number; openAt: number; - // 24-hour format - @ApiProperty({ maximum: 24, minimum: 0 }) closeAt: number; } diff --git a/backend/src/place/dto/get-place.dto.ts b/backend/src/place/dto/get-place.dto.ts index ece429a3..4625b1c5 100644 --- a/backend/src/place/dto/get-place.dto.ts +++ b/backend/src/place/dto/get-place.dto.ts @@ -8,7 +8,8 @@ export class GetPlaceDto { name: string; description: string; imageName: string; - coords: string; + latitude: number; + longitude: number; openAt: number; closeAt: number; startDate: Date; diff --git a/backend/src/place/entities/place.entity.ts b/backend/src/place/entities/place.entity.ts index 2c2a9b1e..35869609 100644 --- a/backend/src/place/entities/place.entity.ts +++ b/backend/src/place/entities/place.entity.ts @@ -29,7 +29,10 @@ export class Place { imageName: string; @Column({ nullable: false }) - coords: string; + latitude: number; + + @Column({ nullable: false }) + longitude: number; @Column({ nullable: false }) openAt: number; diff --git a/backend/src/place/place.service.ts b/backend/src/place/place.service.ts index 443bfbc3..86ba9854 100644 --- a/backend/src/place/place.service.ts +++ b/backend/src/place/place.service.ts @@ -28,7 +28,8 @@ export class PlaceService { const createPlace: CreatePlaceDto = { available: createPlaceDto.available, closeAt: createPlaceDto.closeAt, - coords: createPlaceDto.coords, + latitude: createPlaceDto.latitude, + longitude: createPlaceDto.longitude, idTown: town, name: createPlaceDto.name, openAt: createPlaceDto.openAt, @@ -76,13 +77,14 @@ export class PlaceService { 'place.imageName AS imageName', 'placeTrad.language AS language', 'placeTrad.description AS description', - 'place.coords AS coords', 'place.openAt AS openAt', 'place.closeAt AS closeAt', 'availableDate.startDate AS startDate', 'availableDate.endDate AS endDate', 'place.available AS available', 'place.idTown AS idTown', + 'place.latitude AS latitude', + 'place.longitude AS longitude', ]) .where('place.idTown = :idTown', { idTown: idTown }) .andWhere('placeTrad.language = :language', { language: lang }) @@ -93,7 +95,8 @@ export class PlaceService { idPlace: place.idPlace, available: place.available, description: place.description, - coords: place.coords, + latitude: place.latitude, + longitude: place.longitude, imageName: `${ServerConstants.HOST}/places/${place.imageName}`, name: place.name, openAt: place.openAt, @@ -121,7 +124,8 @@ export class PlaceService { 'place.imageName AS imageName', 'placeTrad.language AS language', 'placeTrad.description AS description', - 'place.coords AS coords', + 'place.latitude AS latitude', + 'place.longitude AS longitude', 'place.openAt AS openAt', 'place.closeAt AS closeAt', 'availableDate.startDate AS startDate', @@ -137,7 +141,8 @@ export class PlaceService { idPlace: place.idPlace, available: place.available, description: place.description, - coords: place.coords, + latitude: place.latitude, + longitude: place.longitude, imageName: `${ServerConstants.HOST}/places/${place.imageName}`, name: place.name, openAt: place.openAt, -- GitLab