Skip to content

Commit

Permalink
Use object destructuring
Browse files Browse the repository at this point in the history
  • Loading branch information
paulrobertlloyd committed Dec 15, 2023
1 parent 43d07ee commit 2960010
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,42 @@ const utils = require('./lib/utils.js')
* @returns {Object} Next and back paths
*/
const wizard = (journey, req) => {
const { data } = req.session
const { method, path, session } = req
const { data } = session
const paths = Object.keys(journey)
const currentPath = req.path
const query = utils.getOriginalQuery(req)
const index = paths.indexOf(currentPath)
const index = paths.indexOf(path)
let fork
let next
let back

if (index !== -1) {
fork = utils.getFork(journey[currentPath], req)
fork = utils.getFork(journey[path], req)
next = fork || paths[index + 1] || ''
back = paths[index - 1] || ''
}

// Point back to where we forked from
if (currentPath === data['forked-to']) {
if (path === data['forked-to']) {
back = data['forked-from']
}

// Remove the saved fork if we return to it
if (currentPath === data['forked-from'] && req.method === 'GET') {
if (path === data['forked-from'] && method === 'GET') {
delete data['forked-from']
delete data['forked-to']
}

// Add a new fork
if (fork && req.method === 'POST') {
data['forked-from'] = currentPath
if (fork && method === 'POST') {
data['forked-from'] = path
data['forked-to'] = fork
}

return {
next: next && next + query,
back: back && back + query,
current: currentPath + query
current: path + query
}
}

Expand Down

0 comments on commit 2960010

Please sign in to comment.