From b580342cebe8085732e72495632c9dd0dfc6aae4 Mon Sep 17 00:00:00 2001 From: anatole <anatole.romon@polytechnique.edu> Date: Wed, 30 May 2018 18:43:00 +0200 Subject: [PATCH] modif tables des messages --- .../20180530182824_drop_reciepient_column.js | 52 +++++++++++++++++++ db/seeds/02_make_posts.js | 31 +++++++++++ src/graphql/connectors/connectors.js | 6 +-- 3 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 db/migrations/20180530182824_drop_reciepient_column.js diff --git a/db/migrations/20180530182824_drop_reciepient_column.js b/db/migrations/20180530182824_drop_reciepient_column.js new file mode 100644 index 0000000..90a48e9 --- /dev/null +++ b/db/migrations/20180530182824_drop_reciepient_column.js @@ -0,0 +1,52 @@ + +exports.up = async function(knex, Promise) { + let recipients = await knex('private_posts').select('id', 'recipient_uid'); + for(entry of recipients){ + knex('group_message_relationships').insert({ + message : entry.id, + group : entry.recipient_uid, + status : "recieve" + }); + } + await knex.schema.table('private_posts', (table) => { + table.dropColumn('recipient_uid'); + }); + + recipients = await knex('questions').select('id', 'recipient_uid'); + for(entry of recipients){ + knex('group_message_relationships').insert({ + message : entry.id, + group : entry.recipient_uid, + status : "recieve" + }); + } + await knex.schema.table('questions', (table) => { + table.dropColumn('recipient_uid'); + }); + + recipients = await knex('answers').select('id', 'recipient_uid'); + for(entry of recipients){ + knex('group_message_relationships').insert({ + message : entry.id, + group : entry.recipient_uid, + status : "recieve" + }); + } + await knex.schema.table('answers', (table) => { + table.dropColumn('recipient_uid'); + }); + +}; + +exports.down = async function(knex, Promise) { + await knex.schema.table('private_posts', (table) => { + table.string("recipient_uid"); + }); + await knex.schema.table('questions', (table) => { + table.string("recipient_uid"); + }); + await knex.schema.table('answers', (table) => { + table.string("recipient_uid"); + }); + +}; diff --git a/db/seeds/02_make_posts.js b/db/seeds/02_make_posts.js index 1979d20..5aad98a 100644 --- a/db/seeds/02_make_posts.js +++ b/db/seeds/02_make_posts.js @@ -32,6 +32,24 @@ exports.seed = async function(knex, Promise) { } ]); + await knex('private_posts').del(); + await knex('private_posts').insert([ + { + id : 4, + title : "Anatole met du temps à faire avancer resolver_dev", + content : "C'est scandaleux qu'anatole mette autant de temps à corriger les bugs et merge sa branche. Comment on fait pour présenter le projet aux 17 ?", + author_uid : "guillaume.wang", + author_db : "ldap" + }, + { + id : 5, + title : "Sushi tradi", + content : "Le prochain sushi tradi aura lieux ce mardi. Tout le monde est invité.", + author_uid : "martin.guillot", + author_db : "ldap" + }, + ]); + await knex('group_message_relationships').del(); await knex('group_message_relationships').insert([ @@ -74,5 +92,18 @@ exports.seed = async function(knex, Promise) { status: 'host' }]); + await knex('group_message_relationships').insert([ + { + message : 4, + group : "br", + status : "recieve" + }, + { + message : 5, + group : "faerix", + status : "recieve" + } + ]); + return; }; diff --git a/src/graphql/connectors/connectors.js b/src/graphql/connectors/connectors.js index 1538d86..8f89867 100644 --- a/src/graphql/connectors/connectors.js +++ b/src/graphql/connectors/connectors.js @@ -433,7 +433,7 @@ export async function allVisibleAnnouncements(user){ } export async function recievedPrivatePosts(user, groupUID){ - let result = await knex('private_post').select() + let result = await knex('private_posts').select() .where('recipient_uid', groupUID); for(element of result){ element.type = 'PrivatePost'; @@ -442,7 +442,7 @@ export async function recievedPrivatePosts(user, groupUID){ } export async function receivedQuestions(user, groupUID){ - let result = await knex().select().from('question') + let result = await knex().select().from('questions') .where('recipient_uid', groupUID); for(element of result){ element.type = 'Question'; @@ -451,7 +451,7 @@ export async function receivedQuestions(user, groupUID){ } export async function recievedAnswers(user, groupUID){ - let result = await knex().select().from('answer') + let result = await knex().select().from('answers') .where('recipient_uid', groupUID); for(element of result){ element.type = 'Answer'; -- GitLab