Loading backend/src/town/town.service.ts +21 −1 Original line number Diff line number Diff line Loading @@ -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<Town>, @InjectRepository(TownTraduction) private townTradRepository: Repository<TownTraduction>, 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() { Loading Loading
backend/src/town/town.service.ts +21 −1 Original line number Diff line number Diff line Loading @@ -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<Town>, @InjectRepository(TownTraduction) private townTradRepository: Repository<TownTraduction>, 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() { Loading