Squash Tomato Journal — November 24, 2017–01:00

Chris Johnson
The Squash and the Tomato
2 min readNov 25, 2017
  1. Commented out all list controller and client-side code.
  2. Was worried about checking for permissions on each list controller method, which could run 100x before a reload (methods handle API request to do things such as add items to a list, update the total, and delete an item), and decided to create a global variable. This variable would be declared as null, but on each API call, the respected list controller method returns the permission variable and sets the global variable using the return permission variable.
  3. Modified the list controller add method (handles an API call by the client-side add function) to accept a permissions variable. If the variable is defined when passed to the controller, the controller skips checking for permissions and checks if the variable is equal to ‘OWNER’ or ‘EDIT,’ and if so, performs the main function of the controller method. If the variable is not defined when passed to the controller, the controller searched the list for the user and returns their permissions followed be performing the main function of the controller if permissed.
  4. Fixed a bug with URLs having a space in them — I was originally creating unique URLs for lists by using the username, last four of their ID, and the name of the list, but if the name of the list contained a space, such as ‘Banana Farts,’ the URL would be broken… I used .split(‘ ‘).join(‘_’) to create the list url. (picture below)
  5. Refactored the pug files for individual list rendering and client-side JavaScript to properly display the list helper (Qty | Name | Value).
  6. Refactored the way my add controller method works — I wrote the permission checking + main function into a separate function. (picture below)
  7. Finished converting the list controller clear method to the new format set by the add controller method (#6).
#4 — Creating a new list
#6 — Refactored controller to be reusable and more readable
#7 — refactored clearList to follow addItem

--

--

Chris Johnson
The Squash and the Tomato

Full-stack Surgeon (Design, Vue, Node, mongoDB), knowledge seeker, world dominator, Harry Potter and anime addict, volleyball player, and unfiltered.