Skip to content

Instantly share code, notes, and snippets.

@timwis
Last active September 24, 2016 20:44
Show Gist options
  • Save timwis/f6eaabacdca2e6a39c7633fc57b14642 to your computer and use it in GitHub Desktop.
Save timwis/f6eaabacdca2e6a39c7633fc57b14642 to your computer and use it in GitHub Desktop.
/* 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