diff --git a/db/migrations/20180413024152_new_group_message_relations.js b/db/migrations/20180413024152_new_group_message_relations.js new file mode 100644 index 0000000000000000000000000000000000000000..28c50374cd898bda5dd45ec196224e02510712bf --- /dev/null +++ b/db/migrations/20180413024152_new_group_message_relations.js @@ -0,0 +1,25 @@ + +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', 'recieve', 'internal']); + }); + return knex('group_message_relationships').insert(relations); +}; + +exports.down = async function(knex, Promise) { + let relations = await knex.select().from('group_message_relationships') + .whereIn('status', ['join', 'host', 'publish']); + 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']); + }); + return knex('group_message_relationships').insert(relations); +}; diff --git a/db/seeds/07_make_event.js b/db/seeds/07_make_event.js index d74308778cf02a4c3e2ff1882d8e761106fd3c8a..31c17a350942411c09d6ec8d6e6aa80a6a06262b 100644 --- a/db/seeds/07_make_event.js +++ b/db/seeds/07_make_event.js @@ -2,6 +2,7 @@ exports.seed = async function(knex, Promise) { // Deletes ALL existing entries await knex('events').del() + await knex('group_message_relationships').del() // Inserts seed entries await knex('events').insert([ { @@ -20,7 +21,13 @@ exports.seed = async function(knex, Promise) { message : 42, group : 'br', status : 'host' + }, + { + message : 42, + group : 'kes', + status : 'recieve' } + ]); }; diff --git a/src/graphql/connectors/connectors.js b/src/graphql/connectors/connectors.js index 80e4c8e6d7e82f61a47b64a166877a09cfadba11..432fc9cac79c0ccaec7e75d5cd61564eb588e375 100644 --- a/src/graphql/connectors/connectors.js +++ b/src/graphql/connectors/connectors.js @@ -400,7 +400,17 @@ export async function getMessageAuthor(user, messageID){ } export async function getMessageRecipient(user, messageID){ + let GroupReciepients = await getGroupsFromCallbacks(user, qb => { + return qb.select({uid: 'group'}).from('group_message_relationships') + .where('message', messageID).where('status', 'recieve') + }) + let recipientObject = Object() + if(GroupReciepients.length == 1) + recipientObject.singleGroup = GroupReciepients[0] + else + authorObject.multipleGroups = GroupReciepients + return recipientObject } /** diff --git a/src/graphql/resolvers.js b/src/graphql/resolvers.js index 5ce33b5f443b3fa23e9421caec2b3db1b66675d3..310a738e50e07b10b266268bf4b7b763343a44e5 100644 --- a/src/graphql/resolvers.js +++ b/src/graphql/resolvers.js @@ -113,7 +113,7 @@ export const resolvers = { }, test: async function(obj, args, context){ - return connectors.getSimpleGroup(context.user, "br") + return connectors.getSimpleGroup(context.user, "br"); } }, @@ -219,11 +219,11 @@ export const resolvers = { }, authors: async function (obj, args, context){ - return connectors.getMessageAuthor(context.user, obj.id) + return connectors.getMessageAuthor(context.user, obj.id); }, recipient: async function (obj, args, context){ - return connectors.getMessageRecipient(context.user, obj.id) + return connectors.getMessageRecipient(context.user, obj.id); } }, @@ -247,11 +247,11 @@ export const resolvers = { }, authors: async function (obj, args, context){ - return connectors.getMessageAuthor(context.user, obj.id) + return connectors.getMessageAuthor(context.user, obj.id); }, recipient: async function (obj, args, context){ - return connectors.getMessageRecipient(context.user, obj.id) + return connectors.getMessageRecipient(context.user, obj.id); } },