Skip to content

Commit

Permalink
✨ Feat (candidacy.repository): Alteração no tratamento de erro de und…
Browse files Browse the repository at this point in the history
…efined para console.log e utilização do throw new Error.
  • Loading branch information
leticiazalasik committed Oct 14, 2024
1 parent b10a1e1 commit 16dc3c1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/modules/alert/repository/candidacy.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,26 @@ export class CandidacyRepository {
return this.candidacyRepository.save(candidacy);
}

async updateStatus(id: string, status: CandidacyStatus): Promise<CandidacyEntity | undefined> {
async updateStatus(id: string, status: CandidacyStatus): Promise<CandidacyEntity> {
try {
const candidacyToUpdate = await this.candidacyRepository.findOne({ where: { id } });
const candidacyToUpdate = await this.candidacyRepository.findOne({ where: { id } });

if (!candidacyToUpdate) {
return undefined;
console.log(`Candidatura com ID ${id} não encontrada.`);
throw new Error(`Candidatura com ID ${id} não foi encontrada.`);
}

candidacyToUpdate.status = status;
await this.candidacyRepository.save(candidacyToUpdate);

return candidacyToUpdate;
} catch (error) {
return undefined;
console.error('Erro ao atualizar o status da candidatura:', error.message);
throw new Error('Erro ao atualizar o status da candidatura.');
}
}


async findByUserId(userId: string): Promise<CandidacyEntity[]> {
return await this.candidacyRepository.find({ where: { userId } });
}
Expand Down

0 comments on commit 16dc3c1

Please sign in to comment.