@azteam/express 1.2.125 → 1.2.126

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azteam/express",
3
- "version": "1.2.125",
3
+ "version": "1.2.126",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "repository": {
@@ -1,8 +1,8 @@
1
- import { NOT_EXISTS } from '@azteam/error';
1
+ import {NOT_EXISTS} from '@azteam/error';
2
2
 
3
- import { REQUEST_TYPE, USER_LEVEL } from './constant';
4
- import { paginateMiddleware, roleMiddleware, validateMiddleware } from './middleware';
5
- import { rulesID } from './validate';
3
+ import {REQUEST_TYPE, USER_LEVEL} from './constant';
4
+ import {paginateMiddleware, roleMiddleware, validateMiddleware} from './middleware';
5
+ import {rulesID} from './validate';
6
6
  import Controller from './Controller';
7
7
 
8
8
 
@@ -29,9 +29,9 @@ class AdminController extends Controller {
29
29
  });
30
30
  }
31
31
 
32
- getPaginate() {
32
+ getPaginatePublic() {
33
33
  return {
34
- path: '/public',
34
+ path: '/',
35
35
  method: [
36
36
  roleMiddleware([this.options.roles.READ], USER_LEVEL.ADMIN),
37
37
  paginateMiddleware(this.options.paginateOptions),
@@ -46,7 +46,7 @@ class AdminController extends Controller {
46
46
 
47
47
  getPaginateTrash() {
48
48
  return {
49
- path: '/trash',
49
+ path: '/',
50
50
  method: [
51
51
  roleMiddleware([this.options.roles.READ], USER_LEVEL.ADMIN),
52
52
  paginateMiddleware(this.options.paginateOptions),
@@ -59,9 +59,9 @@ class AdminController extends Controller {
59
59
  };
60
60
  };
61
61
 
62
- getOne() {
62
+ getOnePubic() {
63
63
  return {
64
- path: '/public/:id',
64
+ path: '/:id',
65
65
  method: [
66
66
  roleMiddleware([this.options.roles.READ], USER_LEVEL.ADMIN),
67
67
  validateMiddleware(REQUEST_TYPE.PARAMS, rulesID),
@@ -77,7 +77,7 @@ class AdminController extends Controller {
77
77
 
78
78
  getOneTrash() {
79
79
  return {
80
- path: '/trash/:id',
80
+ path: '/:id',
81
81
  method: [
82
82
  roleMiddleware([this.options.roles.READ], USER_LEVEL.ADMIN),
83
83
  validateMiddleware(REQUEST_TYPE.PARAMS, rulesID),
@@ -96,9 +96,9 @@ class AdminController extends Controller {
96
96
  return data;
97
97
  };
98
98
 
99
- postCreate() {
99
+ postCreatePublic() {
100
100
  return {
101
- path: '/public',
101
+ path: '/',
102
102
  method: [
103
103
  roleMiddleware([this.options.roles.CREATE], USER_LEVEL.ADMIN),
104
104
  validateMiddleware(REQUEST_TYPE.BODY, this.options.rulesCreate),
@@ -119,9 +119,9 @@ class AdminController extends Controller {
119
119
  return data;
120
120
  };
121
121
 
122
- putModify() {
122
+ putModifyPublic() {
123
123
  return {
124
- path: '/public/:id',
124
+ path: '/:id',
125
125
  method: [
126
126
  roleMiddleware([this.options.roles.UPDATE], USER_LEVEL.ADMIN),
127
127
  validateMiddleware(REQUEST_TYPE.PARAMS, rulesID),
@@ -141,9 +141,9 @@ class AdminController extends Controller {
141
141
  };
142
142
  };
143
143
 
144
- delete() {
144
+ deletePublic() {
145
145
  return {
146
- path: '/public/:id',
146
+ path: '/:id',
147
147
  method: [
148
148
  roleMiddleware([this.options.roles.DELETE], USER_LEVEL.ADMIN),
149
149
  validateMiddleware(REQUEST_TYPE.PARAMS, rulesID),
@@ -158,7 +158,7 @@ class AdminController extends Controller {
158
158
  };
159
159
  };
160
160
 
161
- postRestore() {
161
+ postRestoreTrash() {
162
162
  return {
163
163
  path: '/trash/:id',
164
164
  method: [
@@ -175,9 +175,9 @@ class AdminController extends Controller {
175
175
  };
176
176
  };
177
177
 
178
- deleteDestroy() {
178
+ deleteDestroyTrash() {
179
179
  return {
180
- path: '/destroy/:id',
180
+ path: '/trash/:id',
181
181
  method: [
182
182
  roleMiddleware([this.options.roles.DESTROY], USER_LEVEL.ADMIN),
183
183
  validateMiddleware(REQUEST_TYPE.PARAMS, rulesID),
package/src/ApiServer.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import fs from 'fs';
2
+ import path from 'path';
2
3
  import http from 'http';
3
4
  import express from 'express';
4
5
  import helmet from 'helmet';
@@ -229,33 +230,31 @@ class ApiServer {
229
230
  });
230
231
 
231
232
  const msg = [];
232
- _.map(this.controllers, (obj) => {
233
+ _.map(this.controllers, (data) => {
234
+ const controller = data.controller;
235
+ const controllerName = data.name;
236
+ const controllerVersion = data.version;
233
237
 
234
- const {name, controller, version} = obj;
238
+ const listPublicRouter = controller.publicRouter();
235
239
 
236
- const listPublicMethod = obj.controller.publicMethod();
240
+ _.map(listPublicRouter, (method) => {
241
+ const {name, type} = method;
237
242
 
238
- _.map(listPublicMethod, (methodName) => {
243
+ const router = controller[name]();
239
244
 
240
- const matches = methodName.match(/get|post|put|patch|delete/);
241
- if (matches) {
242
- const type = matches[0];
243
- const item = controller[methodName]();
245
+ router.path = `/${method.path}/${router.path}`;
246
+ router.path = controller.pathName ? `/${controller.pathName}${router.path}` : router.path;
247
+ router.path = controllerVersion.startsWith('v') ? `/${controllerVersion}${router.path}` : router.path;
244
248
 
245
- item.path = controller.pathName ? `/${controller.pathName}${item.path}` : item.path;
246
-
247
- item.path = version.startsWith('v') ? `/${version}${item.path}` : item.path;
248
-
249
- msg.push({
250
- controller: name,
251
- version,
252
- type,
253
- method: methodName,
254
- path: item.path
255
- });
249
+ msg.push({
250
+ controller: controllerName,
251
+ version: controllerVersion,
252
+ type,
253
+ method: name,
254
+ path: path.resolve(router.path)
255
+ });
256
256
 
257
- app[type](item.path, ...item.method);
258
- }
257
+ app[type](router.path, ...router.method);
259
258
  });
260
259
  });
261
260
 
package/src/Controller.js CHANGED
@@ -8,7 +8,7 @@ class Controller {
8
8
  };
9
9
  }
10
10
 
11
- publicMethod() {
11
+ publicRouter() {
12
12
  let child = this;
13
13
  let result = [];
14
14
 
@@ -16,11 +16,23 @@ class Controller {
16
16
 
17
17
  const data = Object.getOwnPropertyNames(Object.getPrototypeOf(child));
18
18
 
19
- result = [
20
- ...result,
21
- ...data.filter((methodName) => methodName.match(/^get|post|put|patch|delete/))
22
- ]
19
+ data.map((methodName) => {
20
+ const matches = methodName.match(/get|post|put|patch|delete/);
21
+ if (matches) {
22
+ let path = '/';
23
+ if (methodName.match(/Public/)) {
24
+ path += 'public';
25
+ } else if (methodName.match(/Trash/)) {
26
+ path += 'trash';
27
+ }
23
28
 
29
+ result.push({
30
+ type: matches[0],
31
+ name: methodName,
32
+ path
33
+ });
34
+ }
35
+ });
24
36
  child = child.__proto__;
25
37
  }
26
38
  return result;