-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update Documentation and fix User and Org Fields #6
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,10 @@ | ||
import client from '../lib/client'; | ||
import { getTicketData } from "../lib/api"; | ||
import { getUserData } from "../lib/api"; | ||
import { getOrganizationData } from "../lib/api"; | ||
|
||
const TEMPLATE_OPTIONS = { interpolate: /\{\{(.+?)\}\}/g }; | ||
|
||
/** | ||
* Parses a Zendesk users first and last name | ||
* from their Full name | ||
* | ||
* TODO: Docz | ||
* | ||
* @param {Object} user - A Zendesk User Object | ||
*/ | ||
export function parseFirstLastName(user) { | ||
const [first_name = '', last_name = ''] = (user.name || '').split(' '); | ||
|
||
return { | ||
...user, | ||
first_name, | ||
last_name, | ||
}; | ||
} | ||
|
||
/** | ||
* TODO: JS DOcs | ||
* @param {*} settings - blah | ||
|
@@ -36,7 +20,7 @@ export function getUrisFromSettings({ uri_templates }) { | |
*/ | ||
export function buildTemplatesFromContext(uris, context) { | ||
return _.map(uris, uri => { | ||
mike.url = _.template(uri.url, TEMPLATE_OPTIONS)(context) | ||
uri.url = _.template(uri.url, TEMPLATE_OPTIONS)(context) | ||
uri.title = _.template(uri.title, TEMPLATE_OPTIONS)(context) | ||
|
||
return uri; | ||
|
@@ -58,46 +42,38 @@ function assignTicketFields(ticket, ticketFields) { | |
} | ||
|
||
/** | ||
* TODO: JS DOcs | ||
* TODO: JS Docs | ||
* @param {*} user | ||
*/ | ||
function parseFirstLastName(user) { | ||
const [first_name = '', last_name = ''] = (user.name || '').split(' '); | ||
async function processUserObject(user) { | ||
const [firstName = '', lastName = ''] = (user.name || '').split(' '); | ||
const { user: {user_fields}} = await client.request(getUserData(user.id)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Destructuring a nested object. |
||
|
||
return { | ||
...user, | ||
first_name, | ||
last_name, | ||
firstName, | ||
lastName, | ||
user_fields | ||
}; | ||
} | ||
|
||
/** | ||
* TODO: JS DOcs | ||
*/ | ||
async function getContext() { | ||
function buildContext(ticket, currentUser) { | ||
async function buildContext(ticket, currentUser) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
let context = {}; | ||
context.ticket = ticket; | ||
|
||
if (ticket.requester.id) { | ||
context.ticket.requester = parseFirstLastName(ticket.requester); | ||
|
||
/* | ||
// TODO: Look into organizations | ||
// this should be ticket.requester.organization_id | ||
if (context.ticket.requester.organization_id) { | ||
context.ticket.organization = _.find(data.organizations, org => { | ||
return org.id = context.ticket.requester.organization_id; | ||
}); | ||
} | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Per this issue, I believe the organization fields are referred to incorrectly. The below code refers to the ticket's organization versus one of the requester organizations. |
||
context.ticket.requester = await processUserObject(ticket.requester); | ||
} | ||
|
||
if (ticket.assignee.id) { | ||
context.ticket.assignee.user = parseFirstLastName(ticket.assignee); | ||
if (ticket.assignee.user.id) { | ||
context.ticket.assignee.user = await processUserObject(ticket.assignee.user); | ||
} | ||
|
||
context.current_user = parseFirstLastName(currentUser); | ||
context.currentUser = await processUserObject(currentUser); | ||
|
||
return context; | ||
}; | ||
|
@@ -106,9 +82,14 @@ async function getContext() { | |
let { ticket } = await client.get('ticket'); | ||
const ticketFields = await client.request(getTicketData(ticket.id)); | ||
|
||
if (ticket.organization) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a conundrum. I checked both ZAFCient and Zendesk API for all the organizations, and of the 5 Organization objects returned, none of them had data in the |
||
const { organization } = await client.request(getOrganizationData(ticket.organization.id)); | ||
ticket.organization.organization_fields = organization.organization_fields; | ||
} | ||
|
||
ticket = assignTicketFields(ticket, ticketFields); | ||
|
||
return buildContext(ticket, currentUser) | ||
return await buildContext(ticket, currentUser) | ||
} | ||
|
||
export default getContext; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We had this twice; this one being exported but not used anywhere else.