Merge branch 'refacto/live-votes' into dev

This commit is contained in:
Maxime Lalo 2023-10-02 10:01:59 +02:00
commit 02b046ad59
3 changed files with 18 additions and 47 deletions

View File

@ -1,4 +1,4 @@
import { Appointment } from "le-coffre-resources/dist/SuperAdmin"; import { Appointment, Vote } from "le-coffre-resources/dist/SuperAdmin";
import BaseSuperAdmin from "../BaseSuperAdmin"; import BaseSuperAdmin from "../BaseSuperAdmin";
@ -18,6 +18,9 @@ export type LiveVote = {
appointment: Appointment; appointment: Appointment;
}; };
export type IDeleteVotesParams = {
uid: Vote["uid"];
};
export default class LiveVotes extends BaseSuperAdmin { export default class LiveVotes extends BaseSuperAdmin {
private static instance: LiveVotes; private static instance: LiveVotes;
private readonly baseURl = this.namespaceUrl.concat("/live-votes"); private readonly baseURl = this.namespaceUrl.concat("/live-votes");
@ -46,4 +49,17 @@ export default class LiveVotes extends BaseSuperAdmin {
return Promise.reject(err); return Promise.reject(err);
} }
} }
/**
* @description : Delete a vote
*/
public async delete(body: IDeleteVotesParams): Promise<Vote> {
const url = new URL(`${this.baseURl}/${body.uid}`);
try {
return await this.deleteRequest<Vote>(url, body);
} catch (err) {
this.onError(err);
return Promise.reject(err);
}
}
} }

View File

@ -1,44 +0,0 @@
import { Vote } from "le-coffre-resources/dist/SuperAdmin";
import BaseSuperAdmin from "../BaseSuperAdmin";
// TODO Type get query params -> Where + inclue + orderby
export interface IGetVotessparams {
where?: {};
include?: {};
select?: {};
}
export type IDeleteVotesParams = {
uid: Vote["uid"];
};
export default class Votes extends BaseSuperAdmin {
private static instance: Votes;
private readonly baseURl = this.namespaceUrl.concat("/votes");
private constructor() {
super();
}
public static getInstance() {
if (!this.instance) {
return new this();
} else {
return this.instance;
}
}
/**
* @description : Create a Votes
*/
public async delete(body: IDeleteVotesParams): Promise<Vote> {
const url = new URL(this.baseURl + "/" + body.uid);
try {
return await this.deleteRequest<Vote>(url, body);
} catch (err) {
this.onError(err);
return Promise.reject(err);
}
}
}

View File

@ -3,7 +3,6 @@ import WarningIcon from "@Assets/images/warning.png";
import Roles from "@Front/Api/LeCoffreApi/Admin/Roles/Roles"; import Roles from "@Front/Api/LeCoffreApi/Admin/Roles/Roles";
import LiveVotes from "@Front/Api/LeCoffreApi/SuperAdmin/LiveVotes/LiveVotes"; import LiveVotes from "@Front/Api/LeCoffreApi/SuperAdmin/LiveVotes/LiveVotes";
import Users from "@Front/Api/LeCoffreApi/SuperAdmin/Users/Users"; import Users from "@Front/Api/LeCoffreApi/SuperAdmin/Users/Users";
import Votes from "@Front/Api/LeCoffreApi/SuperAdmin/Votes/Votes";
import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button"; import Button, { EButtonVariant } from "@Front/Components/DesignSystem/Button";
import SelectField, { IOption } from "@Front/Components/DesignSystem/Form/SelectField"; import SelectField, { IOption } from "@Front/Components/DesignSystem/Form/SelectField";
import Confirm from "@Front/Components/DesignSystem/Modal/Confirm"; import Confirm from "@Front/Components/DesignSystem/Modal/Confirm";
@ -224,7 +223,7 @@ export default function UserInformations(props: IProps) {
const user = JwtService.getInstance().decodeJwt(); const user = JwtService.getInstance().decodeJwt();
const vote = currentAppointment.votes?.find((vote) => vote.voter?.uid === user?.userId); const vote = currentAppointment.votes?.find((vote) => vote.voter?.uid === user?.userId);
if (!vote) return; if (!vote) return;
await Votes.getInstance().delete({ uid: vote.uid }); await LiveVotes.getInstance().delete({ uid: vote.uid });
await getUser(); await getUser();
}, [currentAppointment, getUser]); }, [currentAppointment, getUser]);