From 576bb901366aca089748c81baf804a27b1f18d0d Mon Sep 17 00:00:00 2001
From: ManifoldFR <wilson.jallet@gmail.com>
Date: Mon, 5 Mar 2018 15:03:09 +0100
Subject: [PATCH] Nouveaux groupes, posts, nouveaux champs

---
 db/seeds/01_create_groups.js         | 16 ++++++++++++++++
 db/seeds/02_make_posts.js            |  8 ++++++++
 src/graphql/connectors/connectors.js | 15 +++++++++++----
 src/graphql/resolvers.js             |  3 ---
 src/graphql/typeDefs.js              | 10 ++++++++--
 5 files changed, 43 insertions(+), 9 deletions(-)

diff --git a/db/seeds/01_create_groups.js b/db/seeds/01_create_groups.js
index fb2d494..048d6f7 100644
--- a/db/seeds/01_create_groups.js
+++ b/db/seeds/01_create_groups.js
@@ -48,6 +48,14 @@ exports.seed = function(knex, Promise) {
           website: 'laserwave.fr',
           school: 'supoptique',
           type : 'simple'
+        },
+        {
+          name: 'WikiX',
+          uid: 'wikix',
+          website: 'https://wikix.polytechnique.org/',
+          school: "polytechnique",
+          description: "Le recueil de la mémoire des élèves",
+          type: "simple",
         },{
           name: 'BDE Ensta',
           uid: 'bdeensta',
@@ -55,6 +63,14 @@ exports.seed = function(knex, Promise) {
           school: 'ensta',
           type : 'simple'
         },
+        {
+          name: "X-Chine",
+          uid: "x-chine",
+          website: "",
+          school: "polytechnique",
+          description: `X-Chine est le binet qui rassemble les amoureux et les curieux de l'Empire du Milieu, qu'ils soient chinois ou non !`,
+          type: "simple"
+        },
         {
           name: 'Subaïsse',
           uid: 'subaisse',
diff --git a/db/seeds/02_make_posts.js b/db/seeds/02_make_posts.js
index 4b9f577..772e4c6 100644
--- a/db/seeds/02_make_posts.js
+++ b/db/seeds/02_make_posts.js
@@ -11,6 +11,14 @@ exports.seed = function(knex, Promise) {
         title: "Proj'et Promotion",
         description: "La nouvelle proj' du JTX arrive !",
         authors: ['br']
+      },{
+        title: "Fête de la Lune",
+        description: "C'est bientôt la fête de la Lune ! Inscrivez-vous pour un dîner-spectacle dans le Grand Hall !",
+        authors: ['x-chine']
+      },{
+        title: "Formation Web",
+        description: "Envie d'apprendre à faire un site Web en Django ? Alors viens en amphi Sauvy ce jeudi à 20h !",
+        authors: ['br']
       }];
 
       return knex('posts').insert(posts);
diff --git a/src/graphql/connectors/connectors.js b/src/graphql/connectors/connectors.js
index 6b431f7..3577c44 100644
--- a/src/graphql/connectors/connectors.js
+++ b/src/graphql/connectors/connectors.js
@@ -234,14 +234,14 @@ export async function getAllVisibleSimpleGroups (user){
     return knex.with('visible_groups', visible_groups).select().from("simple_groups").innerJoin('visible_groups', function (){
         this.on('visible_groups.uid', '=', 'simple_groups.uid');
     });
-};
+}
 
 export async function getAllVisibleMetaGroups (user){
     let visible_groups = await getVisibleGroupCallback(user);
     return knex.with('visible_groups', visible_groups).select().from("meta_groups").innerJoin('visible_groups', function (){
         this.on('visible_groups.uid', '=', 'meta_groups.uid');
     });
-};
+}
 
 /**
  * @summary Renvoie tous les groupes visibles par l'utilisateur user
@@ -393,19 +393,26 @@ export const getYourGroupHostEventRequests = (user, recipientUID) => {
 //Don't forget the argument user is the guy who makes the request, not the user we want
 export const getUser = (user, userUID) => { 
     const refactorer = (data) => {
+        console.log("type of nick",typeof data.nickname);
+        if (typeof data.brRoom == 'string') data.brRoom = [data.brRoom];
+
         return {
             uid: userUID,
             lastName: data.sn,
             givenName: data.givenName,
+            nickname: data.displayName,
+            nationality: data.country,
             birthdate: data.brBirthdate,
             groups: data.brMemberOf,
             mail: data.mail,
             phone: data.telephoneNumber,
-            room: data.brRoom
+            address: data.brRoom,
+            promotion: data.brPromo
         };
     };
 
     const result = renseignerSurUtilisateur(user, userUID).then(res => {
+        console.log(res[0]);
         return refactorer(res[0]);
     });
 
@@ -478,4 +485,4 @@ export async function getMetaGroupMembersCallback(user, metaGroupUID){
             .innerJoin('meta_group_membership', 'groups.uid', 'meta_group_membership.member_uid')
             .where('meta_group_membership.union_uid', '=', metaGroupUID);
     };
-};
\ No newline at end of file
+}
\ No newline at end of file
diff --git a/src/graphql/resolvers.js b/src/graphql/resolvers.js
index d7b681c..a2ee7cb 100644
--- a/src/graphql/resolvers.js
+++ b/src/graphql/resolvers.js
@@ -258,16 +258,13 @@ export const resolvers = {
     },
 
     SimpleGroup: {
-
         members: (obj, args, context) => {
             return connectors.listerMembres(context.user,obj.uid);
         }
     },
 
     MetaGroup: {
-
         members: (obj, args, context) => {
         }
-
     }
 };
diff --git a/src/graphql/typeDefs.js b/src/graphql/typeDefs.js
index f226961..9bde819 100644
--- a/src/graphql/typeDefs.js
+++ b/src/graphql/typeDefs.js
@@ -139,6 +139,9 @@ const User = `
         givenName: String!
         # Nom de famille
         lastName: String!
+        # Surnom
+        nickname: String
+        nationality: String
         uid: ID!
         birthdate: String!
         mail: String
@@ -147,7 +150,10 @@ const User = `
         groups: [SimpleGroup]
         # Groupes que l'utilisateur aime.
         likes: [Group]
-        address: String
+        # Adresse(s) de l'utilisateur.
+        address: [String]
+        # Promotion
+        promotion: String
     }
 `;
 
@@ -226,7 +232,7 @@ const Post = `
         createdAt: String!
         updatedAt: String!
         authors: [Group]
-        content: String!
+        description: String!
     }
 `;
 
-- 
GitLab