From e0e63b46ebd7c6b6876cb1292390dd80b3bd7cab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Thu, 25 Apr 2024 11:14:20 -0600 Subject: [PATCH 1/8] agregando town traduction --- backend/src/app.module.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index 203a432c..4cb9adc6 100644 --- a/backend/src/app.module.ts +++ b/backend/src/app.module.ts @@ -16,6 +16,7 @@ import { ServeStaticModule } from '@nestjs/serve-static'; import { join } from 'path'; import { Town } from './town/entities/town.entity'; import { TownModule } from './town/town.module'; +import { TownTraduction } from './town/entities/town-traduction.entity'; @Module({ imports: [ TypeOrmModule.forRoot({ @@ -25,7 +26,7 @@ import { TownModule } from './town/town.module'; username: DbConstants.DB_USER, password: DbConstants.DB_PASSWORD, database: DbConstants.DB_NAME, - entities: [Admin, User, State, Town], + entities: [Admin, User, State, Town, TownTraduction], synchronize: DbConstants.DB_SYNC, }), AuthAdminModule, -- GitLab From 33cc3f689e770f08ab36f40a9ba7f1eea2790f35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Thu, 25 Apr 2024 11:14:55 -0600 Subject: [PATCH 2/8] agregando enum de los idiomas disponibles --- backend/src/enum/languages.enum.ts | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 backend/src/enum/languages.enum.ts diff --git a/backend/src/enum/languages.enum.ts b/backend/src/enum/languages.enum.ts new file mode 100644 index 00000000..78a3c146 --- /dev/null +++ b/backend/src/enum/languages.enum.ts @@ -0,0 +1,4 @@ +export enum LANGUAGES { + EN = 'en', + ES = 'es', +} -- GitLab From 64dd02314cdbc1fe5a915025da8d9dadce6b0447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Thu, 25 Apr 2024 11:15:15 -0600 Subject: [PATCH 3/8] eliminando town de la entidad principal --- backend/src/town/entities/town.entity.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/backend/src/town/entities/town.entity.ts b/backend/src/town/entities/town.entity.ts index a2d69e5d..6001257c 100644 --- a/backend/src/town/entities/town.entity.ts +++ b/backend/src/town/entities/town.entity.ts @@ -12,9 +12,6 @@ export class Town { @Column() name: string; - @Column() - description: string; - @Column() imageName: string; -- GitLab From 739c7eccacb78b5fcbe316be970b3376225a7b6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Thu, 25 Apr 2024 11:15:31 -0600 Subject: [PATCH 4/8] agregando entidad de traducciones de towns --- .../src/town/entities/town-traduction.entity.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 backend/src/town/entities/town-traduction.entity.ts diff --git a/backend/src/town/entities/town-traduction.entity.ts b/backend/src/town/entities/town-traduction.entity.ts new file mode 100644 index 00000000..52f55877 --- /dev/null +++ b/backend/src/town/entities/town-traduction.entity.ts @@ -0,0 +1,14 @@ +import { Entity, Column, OneToOne, PrimaryColumn } from 'typeorm'; +import { Town } from './town.entity'; +import { LANGUAGES } from 'src/enum/languages.enum'; +@Entity() +export class TownTraduction { + @PrimaryColumn() + @OneToOne(() => Town, (town) => town.townId) + townId: number; + @PrimaryColumn() + language: LANGUAGES; + + @Column() + description: string; +} -- GitLab From 1a83733922d3e8ef9fa611f0243b63a3fa948f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Thu, 25 Apr 2024 11:16:17 -0600 Subject: [PATCH 5/8] agregando dto para crear un pueblo --- backend/src/town/dto/create-town.dto.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/backend/src/town/dto/create-town.dto.ts b/backend/src/town/dto/create-town.dto.ts index 59e19ab9..d4a20eec 100644 --- a/backend/src/town/dto/create-town.dto.ts +++ b/backend/src/town/dto/create-town.dto.ts @@ -3,8 +3,18 @@ import { ApiProperty } from '@nestjs/swagger'; export class CreateTownDto { @ApiProperty() name: string; - @ApiProperty() - description: 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; -- GitLab From 45b1dcdcc4af617d5ac990012f26d9ef31c082d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Thu, 25 Apr 2024 11:16:36 -0600 Subject: [PATCH 6/8] agregando dto para la creacion de las traducciones --- backend/src/town/dto/create-town-trad.dto.ts | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 backend/src/town/dto/create-town-trad.dto.ts diff --git a/backend/src/town/dto/create-town-trad.dto.ts b/backend/src/town/dto/create-town-trad.dto.ts new file mode 100644 index 00000000..bb0bba99 --- /dev/null +++ b/backend/src/town/dto/create-town-trad.dto.ts @@ -0,0 +1,8 @@ +import { LANGUAGES } from 'src/enum/languages.enum'; + +export class CreateTownTraductionDto { + townId: number; + language: LANGUAGES; + name: string; + description: string; +} -- GitLab From eec8e7885439efbf0a65d40eb4fdd9a8f2c6ed8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Thu, 25 Apr 2024 11:17:37 -0600 Subject: [PATCH 7/8] agregando entidad town traduction --- backend/src/town/town.module.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/src/town/town.module.ts b/backend/src/town/town.module.ts index 13393bc2..528cfcc3 100644 --- a/backend/src/town/town.module.ts +++ b/backend/src/town/town.module.ts @@ -5,10 +5,11 @@ import { TypeOrmModule } from '@nestjs/typeorm'; import { Town } from './entities/town.entity'; import { StateService } from 'src/state/state.service'; import { State } from 'src/state/entities/state.entity'; +import { TownTraduction } from './entities/town-traduction.entity'; @Module({ controllers: [TownController], providers: [TownService, StateService], - imports: [TypeOrmModule.forFeature([Town, State])], + imports: [TypeOrmModule.forFeature([Town, State, TownTraduction])], }) export class TownModule {} -- GitLab From 9408590301d9b04f0c83ea448d581c098e896bbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Iv=C3=A1n?= <80365304+Diego-lvan@users.noreply.github.com> Date: Thu, 25 Apr 2024 11:18:14 -0600 Subject: [PATCH 8/8] modificando servicio para que agregue traducciones --- backend/src/town/town.service.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/backend/src/town/town.service.ts b/backend/src/town/town.service.ts index 027ad857..e547f2da 100644 --- a/backend/src/town/town.service.ts +++ b/backend/src/town/town.service.ts @@ -4,18 +4,38 @@ import { Repository } from 'typeorm'; import { Town } from './entities/town.entity'; import { InjectRepository } from '@nestjs/typeorm'; import { StateService } from 'src/state/state.service'; +import { TownTraduction } from './entities/town-traduction.entity'; +import { CreateTownTraductionDto } from './dto/create-town-trad.dto'; +import { LANGUAGES } from 'src/enum/languages.enum'; @Injectable() export class TownService { constructor( @InjectRepository(Town) private townRepository: Repository, + @InjectRepository(TownTraduction) private townTradRepository: Repository, private state: StateService, ) {} async create(createTownDto: CreateTownDto) { const state = await this.state.findOne(createTownDto.state); if (!state) throw new BadRequestException('State does not exist'); - await this.townRepository.save(createTownDto); + const town = await this.townRepository.save(createTownDto); + 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, + }; + + await this.townTradRepository.save(createTownTradDtoES); + await this.townTradRepository.save(createTownTradDtoEN); } findAll() { -- GitLab