✨ Delete appointment if no votes in appointment
This commit is contained in:
parent
7a8b6b4226
commit
2fc307f3c3
@ -105,7 +105,11 @@ export default class LiveVoteController extends ApiController {
|
||||
return;
|
||||
}
|
||||
|
||||
const voteFound = await this.liveVoteService.getVoteByUid(uid);
|
||||
const voteFound = await this.liveVoteService.getVoteByUid(uid, {
|
||||
appointment: {
|
||||
include: { votes: true },
|
||||
},
|
||||
});
|
||||
|
||||
if (!voteFound) {
|
||||
this.httpNotFoundRequest(response, "vote not found");
|
||||
@ -117,14 +121,18 @@ export default class LiveVoteController extends ApiController {
|
||||
return;
|
||||
}
|
||||
|
||||
const vote = Vote.hydrate<Vote>(voteFound, { strategy: "excludeAll" });
|
||||
|
||||
//call service to get prisma entity
|
||||
const voteEntity: Votes = await this.liveVoteService.deleteVote(uid);
|
||||
|
||||
//Hydrate ressource with prisma entity
|
||||
const vote = Vote.hydrate<Vote>(voteEntity, { strategy: "excludeAll" });
|
||||
if (vote.appointment.uid && vote.appointment.votes && vote.appointment.votes.length === 1) {
|
||||
await this.liveVoteService.deleteAppointment(vote.appointment.uid);
|
||||
}
|
||||
|
||||
const voteToReturn = Vote.hydrate<Vote>(voteEntity, { strategy: "excludeAll" });
|
||||
//success
|
||||
this.httpSuccess(response, vote);
|
||||
this.httpSuccess(response, voteToReturn);
|
||||
} catch (error) {
|
||||
this.httpInternalError(response, error);
|
||||
return;
|
||||
|
@ -49,6 +49,14 @@ export default class LiveVoteService extends BaseService {
|
||||
return this.voteRepository.delete(uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : delete an appointment by uid
|
||||
* @throws {Error} If appointment cannot be get by uid
|
||||
*/
|
||||
public deleteAppointment(uid: string) {
|
||||
return this.appointmentRepository.delete(uid);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description : Get a appointment by uid
|
||||
* @throws {Error} If appointment cannot be get by uid
|
||||
|
Loading…
x
Reference in New Issue
Block a user