diff --git a/src/graphql/connectors/connectors.js b/src/graphql/connectors/connectors.js index 0ad6096fe3e598e25b662266c7173153ea39a1cf..8df5b0499be674ce3b3f09d15e8f481cd893bee2 100644 --- a/src/graphql/connectors/connectors.js +++ b/src/graphql/connectors/connectors.js @@ -7,8 +7,6 @@ import * as selectors from './selectors'; import * as list_selectors from './list_selectors'; import ldap from '../../ldap/ldap_data'; -// dn et mot de passe du bind user du LDAP -import ldap_bind_user from '../../../ldap_connexion_config.json'; const utilisateur = new ldap.UtilisateurAnonyme(); diff --git a/src/graphql/resolvers.js b/src/graphql/resolvers.js index dfcc206f3600108603fb48aa2ad16312c8f157b8..af420e114b2f88a6d31985d5e6d5c0c218dffea5 100644 --- a/src/graphql/resolvers.js +++ b/src/graphql/resolvers.js @@ -14,6 +14,7 @@ import authenticator from '../graphql/authenticator'; import * as connectors from './connectors/connectors'; import * as list_selectors from './connectors/list_selectors'; import * as authentifiers from './connectors/authentifiers'; +import MessageResolvers from './resolvers/messages'; /** * @description Résolveurs des différentes requêtes GraphQL @@ -65,11 +66,11 @@ export const resolvers = { return knex.select().from("announcements"); }, - allEvents: function(obj, args, context) { + allEvents(root, args, context) { return knex.select().from("events"); }, - allMessages: function(obj, args, context) { + allMessages(root, args, context) { const events = knex.select().from("events"); const posts = knex.select().from("posts"); return Promise.all([events, posts]).then(res => { @@ -232,56 +233,11 @@ export const resolvers = { }, - Message: { - - __resolveType: function(obj) { - if (obj.hasOwnProperty('location')) return "Event"; - else return "Post"; - }, - authors: (obj, args, context) => { - return knex.select().from('groups').whereIn('uid', obj.authors); - } - - }, - - Post: { - }, - - Announcement: { - forEvent : function(obj, args, context){ - // le champ is_announcement n'existe que sur les Events - // une ligne de la bdd events peut résoudre comme évènement ou comme annonce - if(obj.is_announcement) - return obj; - else - return null; - } - }, - - Event: { - - startTime : function(obj){ - return obj.start_time; - }, - - endTime : function(obj){ - return obj.end_time; - }, - - asAnnouncement : function(obj, args, context){ - // le champ is_announcement indique si il existe une annonce qui va avec l'évènement - // une ligne de la bdd events peut résoudre comme évènement ou comme annonce - if(obj.is_announcement) - return obj; - else - return null; - } - }, + ...MessageResolvers, // @rights viewer(obj.uid) Group: { __resolveType: async (obj) => { - switch(obj.type) { case "simple": return "SimpleGroup"; @@ -293,7 +249,6 @@ export const resolvers = { // @rights viewer(obj.uid) SimpleGroup: { - members: (obj, args, context) => { return connectors.utilisateur.listMembers(context.bindUser,obj.uid); } diff --git a/src/graphql/resolvers/messages.js b/src/graphql/resolvers/messages.js new file mode 100644 index 0000000000000000000000000000000000000000..fbcc64b88aa8f971fd87da19e625c7306cbc4c4b --- /dev/null +++ b/src/graphql/resolvers/messages.js @@ -0,0 +1,67 @@ +/** + * @file Resolvers pour tous les types de messages. + */ +import knex from '../../../db/knex_router'; + +const MessageResolvers = { + + Message: { + __resolveType: function(message) { + if (message.hasOwnProperty('location')) return "Event"; + else return "Post"; + } + }, + + Post: { + authors(message, args, context) { + const result = knex.select().from('groups').whereIn('uid', message.authors); + console.log("Resolved authors field as:"); + // console.log(result); + return result; + } + }, + + Announcement: { + authors(message, args, context) { + const result = knex.select().from('groups').whereIn('uid', message.authors); + console.log("Resolved authors field as:"); + // console.log(result); + return result; + }, + forEvent: function(obj, args, context) { + // le champ is_announcement n'existe que sur les Events + // une ligne de la bdd events peut résoudre comme évènement ou comme annonce + if (obj.is_announcement) + return obj; + else + return null; + } + }, + + Event: { + authors(message, args, context) { + const result = knex.select().from('groups').whereIn('uid', message.authors); + // console.log(result); + return result; + }, + + startTime: function(obj) { + return obj.start_time; + }, + + endTime: function(obj) { + return obj.end_time; + }, + + asAnnouncement: function(obj, args, context) { + // le champ is_announcement indique si il existe une annonce qui va avec l'évènement + // une ligne de la bdd events peut résoudre comme évènement ou comme annonce + if (obj.is_announcement) + return obj; + else + return null; + } + } +}; + +export default MessageResolvers; \ No newline at end of file diff --git a/src/graphql/typeDefs/objects.graphql b/src/graphql/typeDefs/objects.graphql index bc6609bd22f82ca46911a38768a4ff6616f98ee8..f82ba0544c9a4184fe77a0ef05767db735f06635 100644 --- a/src/graphql/typeDefs/objects.graphql +++ b/src/graphql/typeDefs/objects.graphql @@ -47,12 +47,12 @@ type SimpleGroup implements Group { uid: ID name: String website: String + description: String createdAt: String! updatedAt: String! # Membres du groupe members: [User] - description: String # École d'origine du groupe school: String # Groupe parent @@ -104,7 +104,7 @@ type Announcement implements Message { content: String! importance: Int views: Int - forEvent : Event + forEvent: Event } # Événements organisés par un ou plusieurs groupes. @@ -124,7 +124,7 @@ type Event implements Message { participatingGroups: [Group] participatingUsers: [User] content: String - asAnnouncement : Announcement + asAnnouncement: Announcement } interface Request { diff --git a/src/server.ts b/src/server.ts index 75f997dba5b908582da10f4c31805162afaf1c22..9c967cad9d4a3840bf98872c51a9850c15a4a88d 100644 --- a/src/server.ts +++ b/src/server.ts @@ -200,13 +200,13 @@ const context = async ({ req }) => { let uid; let password; - console.log("Responding to graphql request..."); - console.log(` + // console.log("Responding to graphql request..."); + /*console.log(` | User: ${req.user ? req.user.uid : "none"} | Authorization: ${req.headers.authorization} | Authenticated: ${req.isAuthenticated()} `.trim()); - + */ if(req.isAuthenticated()) { console.log("graphql API is receiving a request from an authenticated user! \\o/"); try {