Skip to content

Commit

Permalink
Merge pull request #190 from herbsjs/revert-188-feat/update-herbs-and…
Browse files Browse the repository at this point in the history
…-glues-version

Revert "Updated version of herbsjs and glues"
  • Loading branch information
dalssoft authored May 2, 2023
2 parents 150aec6 + ae267ce commit 33b9f1e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 33 deletions.
20 changes: 10 additions & 10 deletions src/generators/src/packagejson.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const { objToString } = require('../utils')

const optionalPackages = {
mongo: ['"@herbsjs/herbs2mongo": "^4.0.0"', '"mongodb": "^4.8.1"'],
postgres: ['"@herbsjs/herbs2knex": "^2.1.1"', '"pg": "^8.7.3"'],
sqlite: ['"@herbsjs/herbs2knex": "^2.1.1"', '"sqlite3": "^5.0.11"'],
sqlserver: ['"@herbsjs/herbs2knex": "^2.1.1"', '"tedious": "^15.1.0"', '"mssql": "^9.0.1"'],
mysql: ['"@herbsjs/herbs2knex": "^2.1.1"', '"mysql2": "^2.3.3"'],
rest: ['"express": "^4.18.1"', '"cors": "^2.8.5"', '"@herbsjs/herbs2rest": "^4.1.1"'],
graphql: ['"graphql": "^16.5.0"', '"@herbsjs/herbs2gql": "^3.0.0"', '"apollo-server": "^3.8.2"','"apollo-server-express": "^3.8.2"', '"graphql-tools": "^8.2.12"', '"graphql-scalars": "^1.17.0"',]
mongo: ['"@herbsjs/herbs2mongo": "^3.0.3"', '"mongodb": "^4.8.1"'],
postgres: ['"@herbsjs/herbs2knex": "^1.5.7"', '"pg": "^8.7.3"'],
sqlite: ['"@herbsjs/herbs2knex": "^1.5.7"', '"sqlite3": "^5.0.11"'],
sqlserver: ['"@herbsjs/herbs2knex": "^1.5.7"', '"tedious": "^15.1.0"', '"mssql": "^9.0.1"'],
mysql: ['"@herbsjs/herbs2knex": "^1.5.7"', '"mysql2": "^2.3.3"'],
rest: ['"express": "^4.18.1"', '"cors": "^2.8.5"', '"@herbsjs/herbs2rest": "^3.2.1"'],
graphql: ['"graphql": "^16.5.0"', '"@herbsjs/herbs2gql": "^2.3.0"', '"apollo-server": "^3.8.2"','"apollo-server-express": "^3.8.2"', '"graphql-tools": "^8.2.12"', '"graphql-scalars": "^1.17.0"',]
}

