Created
January 15, 2019 06:47
-
-
Save Restuta/c2554cd5bb40d56ba20d22e207db45f8 to your computer and use it in GitHub Desktop.
App Flow Proto 2
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
// step module | |
const applyUpdates = () => {}; | |
const updateStepBody = useDb => (stepBody, updates) => { | |
const updatedBody = applyUpdates(stepBody, updates); | |
useDb(transaction => { | |
createHistoryRecord(updatedBody, updates); | |
}); | |
return updatedBody; | |
}; | |
const createStep = (appLevelDeps, stepLevelDeps) => {}; | |
const stepFactory = ({ stepBody, dbTransactionDidCommit, useDb }) => | |
createStep({ stepBody, dbTransactionDidCommit, useDb }, { hubspot, log, worker }); | |
const createSoftCreditCheckStep => ({ | |
createStepInDb, | |
transaction | |
}) | |
// const stepFactory = ({ stepBody, dbTransactionDidCommit, useDb }) => ({ | |
// log, | |
// hubstpot, | |
// worker, | |
// }) => { | |
// return { | |
// updateStepAsUser(updates, user) {}, | |
// }; | |
// }; | |
// application module | |
const effectsContainer = (effects = []) => ({ | |
getAll() { | |
return effects; | |
}, | |
add(effect) { | |
effects.push(effect); | |
return; | |
}, | |
}); | |
const createApplication = ({ log, sequelize }) => ({ | |
async updateStep(stepId, updates, user) { | |
const dbOperations = effectsContainer(); | |
const transactionDidCommitOperations = effectsContainer(); | |
const createNewStepInDb = (...args) => { | |
dbOperations.add(transaction => Steps.create(transaction, ...args)); | |
}; | |
const createStep = getStepFactory(stepType); | |
const step = createStep({ | |
stepBody, | |
dbTransactionDidCommit: transactionDidCommitOperations.add, | |
useDb: dbOperations.add, | |
}); | |
const results = currentUser.isAdmin | |
? step.updateStepAsUser(updates, currentUser) | |
: step.updateStepAsAdmin(updates, currentUser); | |
// start transaction | |
sequelize.startTransaction(async transaction => { | |
const stepsToCreate = results.stepsTOCreate; | |
// create those steps ^ | |
// run all db operations | |
await Promise.all(dbOperations.getAll().map(dbOperation => dbOperation(transaction))); | |
}); | |
// assuming transaction commited | |
await Promise.all(transactionDidCommitOperations.getAll().map(x => x())); | |
}, | |
}); | |
const createNewApplicationForUser = userId => { | |
// application object + steps | |
}; | |
// application.updateStep(stepId, updates, user) | |
// application. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment