Last active
September 24, 2016 20:44
-
-
Save timwis/f6eaabacdca2e6a39c7633fc57b14642 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* global setState, sendVerificationEmail, sendApprovalEmail, sendRejectNotification, isValidKey */ | |
const supervisors = [ | |
'john.doe@co.com', | |
'jane.doe@co.com' | |
] | |
module.exports = { | |
name: 'Travel Request', | |
states: [ | |
{ | |
name: 'Not started', | |
actions: { | |
initiate: { | |
template: () => {}, | |
handler: (data) => { | |
if (!data.initiatorEmail) return false | |
// create case here? | |
sendVerificationEmail(data.initiatorEmail) // generate key? | |
} | |
}, | |
verify: { | |
template: () => {}, | |
handler: (data) => { | |
if (!isValidKey(data.caseId, data.key)) return false | |
if (!supervisors.includes(data.supervisorEmail)) return false | |
sendApprovalEmail(data.supervisorEmail) | |
setState('Awaiting Supervisor Approval') | |
} | |
} | |
} | |
}, | |
{ | |
name: 'Awaiting Supervisor Approval', | |
actions: { | |
supervisorApproves: { | |
template: () => {}, | |
handler: (data) => { | |
sendApprovalEmail(data.directorEmail) | |
setState('Awaiting Director Approval') | |
} | |
}, | |
supervisorRejects: { | |
template: () => {}, | |
handler: (data) => { | |
sendRejectNotification(data.initiatorEmail) | |
setState('Rejected') | |
} | |
} | |
} | |
}, | |
{ | |
name: 'Awaiting Director Approval', | |
actions: { | |
directorApproves: { | |
template: () => {}, | |
handler: (data) => { | |
sendApprovalEmail(data.directorEmail) | |
setState('Awaiting Director Approval') | |
} | |
}, | |
directorRejects: { | |
template: () => {}, | |
handler: (data) => { | |
sendRejectNotification(data.initiatorEmail) | |
setState('Rejected') | |
} | |
} | |
} | |
}, | |
{ | |
name: 'Awaiting Indebtedness Clearances', | |
actions: { | |
pwdApproves: { | |
template: () => {}, | |
handler: (data, history) => { | |
if (history.events.includes(['pwdApproves', 'taxesApproves', 'baaApproves'])) { | |
sendApprovalEmail(data.directorEmail) | |
setState('Awaiting Director Approval') | |
} | |
} | |
}, | |
taxesApproves: { | |
template: () => {}, | |
handler: (data, history) => { | |
if (history.events.includes(['pwdApproves', 'taxesApproves', 'baaApproves'])) { | |
sendApprovalEmail(data.directorEmail) | |
setState('Awaiting Director Approval') | |
} | |
} | |
}, | |
baaApproves: { | |
template: () => {}, | |
handler: (data) => { | |
sendApprovalEmail(data.directorEmail) | |
setState('Awaiting Director Approval') | |
} | |
}, | |
directorRejects: { | |
template: () => {}, | |
handler: (data) => { | |
sendRejectNotification(data.initiatorEmail) | |
setState('Rejected') | |
} | |
} | |
} | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment