Skip to content
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

Merged
merged 4 commits into from
Sep 24, 2019

Conversation

physik932
Copy link
Collaborator

user_fields and organization_fields work a bit differently than custom_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.

@physik932 physik932 added documentation Improvements or additions to documentation review me labels Sep 23, 2019
@@ -106,9 +78,14 @@ async function getContext() {
let { ticket } = await client.get('ticket');
const ticketFields = await client.request(getTicketData(ticket.id));

if (ticket.organization) {
Copy link
Collaborator Author

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;
});
}
*/
Copy link
Collaborator Author

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) {
Copy link
Collaborator Author

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));
Copy link
Collaborator Author

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) {
Copy link
Collaborator Author

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.

Copy link

@Cavallando Cavallando left a 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 🙇

@physik932 physik932 merged commit 1bd166b into feature/SHOP-9313/scaffold Sep 24, 2019
@physik932 physik932 deleted the docs-and-fields branch September 24, 2019 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation review me
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants