-
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
Conversation
@@ -106,9 +78,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 comment
The 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 organization_fields
object. Furthermore, our User objects and Ticket object do not have organization data. I'm not sure why, or how this gets assigned. Either way, to protect ourselves from this, I have a null check for ticket.organization
before trying to get the organization fields.
return org.id = context.ticket.requester.organization_id; | ||
}); | ||
} | ||
*/ |
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.
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.
}; | ||
} | ||
|
||
/** | ||
* 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 comment
The reason will be displayed to describe this comment to others. Learn more.
async
in an async
doesn't read great. I wonder if we should pull buildContext
out and place it above, like the processUserObject
function. Although only the getContext
function uses them, it might help readability.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Destructuring a nested object.
* | ||
* @param {Object} user - A Zendesk User Object | ||
*/ | ||
export function parseFirstLastName(user) { |
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.
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.
Sweeet, doing the lord's work 🙇
user_fields
andorganization_fields
work a bit differently thancustom_fields
. To get the fields, I added two API calls to get the fields and destructure them into their appropriate objects.I also camelCased the currentUser, firstName and lastName fields in the documentation.