-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
53 additions
and
66 deletions.
There are no files selected for viewing
43 changes: 20 additions & 23 deletions
43
src/module-system/a-captcha/backend/src/bean/middleware.captchaVerify.js
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
17 changes: 7 additions & 10 deletions
17
src/module-system/a-instance/backend/src/bean/middleware.appReady.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,10 @@ | ||
module.exports = ctx => { | ||
class Middleware { | ||
async execute(options, next) { | ||
// check appReady | ||
if (!ctx.innerAccess) { | ||
await ctx.bean.instance.checkAppReady(); | ||
} | ||
// next | ||
await next(); | ||
module.exports = class Middleware { | ||
async execute(options, next) { | ||
// check appReady | ||
if (!this.ctx.innerAccess) { | ||
await this.ctx.bean.instance.checkAppReady(); | ||
} | ||
// next | ||
await next(); | ||
} | ||
return Middleware; | ||
}; |
16 changes: 6 additions & 10 deletions
16
src/module-system/a-instance/backend/src/bean/middleware.instance.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
module.exports = ctx => { | ||
// const moduleInfo = module.info; | ||
class Middleware { | ||
async execute(options, next) { | ||
// init instance | ||
await ctx.bean.instance.initInstance(); | ||
// next | ||
await next(); | ||
} | ||
module.exports = class Middleware { | ||
async execute(options, next) { | ||
// init instance | ||
await this.ctx.bean.instance.initInstance(); | ||
// next | ||
await next(); | ||
} | ||
return Middleware; | ||
}; |
43 changes: 20 additions & 23 deletions
43
src/module-system/a-validation/backend/src/bean/middleware.validate.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,25 @@ | ||
// request.body | ||
// validate: module(optional), validator, schema(optional) | ||
// data: | ||
module.exports = ctx => { | ||
const moduleInfo = module.info; | ||
class Middleware { | ||
async execute(options, next) { | ||
// must exists | ||
const validator = options.validator; | ||
if (!validator) ctx.throw.module(moduleInfo.relativeName, 1001); | ||
// params | ||
const module = options.module || ctx.module.info.relativeName; | ||
const schema = options.schema || (ctx.meta._validator && ctx.meta._validator.schema); | ||
const data = ctx.request.body[options.data || 'data']; | ||
// if error throw 422 | ||
await ctx.bean.validation.validate({ | ||
module, | ||
validator, | ||
schema, | ||
data, | ||
filterOptions: true, | ||
}); | ||
// next | ||
await next(); | ||
} | ||
const moduleInfo = module.info; | ||
module.exports = class Middleware { | ||
async execute(options, next) { | ||
// must exists | ||
const validator = options.validator; | ||
if (!validator) this.ctx.throw.module(moduleInfo.relativeName, 1001); | ||
// params | ||
const module = options.module || this.ctx.module.info.relativeName; | ||
const schema = options.schema || (this.ctx.meta._validator && this.ctx.meta._validator.schema); | ||
const data = this.ctx.request.body[options.data || 'data']; | ||
// if error throw 422 | ||
await this.ctx.bean.validation.validate({ | ||
module, | ||
validator, | ||
schema, | ||
data, | ||
filterOptions: true, | ||
}); | ||
// next | ||
await next(); | ||
} | ||
return Middleware; | ||
}; |