forked from StateVoicesNational/Spoke
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from lperson/conversations-query
Conversations query
- Loading branch information
Showing
4 changed files
with
192 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import _ from 'lodash' | ||
import User from '../models/user' | ||
import CampaignContact from '../models/campaign-contact' | ||
|
||
export const schema = ` | ||
input ConversationFilter { | ||
assignmentsFilter: AssignmentsFilter | ||
campaignsFilter: CampaignsFilter | ||
contactsFilter: ContactsFilter | ||
} | ||
type Conversation { | ||
texter: User! | ||
contact: CampaignContact! | ||
campaign: Campaign! | ||
assignment: Assignment | ||
} | ||
` | ||
|
||
function coerceQueryFieldsToResolverFields(instance, fieldsToRemove) { | ||
const fields = _.remove(Object.keys(instance), el => { | ||
return !(fieldsToRemove.includes(el)) | ||
}) | ||
return _.pick(instance, fields) | ||
} | ||
|
||
export const resolvers = { | ||
Conversation: { | ||
texter: instance => { | ||
const texterFields = coerceQueryFieldsToResolverFields(instance, [ | ||
'u_id', | ||
'u_first_name', | ||
'u_last_name' | ||
]) | ||
texterFields.id = instance.u_id | ||
texterFields.last_name = instance.u_first_name | ||
texterFields.first_name = instance.u_last_name | ||
return texterFields | ||
}, | ||
contact: instance => { | ||
const contactFields = coerceQueryFieldsToResolverFields(instance, [ | ||
'cc_id', | ||
'cc_first_name', | ||
'cc_last_name' | ||
]) | ||
contactFields.id = instance.cc_id | ||
contactFields.first_name = instance.cc_first_name | ||
contactFields.last_name = instance.cc_last_name | ||
return contactFields | ||
}, | ||
campaign: instance => { | ||
const campaignFields = coerceQueryFieldsToResolverFields(instance, ['cmp_id']) | ||
campaignFields.id = instance.cmp_id | ||
return campaignFields | ||
}, | ||
assignment: instance => { | ||
const assignmentFields = coerceQueryFieldsToResolverFields(instance, ['ass_id']) | ||
assignmentFields.id = instance.ass_id | ||
return assignmentFields | ||
} | ||
} | ||
} |
Oops, something went wrong.