Commit b8c76fd4 authored by Olivér FACKLAM's avatar Olivér FACKLAM

[MemberMut] user(un)Participate

parent 645e22ae
Pipeline #5745 passed with stages
in 1 minute and 48 seconds
......@@ -484,39 +484,27 @@ export class MessageModel {
/**
* @memberof GraphQL.MessageModel#
* @function userParticipate
* @summary Fonction pour participer a un evenement.
* @arg {string} uid - Identifiant de l'utilisateur.
* @arg {number} mid - Identifiant de l'évenement.
* @summary Fonction pour participer a un evenement. Les données doivent exister en SQL.
* @return {Promise(boolean)} Renvoie true si modification réussie
* @async
* @rights member d'un groupe author ou recipient
* @rights speaker d'un groupe author ou membre d'un recipient
*/
async userParticipate(uid: string, mid: number): Promise<boolean> {
try{
let res = await knex("events_participating_users").insert({mid : mid, uid : uid}, ['id']);
return true;
}catch(e){
return false;
}
async userParticipate(uid: string, eid: number): Promise<boolean> {
let res = await knex("events_participating_users").insert({eid : eid, uid : uid}, ['id']);
return res.length > 0;
}
/**
* @memberof GraphQL.MessageModel#
* @function userUnparticipate
* @summary Fonction pour ne plus participer a un evenement.
* @arg {string} uid - Identifiant de l'utilisateur.
* @arg {number} mid - Identifiant de l'évenement.
* @return {Promise(boolean)} Renvoie true si modification réussie
* @async
* @rights member d'un groupe author ou recipient
* @rights speaker d'un groupe author ou membre d'un recipient
*/
async userUnparticipate(uid: string, mid: number): Promise<boolean> {
try{
let res = await knex("events_participating_users").where('mid' , mid).andWhere('uid',uid ).del();
return true;
}catch(e){
return false;
}
async userUnparticipate(uid: string, eid: number): Promise<boolean> {
let res = await knex("events_participating_users").where('eid', eid).andWhere('uid', uid).del();
return res > 0;
}
/**
......
......@@ -407,20 +407,29 @@ export const resolvers = {
throw new AuthenticationError("Not a member");
},
// @rights member d'un groupe author ou recipient
// @rights speaker d'un groupe author ou membre d'un recipient
userParticipate: async function (root, args, context: Context): Promise<boolean> {
throw "Not implemented";
//TODO : Vérifier les autorisations
return context.models.message.userParticipate(context.user.uid, args.forEvent);
throw new AuthenticationError("Not a viewer");
let eid = args.forEvent;
let authors = await context.models.message.getEventAuthors(eid);
let recipients = await context.models.message.getEventRecipients(eid);
if(await context.models.auth.isSpeakerOr(authors) || await context.models.auth.isMemberOr(recipients)) {
await context.models.user.ensureExists(context.models.auth.getUid());
return context.models.message.userParticipate(context.models.auth.getUid(), args.forEvent);
}
throw new AuthenticationError("Not a speaker of authors or member of recipients");
},
// @rights member d'un groupe author ou recipient
userUnparticipate: async function (root, args, context: Context): Promise<boolean> {
throw "Not implemented";
//TODO : Vérifier les autorisations
return context.models.message.userUnparticipate(context.user.uid, args.forEvent);
throw new AuthenticationError("Not a viewer");
let eid = args.forEvent;
let authors = await context.models.message.getEventAuthors(eid);
let recipients = await context.models.message.getEventRecipients(eid);
if (await context.models.auth.isSpeakerOr(authors) || await context.models.auth.isMemberOr(recipients)) {
return context.models.message.userUnparticipate(context.models.auth.getUid(), args.forEvent);
}
throw new AuthenticationError("Not a speaker of authors or member of recipients");
},
// @rights member
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment