diff --git a/backend/src/app.module.ts b/backend/src/app.module.ts index 203a432ca68251b7fd796cb07392b869c5b423b6..4cb9adc60459df315c12580eb4a77f134a694e56 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, diff --git a/backend/src/enum/languages.enum.ts b/backend/src/enum/languages.enum.ts new file mode 100644 index 0000000000000000000000000000000000000000..78a3c1465985c88d46f64f5c7ae789cfb766cbcd --- /dev/null +++ b/backend/src/enum/languages.enum.ts @@ -0,0 +1,4 @@ +export enum LANGUAGES { + EN = 'en', + ES = 'es', +} 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 0000000000000000000000000000000000000000..bb0bba99c47c342a68ada7a246a0ff2b525a147c --- /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; +} diff --git a/backend/src/town/dto/create-town.dto.ts b/backend/src/town/dto/create-town.dto.ts index 59e19ab9e3c434f9bbd601826c377338b31d782a..d4a20eec5d8364fdfbac5d317180a564bcb8de65 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; 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 0000000000000000000000000000000000000000..52f5587761833af05cc412792bb099dce033c6c6 --- /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; +} diff --git a/backend/src/town/entities/town.entity.ts b/backend/src/town/entities/town.entity.ts index a2d69e5dc081fbe0af5060e25fcc60c2e9e5659e..6001257cf99346c43c4f4e3f15f3fc71c5bd51a6 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; diff --git a/backend/src/town/town.module.ts b/backend/src/town/town.module.ts index 13393bc233fa370202cee0b8e97287fc41b0b560..528cfcc3ecd4b8a5ed6112f6bcdb0538aa901b10 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 {} diff --git a/backend/src/town/town.service.ts b/backend/src/town/town.service.ts index 027ad857b647c895d62cd66c8a00cdbe179c6e58..e547f2daf2e1b007417870762091e4616cbc8647 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() {