diff --git a/backend/src/admin/admin.controller.ts b/backend/src/admin/admin.controller.ts index fd2874a856bb72b7474eb918dd233cb25a0202b5..70a9d11745bf87e78749ebbcca59959364a23cab 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/place/dto/create-place-date.dto.ts b/backend/src/place/dto/create-place-date.dto.ts index 5eb4923356e7a062f56c58193ba5c567ec3820eb..7e3adcc5442852ce4b40815ed5f28f24979a6124 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 cfb2aa2bee236a112d1d08afcdccd4aab45c27be..b37e0f41e9cf46cabbe82970488b7545ad36a28c 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 ece429a357ba679f045224ed808d9134aac653ac..4625b1c510463fba204f33ed5a747c4f8e961009 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 2c2a9b1e2b773a211c262eefb41fe16183f0d776..3586960997fda6ad1faa9879bf2b93126226ed7c 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 443bfbc3b0609b8a571ee43d423672e18ab03a31..86ba9854f63bcd069749676b9a38cd0fe82adde8 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, diff --git a/backend/src/town/dto/create-town-trad.dto.ts b/backend/src/town/dto/create-town-trad.dto.ts index eb9058fc6be2d18ea8f3199c3bc7a6ca894f4b37..deffbdef845d45f2fa5c15ed409481e281591153 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/create-town.dto.ts b/backend/src/town/dto/create-town.dto.ts index d4a20eec5d8364fdfbac5d317180a564bcb8de65..461128acad54e31ff397d06ea128df43a8ef7702 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/dto/createTownReq.dto.ts b/backend/src/town/dto/createTownReq.dto.ts new file mode 100644 index 0000000000000000000000000000000000000000..9ee2cec108c99b9b5410b1ed29edb1b5ed5ca491 --- /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; +} diff --git a/backend/src/town/dto/update-town.dto.ts b/backend/src/town/dto/update-town.dto.ts index 6982b689f2ff37d9ebfa57f10c3f063039cfdc02..5bd1663050302afd1105594a54f7399216d8f0c5 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 9e9689ae4485c662c20c2d3dc63fb8f449f915c7..bfe8a378d1fc2f4f414671f12bbe92fd9ceee9c8 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[]; diff --git a/backend/src/town/town.controller.ts b/backend/src/town/town.controller.ts index f0028d14750800aaae38c2873c65349a576eff6a..4e986796b87557c411061a5058564c2d7a71f015 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'; @@ -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') @@ -37,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 c4d5ef95febab420a45a49da7c3d38e8460de372..59fc928bed9f51209afc008b28d11066630e07b9 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); + } } diff --git a/backend/src/user/user.controller.ts b/backend/src/user/user.controller.ts index ac921025eee12e482ff0e9fffbb2102e9ad70598..b95b2314be0e0a53d3b7b2c295a952477912803c 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; - } - } }