Loading backend/src/state/state.service.ts +14 −5 Original line number Diff line number Diff line Loading @@ -4,20 +4,19 @@ import { InjectRepository } from '@nestjs/typeorm'; import { State } from './entities/state.entity'; import { Repository } from 'typeorm'; import { ServerConstants } from 'src/constants/server.contants'; import { StateResponseDto } from './dto/state-res.dto'; @Injectable() export class StateService { constructor( @InjectRepository(State) private stateRepository: Repository<State>, ) {} constructor(@InjectRepository(State) private stateRepository: Repository<State>) {} async create(createStateDto: CreateStateDto) { await this.stateRepository.save(createStateDto); } async findAll() { async findAll(): Promise<Array<StateResponseDto>> { const states = await this.stateRepository.find(); const statesResponse = states.map(({ imageName, name, stateId }) => { const statesResponse: Array<StateResponseDto> = states.map(({ imageName, name, stateId }) => { return { stateId, name, Loading @@ -27,4 +26,14 @@ export class StateService { return statesResponse; } async findOne(id: number) { const state = await this.stateRepository.findOneBy({ stateId: id }); if (!state) return null; return { stateId: state.stateId, name: state.name, imageURL: `${ServerConstants.HOST}/states/${state.imageName}`, }; } } Loading
backend/src/state/state.service.ts +14 −5 Original line number Diff line number Diff line Loading @@ -4,20 +4,19 @@ import { InjectRepository } from '@nestjs/typeorm'; import { State } from './entities/state.entity'; import { Repository } from 'typeorm'; import { ServerConstants } from 'src/constants/server.contants'; import { StateResponseDto } from './dto/state-res.dto'; @Injectable() export class StateService { constructor( @InjectRepository(State) private stateRepository: Repository<State>, ) {} constructor(@InjectRepository(State) private stateRepository: Repository<State>) {} async create(createStateDto: CreateStateDto) { await this.stateRepository.save(createStateDto); } async findAll() { async findAll(): Promise<Array<StateResponseDto>> { const states = await this.stateRepository.find(); const statesResponse = states.map(({ imageName, name, stateId }) => { const statesResponse: Array<StateResponseDto> = states.map(({ imageName, name, stateId }) => { return { stateId, name, Loading @@ -27,4 +26,14 @@ export class StateService { return statesResponse; } async findOne(id: number) { const state = await this.stateRepository.findOneBy({ stateId: id }); if (!state) return null; return { stateId: state.stateId, name: state.name, imageURL: `${ServerConstants.HOST}/states/${state.imageName}`, }; } }