Skip to content
Snippets Groups Projects
Commit 0ed79d5c authored by Elia AZAR's avatar Elia AZAR
Browse files

groups.ts -> getAllAnnouncements (args: *GroupSet*); two new functions :...

groups.ts -> getAllAnnouncements (args: *GroupSet*); two new functions : getAllAnnouncementsSent, getAllAnnouncementsReceived
parent 5678a1ed
No related branches found
No related tags found
No related merge requests found
...@@ -105,12 +105,12 @@ export class MessageModel { ...@@ -105,12 +105,12 @@ export class MessageModel {
* @memberof GraphQL.MessageModel# * @memberof GraphQL.MessageModel#
* @function getAllAnnouncements * @function getAllAnnouncements
* @summary Fonction qui renvoie toutes les annonces visibles. * @summary Fonction qui renvoie toutes les annonces visibles.
* @arg {GroupCollection} groups - Un ensemble d'identifiants, supposés valides. * @arg {GroupSet} groups - Un ensemble d'identifiants, supposés valides.
* @return {Promise(Announcement[])} Renvoie toutes les annonces émises ou reçues par ces groupes * @return {Promise(Announcement[])} Renvoie toutes les annonces émises ou reçues par ces groupes
* @async * @async
* @rights member of groups * @rights member of groups
*/ */
async getAllAnnouncements(groups: GroupCollection): Promise<Announcement[]> { async getAllAnnouncements(groups: GroupSet): Promise<Announcement[]> {
throw "Not implemented"; throw "Not implemented";
/*let result = await knex.select().from('announcements').whereIn('id', selection); /*let result = await knex.select().from('announcements').whereIn('id', selection);
...@@ -123,6 +123,50 @@ export class MessageModel { ...@@ -123,6 +123,50 @@ export class MessageModel {
return result;*/ return result;*/
} }
/**
* @memberof GraphQL.MessageModel#
* @function getAllAnnouncementsSent
* @summary Fonction qui renvoie toutes les annonces émises visibles.
* @arg {GroupSet} groups - Un ensemble d'identifiants, supposés valides.
* @return {Promise(Announcement[])} Renvoie toutes les annonces émises par ces groupes
* @async
* @rights member of groups
*/
async getAllAnnouncementsSent(groups: GroupSet): Promise<Announcement[]> {
throw "Not implemented";
/*let result = await knex.select().from('announcements').whereIn('gid');
result = result.concat(
await knex.select().from('events').whereIn('id')
);
for (let r of result) {
r.type = 'Announcement';
}
return result;*/
}
/**
* @memberof GraphQL.MessageModel#
* @function getAllAnnouncementsReceived
* @summary Fonction qui renvoie toutes les annonces reçues visibles.
* @arg {GroupSet} groups - Un ensemble d'identifiants, supposés valides.
* @return {Promise(Announcement[])} Renvoie toutes les annonces reçues par ces groupes
* @async
* @rights member of groups
*/
async getAllAnnouncementsReceived(groups: GroupSet): Promise<Announcement[]> {
throw "Not implemented";
/*let result = await knex.select().from('announcements').whereIn('gid');
result = result.concat(
await knex.select().from('events').whereIn('id')
);
for (let r of result) {
r.type = 'Announcement';
}
return result;*/
}
/** /**
* @memberof GraphQL.MessageModel# * @memberof GraphQL.MessageModel#
* @function getAllEvents * @function getAllEvents
......
...@@ -10,6 +10,7 @@ import knex from '../../../db/knex_router'; ...@@ -10,6 +10,7 @@ import knex from '../../../db/knex_router';
import { Context } from '../typeDefs/queries'; import { Context } from '../typeDefs/queries';
import { ApolloError, AuthenticationError } from 'apollo-server-core'; import { ApolloError, AuthenticationError } from 'apollo-server-core';
import { Request, UserJoinGroup, GroupJoinMetagroup, GroupCoauthorEvent } from './requests'; import { Request, UserJoinGroup, GroupJoinMetagroup, GroupCoauthorEvent } from './requests';
import { GroupSet } from '../models/tools';
export abstract class Group { export abstract class Group {
...@@ -232,7 +233,10 @@ export abstract class Group { ...@@ -232,7 +233,10 @@ export abstract class Group {
*/ */
async announcementsFromGroup(args, context: Context, info): Promise<Announcement[]> { async announcementsFromGroup(args, context: Context, info): Promise<Announcement[]> {
if(context.models.auth.isMember(this.gid)) { if(context.models.auth.isMember(this.gid)) {
throw "Not implemented" //03/03/19
let res = new GroupSet();
res.add(this.gid);
return context.models.message.getAllAnnouncementsSent(res);
} }
throw new AuthenticationError("Not a member"); throw new AuthenticationError("Not a member");
} }
...@@ -246,8 +250,11 @@ export abstract class Group { ...@@ -246,8 +250,11 @@ export abstract class Group {
* @async * @async
*/ */
async announcementsToGroup(args, context: Context, info): Promise<Announcement[]> { async announcementsToGroup(args, context: Context, info): Promise<Announcement[]> {
if (context.models.auth.isMember(this.gid)) { if(context.models.auth.isMember(this.gid)) {
throw "Not implemented" //03/03/19
let res = new GroupSet();
res.add(this.gid);
return context.models.message.getAllAnnouncementsReceived(res);
} }
throw new AuthenticationError("Not a member"); throw new AuthenticationError("Not a member");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment