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