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

agregando metodoo que regresa todos los estados

parent 6a70d15f
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -3,6 +3,7 @@ import { CreateStateDto } from './dto/create-state.dto';
import { InjectRepository } from '@nestjs/typeorm';
import { State } from './entities/state.entity';
import { Repository } from 'typeorm';
import { ServerConstants } from 'src/constants/server.contants';

@Injectable()
export class StateService {
@@ -13,4 +14,17 @@ export class StateService {
  async create(createStateDto: CreateStateDto) {
    await this.stateRepository.save(createStateDto);
  }

  async findAll() {
    const states = await this.stateRepository.find();
    const statesResponse = states.map(({ imageName, name, stateId }) => {
      return {
        stateId,
        name,
        imageURL: `${ServerConstants.HOST}/states/${imageName}`,
      };
    });

    return statesResponse;
  }
}