diff --git a/db/migrations/20180530191430_fix_spelling_recieve.js b/db/migrations/20180530191430_fix_spelling_recieve.js new file mode 100644 index 0000000000000000000000000000000000000000..e816c31d7826661d4eedd1a8f9d52d3872c4e5b2 --- /dev/null +++ b/db/migrations/20180530191430_fix_spelling_recieve.js @@ -0,0 +1,36 @@ + +exports.up = async function(knex, Promise) { + let relations = await knex.select().from('group_message_relationships'); + await knex('group_message_relationships').del(); + await knex.schema.table('group_message_relationships', table => { + table.dropColumn('status'); + }); + await knex.schema.table('group_message_relationships', table => { + table.enum('status', ['join', 'host', 'publish', 'receive', 'internal']); + }); + let entry; + for(entry of relations){ + if(entry.status == "recieve"){ + entry.status = "receive"; + } + } + return knex('group_message_relationships').insert(relations); +}; + +exports.down = async function(knex, Promise) { + let relations = await knex.select().from('group_message_relationships'); + await knex('group_message_relationships').del(); + await knex.schema.table('group_message_relationships', table => { + table.dropColumn('status'); + }); + await knex.schema.table('group_message_relationships', table => { + table.enum('status', ['join', 'host', 'publish', 'recieve', 'internal']); + }); + let entry; + for(entry of relations){ + if(entry.status == "receive"){ + entry.status = "recieve"; + } + } + return knex('group_message_relationships').insert(relations); +}; diff --git a/db/seeds/02_make_posts.js b/db/seeds/02_make_posts.js index 5aad98ab84dd3098b69fc706ce20ec9709a85c63..451fdb600b0c2020a186d82fffd5a06497823b68 100644 --- a/db/seeds/02_make_posts.js +++ b/db/seeds/02_make_posts.js @@ -61,7 +61,7 @@ exports.seed = async function(knex, Promise) { { message : 42, group : 'kes', - status : 'recieve' + status : 'receive' } ]); @@ -96,12 +96,12 @@ exports.seed = async function(knex, Promise) { { message : 4, group : "br", - status : "recieve" + status : "receive" }, { message : 5, group : "faerix", - status : "recieve" + status : "receive" } ]); diff --git a/src/graphql/connectors/connectors.js b/src/graphql/connectors/connectors.js index 8f89867e21728d8ebedf4bd0cfac3b060c94d8af..1c4a6452aec0b7f8ac56cadfc0e81190c31f985f 100644 --- a/src/graphql/connectors/connectors.js +++ b/src/graphql/connectors/connectors.js @@ -432,29 +432,32 @@ export async function allVisibleAnnouncements(user){ return result; } -export async function recievedPrivatePosts(user, groupUID){ - let result = await knex('private_posts').select() - .where('recipient_uid', groupUID); - for(element of result){ - element.type = 'PrivatePost'; +export async function receivedPrivatePosts(user, groupUID){ + let received_messages = await selectors.recievedMessages(user, groupUID); + let result = await knex('private_posts').select().whereIn('id', received_messages); + let entry; + for(entry of result){ + entry.type = "PrivatePost"; } return result; } export async function receivedQuestions(user, groupUID){ - let result = await knex().select().from('questions') - .where('recipient_uid', groupUID); - for(element of result){ - element.type = 'Question'; + let received_messages = await selectors.recievedMessages(user, groupUID); + let result = await knex('questions').select().whereIn('id', received_messages); + let entry; + for(entry of result){ + entry.type = "Question"; } return result; } -export async function recievedAnswers(user, groupUID){ - let result = await knex().select().from('answers') - .where('recipient_uid', groupUID); - for(element of result){ - element.type = 'Answer'; +export async function receivedAnswers(user, groupUID){ + let received_messages = await selectors.recievedMessages(user, groupUID); + let result = await knex('answers').select().whereIn('id', received_messages); + let entry; + for(entry of result){ + entry.type = "Answer"; } return result; } diff --git a/src/graphql/connectors/selectors.js b/src/graphql/connectors/selectors.js index 85c16fb32925941ede3a94bf594f5f08fffc7f1b..65e814d0222838a9b6498a9068a745cce0261bdb 100644 --- a/src/graphql/connectors/selectors.js +++ b/src/graphql/connectors/selectors.js @@ -109,6 +109,21 @@ export async function metaGroupAdminMembers(user, metaGroupUID){ }; } +/** + * @summary Renvoie un callback de tous les messages reçus par le groupe + * @param {Object} user - Utilisateur effectuant la requête. + * @param {String} groupUID - Identifiant du groupe. + * @return {Promise(callback)} a callback to build a query for the admin members of a group + * @author akka vodol + * @rights admin(groupUID) + */ +export async function recievedMessages(user, groupUID){ + return function(qb){ + return qb.column({id : 'message'}).select().from('group_message_relationships').where('group', groupUID).where('status', 'receive'); + } +} + + export async function callbackIntersection(callbackList){ return function(query_builder){ let cb = callbackList.pop(); diff --git a/src/graphql/resolvers.js b/src/graphql/resolvers.js index 7f847f9bb4151feafb8692067327ee64b3ed1248..a2af4000d36a8125497ae69aa959d1477462223c 100644 --- a/src/graphql/resolvers.js +++ b/src/graphql/resolvers.js @@ -338,17 +338,17 @@ export const resolvers = { privatePosts: async function(obj, args, context){ let user = await authentifiers.member(context.user, obj.uid); - return user && connectors.recievedPrivatePosts(user, obj.uid); + return user && connectors.receivedPrivatePosts(user, obj.uid); }, questions: async function(obj, args, context){ let user = await authentifiers.member(context.user, obj.uid); - return user && connectors.recievedQuestions(user, obj.uid); + return user && connectors.receivedQuestions(user, obj.uid); }, answers: async function(obj, args, context){ let user = await authentifiers.member(context.user, obj.uid); - return user && connectors.recievedAnswers(user, obj.uid); + return user && connectors.receivedAnswers(user, obj.uid); } }, @@ -359,17 +359,17 @@ export const resolvers = { privatePosts: async function(obj, args, context){ let user = await authentifiers.member(context.user, obj.uid); - return user && connectors.recievedPrivatePosts(user, obj.uid); + return user && connectors.receivedPrivatePosts(user, obj.uid); }, questions: async function(obj, args, context){ let user = await authentifiers.member(context.user, obj.uid); - return user && connectors.recievedQuestions(user, obj.uid); + return user && connectors.receivedQuestions(user, obj.uid); }, answers: async function(obj, args, context){ let user = await authentifiers.member(context.user, obj.uid); - return user && connectors.recievedAnswers(user, obj.uid); + return user && connectors.receivedAnswers(user, obj.uid); } } };