Skip to content

Commit 8d0ff0b

Browse files
authored
Merge pull request #17 from danielsous/main
fix(authorize): waiting for return of authorization from useCase before executing it
2 parents ded63bc + 701ded2 commit 8d0ff0b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/repl.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ async function list(usecases, groupBy) {
88

99
let ucs = usecases.map((uc) => {
1010
return {
11-
name: uc.tags[groupBy] + ' - ' + uc.usecase.description,
11+
name: uc.tags[groupBy] + ' - ' + uc.usecase().description,
1212
value: uc.usecase
1313
}
1414
})
@@ -58,7 +58,8 @@ function printDoc(uc) {
5858
}
5959
}
6060

61-
const doc = uc.doc()
61+
const usecase = uc()
62+
const doc = usecase.doc()
6263
const style = chalk.blue.underline
6364
console.log(`\n${style(doc.description)} use case will execute the following steps:`)
6465
for (const step of doc.steps) { printStep(step) }
@@ -68,7 +69,8 @@ async function execute(usecase, user) {
6869

6970
console.log(`\nInform the parameters for the use case execution`)
7071

71-
const params = usecase.requestSchema
72+
const uc = usecase()
73+
const params = uc.requestSchema
7274

7375
const questions = []
7476
for (const param of Object.entries(params)) {
@@ -91,10 +93,10 @@ async function execute(usecase, user) {
9193
console.log(chalk`\n{whiteBright.bold Params:}`)
9294
console.log(chalk.blue(JSON.stringify(answers, null, ' ')))
9395

94-
const hasAccess = usecase.authorize(user)
96+
const hasAccess = await uc.authorize(user)
9597
if (!hasAccess) return console.log(chalk`\n{redBright.bold Access denied}`)
9698

97-
const result = await usecase.run(answers)
99+
const result = await uc.run(answers)
98100
console.log(chalk`\n{whiteBright.bold Result:}`)
99101

100102
let style = result.isOk ? chalk.green : chalk.red

0 commit comments

Comments
 (0)