diff --git a/db/migrations/20180530182824_drop_reciepient_column.js b/db/migrations/20180530182824_drop_reciepient_column.js new file mode 100644 index 0000000000000000000000000000000000000000..90a48e9ae803a33ee89180fb4aa98b3b9b9f1f90 --- /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 1979d205e658ed0247822418667041cf07567044..5aad98ab84dd3098b69fc706ce20ec9709a85c63 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 1538d86380f9497e813f3538838dcf9d62c9d132..8f89867e21728d8ebedf4bd0cfac3b060c94d8af 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';