Commit 94085903 authored by Diego Iván's avatar Diego Iván
Browse files

modificando servicio para que agregue traducciones

parent eec8e788
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -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() {