doomiwork 3.3.3 → 3.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -63,9 +63,9 @@ class controller {
63
63
  * @param {*} req
64
64
  * @param {*} res
65
65
  */
66
- createCRUDRoute(actionType,url,datakey){
66
+ createCRUDRoute(actionType,url,datakey,middleware){
67
67
  let instance = this;
68
- instance.router[actionType.method](url,async (req,res)=>{
68
+ instance.router[actionType.method](url, middleware ? middleware : (req, res, next)=>{return next()},async (req,res)=>{
69
69
  ////执行CRUD之前,可由继承的子类实现规则验证
70
70
  ////如果返回successed:false,则不再继续
71
71
  let beforeResult = await instance.beforeCRUD(actionType,req,res)
@@ -91,14 +91,14 @@ class controller {
91
91
  * @param {*} datakey 对应在dataconfig.json中的key,方便实体和传递的数据的映射以及SQL
92
92
  * @param {*} action 操作的组合 CRUDS
93
93
  */
94
- initializeCRUDRouter(url,datakey,action='SCRUD'){
94
+ initializeCRUDRouter(url, datakey, action = 'SCRUD', middleware){
95
95
  if(!url || !datakey) return;
96
96
  let urlWithId = stringHelper.endsWith(url,'/')?`${url}:id`:`${url}/:id`;
97
- if(action.indexOf('C')>=0) this.createCRUDRoute(constEnum.CRUDAction.Create,url,datakey)
98
- if(action.indexOf('S')>=0) this.createCRUDRoute(constEnum.CRUDAction.Single,urlWithId,datakey)
99
- if(action.indexOf('R')>=0) this.createCRUDRoute(constEnum.CRUDAction.Retrieve,url,datakey)
100
- if(action.indexOf('U')>=0) this.createCRUDRoute(constEnum.CRUDAction.Update,urlWithId,datakey)
101
- if(action.indexOf('D')>=0) this.createCRUDRoute(constEnum.CRUDAction.Delete,urlWithId,datakey)
97
+ if (action.indexOf('C') >= 0) this.createCRUDRoute(constEnum.CRUDAction.Create, url, datakey, middleware)
98
+ if (action.indexOf('S') >= 0) this.createCRUDRoute(constEnum.CRUDAction.Single, urlWithId, datakey, middleware)
99
+ if (action.indexOf('R') >= 0) this.createCRUDRoute(constEnum.CRUDAction.Retrieve, url, datakey, middleware)
100
+ if (action.indexOf('U') >= 0) this.createCRUDRoute(constEnum.CRUDAction.Update, urlWithId, datakey, middleware)
101
+ if (action.indexOf('D') >= 0) this.createCRUDRoute(constEnum.CRUDAction.Delete, urlWithId, datakey, middleware)
102
102
  }
103
103
  /**
104
104
  * CRUD真正进入数据库之前的处理,可由继承的类来处理
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doomiwork",
3
- "version": "3.3.3",
3
+ "version": "3.4.0",
4
4
  "description": "doomisoft nodejs web framework",
5
5
  "main": "index.js",
6
6
  "scripts": {