From 4a9d4856fb3963e50667cb832d15543d57e6af8f Mon Sep 17 00:00:00 2001
From: ManifoldFR <wilson.jallet@gmail.com>
Date: Wed, 28 Feb 2018 23:16:30 +0100
Subject: [PATCH] Un-breaking stuff

---
 src/graphql/schema.js | 14 ++++++++------
 src/ldap/ldap_data.js |  1 -
 src/server.js         | 12 ++++++++++--
 3 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/src/graphql/schema.js b/src/graphql/schema.js
index e844d0c..c120901 100644
--- a/src/graphql/schema.js
+++ b/src/graphql/schema.js
@@ -4,14 +4,14 @@
 */
 
 import knex from '../../db/knex_router';
-import { listGroups, listMembers} from '../ldap/ldap_data';
+// import { listGroups, listMembers } from '../ldap/ldap_data';
 import { makeExecutableSchema } from 'graphql-tools';
 import { request } from 'https';
 
 const typeDefs = `
     type Query {
-        allGroups: [Group]!
-        group(id : ID) : Group!
+        allGroups: [Group]
+        group(id: ID) : [Group]
     }
 
     type Group {
@@ -25,12 +25,13 @@ const typeDefs = `
 `;
 
 const getAllVisibleGroups = (user) => {
-    let group_ids = listGroups(user.id);
-    return knex.select().from('groups').whereIn('id', group_ids);
+    // let group_ids = listGroups(user.id);
+    return knex.select().from('groups')/*.whereIn('id', group_ids)*/;
 };
     
 const getGroupIfVisible = (user, id) => {
-    return this.getAllVisibleGroups(user).where('id', id);
+    return getAllVisibleGroups(user)/*.where('id', id).then(function(table) {
+        console.log(JSON.stringify(table,null,2))*/;
 };
 
 const resolvers = {
@@ -39,6 +40,7 @@ const resolvers = {
             return getAllVisibleGroups(context.user);
         },
         group: (obj, args, context) => {
+            console.log(args.id);
             return getGroupIfVisible(context.user, args.id);
         }
     }
diff --git a/src/ldap/ldap_data.js b/src/ldap/ldap_data.js
index 5e8e5e8..f1fb8a5 100644
--- a/src/ldap/ldap_data.js
+++ b/src/ldap/ldap_data.js
@@ -116,7 +116,6 @@ function TOL(c0="", c1="", c2="", c3="", c4="", c5="", c6="", c7="", c8="", c9="
 
 // Synthaxe d'utilisation
 //listGroups("quentin.louis").then((meList) => { console.log(meList); });
-TOL("","","","","","","faerix","","","","","","").then((meList) => { console.log(meList); });
 
 /* Partage pour le reste du monde ; même remarque synthaxe  
 export { listGroups, listMembers, TOL }; */
diff --git a/src/server.js b/src/server.js
index 0050062..a40a9c5 100644
--- a/src/server.js
+++ b/src/server.js
@@ -32,11 +32,19 @@ server.use(favicon(path.resolve('./','assets','favicon.ico')));
 server.use(morgan('dev'));
 
 // Charge le middleware express pour GraphQL
-server.use('/graphql', bodyParser.json(), 
+server.use('/graphql', bodyParser.json(), cors(),
     graphqlExpress(req => {
+        let uid;
+
+        try {
+            uid = req.session.id;
+        } catch (err) {
+            uid = "1";
+        }
+
         return {
             schema : schema,
-            context : {user : {id : req.session.id}}
+            context : {user : {id : uid}}
         };
     }));
 
-- 
GitLab