const defaultOptions = (options) => {
Expand Down Expand Up @@ -46,9 +46,9 @@ module.exports =
: ''

let packages = [
'"@herbsjs/herbs": "^2.0.0"',
'"@herbsjs/herbarium": "^1.5.0"',
'"@herbsjs/herbsshelf": "^5.0.1"',
'"@herbsjs/herbs": "^1.6.2"',
'"@herbsjs/herbarium": "^1.4.0"',
'"@herbsjs/herbsshelf": "^4.0.1"',
'"dotenv": "^16.0.1"',
'"deepmerge": "^4.2.2"',
'"nodemon": "^2.0.19"',
Expand Down
15 changes: 6 additions & 9 deletions src/templates/domain/useCases/create.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,18 @@ const create<%- props.name.pascalCase %> = injection =>
// authorize: (user) => (user.canCreate<%- props.name.pascalCase %> ? Ok() : Err()),
authorize: () => Ok(),

setup: ctx => {
ctx.di = Object.assign({}, dependency, injection)
ctx.data = {}
},
setup: ctx => (ctx.di = Object.assign({}, dependency, injection)),

//Step description and function
'Check if the <%- props.name.raw %> is valid': step(ctx => {
ctx.data.<%- props.name.camelCase %> = <%- props.name.pascalCase %>.fromJSON(ctx.req)
<% if(!props.mongo){ %>ctx.data.<%- props.name.camelCase %>.id = Math.floor(Math.random() * 100000).toString()<% } %>
ctx.<%- props.name.camelCase %> = <%- props.name.pascalCase %>.fromJSON(ctx.req)
<% if(!props.mongo){ %>ctx.<%- props.name.camelCase %>.id = Math.floor(Math.random() * 100000).toString()<% } %>

if (!ctx.data.<%- props.name.camelCase %>.isValid())
if (!ctx.<%- props.name.camelCase %>.isValid())
return Err.invalidEntity({
message: 'The <%- props.name.raw %> entity is invalid',
payload: { entity: '<%- props.name.raw %>' },
cause: ctx.data.<%- props.name.camelCase %>.errors
cause: ctx.<%- props.name.camelCase %>.errors
})

// returning Ok continues to the next step. Err stops the use case execution.
Expand All @@ -40,7 +37,7 @@ const create<%- props.name.pascalCase %> = injection =>

'Save the <%- props.name.raw %>': step(async ctx => {
const repo = new ctx.di.<%- props.name.pascalCase %>Repository(injection)
const <%- props.name.camelCase %> = ctx.data.<%- props.name.camelCase %>
const <%- props.name.camelCase %> = ctx.<%- props.name.camelCase %>
// ctx.ret is the return value of a use case
return (ctx.ret = await repo.insert(<%- props.name.camelCase %>))
})
Expand Down
9 changes: 3 additions & 6 deletions src/templates/domain/useCases/delete.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@ const delete<%- props.name.pascalCase %> = injection =>
// authorize: (user) => (user.canDelete<%- props.name.pascalCase %> ? Ok() : Err()),
authorize: () => Ok(),

setup: ctx => {
ctx.di = Object.assign({}, dependency, injection)
ctx.data = {}
},
setup: ctx => (ctx.di = Object.assign({}, dependency, injection)),

'Check if the <%- props.name.pascalCase %> exist': step(async ctx => {
const repo = new ctx.di.<%- props.name.pascalCase %>Repository(injection)
const [<%- props.name.camelCase %>] = await repo.findByID(ctx.req.id)
ctx.data.<%- props.name.camelCase %> = <%- props.name.camelCase %>
ctx.<%- props.name.camelCase %> = <%- props.name.camelCase %>

if (<%- props.name.camelCase %>) return Ok()
return Err.notFound({
Expand All @@ -38,7 +35,7 @@ const delete<%- props.name.pascalCase %> = injection =>

'Delete the <%- props.name.pascalCase %>': step(async ctx => {
const repo = new ctx.di.<%- props.name.pascalCase %>Repository(injection)
ctx.ret = await repo.delete(ctx.data.<%- props.name.camelCase %>)
ctx.ret = await repo.delete(ctx.<%- props.name.camelCase %>)
// ctx.ret is the return value of a use case
return Ok(ctx.ret)
})
Expand Down
13 changes: 5 additions & 8 deletions src/templates/domain/useCases/update.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@ const update<%- props.name.pascalCase %> = injection =>
// authorize: (user) => (user.canUpdate<%- props.name.pascalCase %> ? Ok() : Err()),
authorize: () => Ok(),

setup: ctx => {
ctx.di = Object.assign({}, dependency, injection)
ctx.data = {}
},
setup: ctx => (ctx.di = Object.assign({}, dependency, injection)),

'Retrieve the <%- props.name.raw %>': step(async ctx => {
const id = ctx.req.id
const repo = new ctx.di.<%- props.name.pascalCase %>Repository(injection)
const [<%- props.name.camelCase %>] = await repo.findByID(id)
ctx.data.<%- props.name.camelCase %> = <%- props.name.camelCase %>
ctx.<%- props.name.camelCase %> = <%- props.name.camelCase %>
if (<%- props.name.camelCase %> === undefined) return Err.notFound({
message: `<%- props.name.pascalCase %> not found - ID: ${id}`,
payload: { entity: '<%- props.name.raw %>' }
Expand All @@ -37,9 +34,9 @@ const update<%- props.name.pascalCase %> = injection =>
}),

'Check if it is a valid <%- props.name.raw %> before update': step(ctx => {
const old<%- props.name.pascalCase %> = ctx.data.<%- props.name.camelCase %>
const old<%- props.name.pascalCase %> = ctx.<%- props.name.camelCase %>
const new<%- props.name.pascalCase %> = <%- props.name.pascalCase %>.fromJSON(merge.all([ old<%- props.name.pascalCase %>, ctx.req ]))
ctx.data.<%- props.name.camelCase %> = new<%- props.name.pascalCase %>
ctx.<%- props.name.camelCase %> = new<%- props.name.pascalCase %>

return new<%- props.name.pascalCase %>.isValid() ? Ok() : Err.invalidEntity({
message: `<%- props.name.pascalCase %> is invalid`,
Expand All @@ -52,7 +49,7 @@ const update<%- props.name.pascalCase %> = injection =>
'Update the <%- props.name.pascalCase %>': step(async ctx => {
const repo = new ctx.di.<%- props.name.pascalCase %>Repository(injection)
// ctx.ret is the return value of a use case
return (ctx.ret = await repo.update(ctx.data.<%- props.name.camelCase %>))
return (ctx.ret = await repo.update(ctx.<%- props.name.camelCase %>))
})

})
Expand Down

0 comments on commit 33b9f1e

Please sign in to comment.