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

agregando validacion del Town, solo para admins

parent fb6faead
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ import { Admin } from './entities/admin.entity';
import { Repository } from 'typeorm';
import { InjectRepository } from '@nestjs/typeorm';
import { Town } from 'src/town/entities/town.entity';
import { ADMIN_ROLE } from 'src/shared/enum/admin-role.enum';

@Injectable()
export class AdminService {
@@ -12,7 +13,10 @@ export class AdminService {
    @InjectRepository(Town) private townRepository: Repository<Town>,
  ) {}
  async create(createAdminDto: CreateAdminDto) {
    const town = await this.townRepository.findOneBy({ townId: createAdminDto.idTown });
    let town: Town = null;
    if (createAdminDto.role == ADMIN_ROLE.ADMIN) {
      town = await this.townRepository.findOneByOrFail({ townId: createAdminDto.idTown });
    }
    await this.adminRepository.insert({ ...createAdminDto, idTown: town });
  }