123456789101112131415161718192021222324252627282930 |
- 'use strict';
- const rkey = 'team';
- const ckey = 'team';
- const keyZh = '团队';
- const routes = [
- { method: 'get', path: `${rkey}/userteams`, controller: `${ckey}.userteam`, name: `${ckey}Userteam`, zh: `${keyZh}用戶团队` },
- { method: 'get', path: `${rkey}/leaves`, controller: `${ckey}.leave`, name: `${ckey}Leave`, zh: `${keyZh}退出团队` },
- { method: 'get', path: `${rkey}`, controller: `${ckey}.index`, name: `${ckey}Query`, zh: `${keyZh}列表查询` },
- { method: 'get', path: `${rkey}/:id`, controller: `${ckey}.show`, name: `${ckey}Show`, zh: `${keyZh}查询` },
- { method: 'post', path: `${rkey}`, controller: `${ckey}.create`, middleware: [ 'password' ], name: `${ckey}Create`, zh: `创建${keyZh}` },
- { method: 'post', path: `${rkey}/:id`, controller: `${ckey}.update`, name: `${ckey}Update`, zh: `修改${keyZh}` },
- { method: 'delete', path: `${rkey}/:id`, controller: `${ckey}.destroy`, name: `${ckey}Delete`, zh: `删除${keyZh}` },
- ];
- module.exports = app => {
- const { router, config } = app;
- const mwares = app.middleware;
- for (const route of routes) {
- const { method, path, controller: ctl, zh } = route;
- let { middleware = [] } = route;
- if (!method || !path || !ctl) continue;
-
- const allPath = `${config.routePrefix}/${path}`;
-
- if (middleware.length > 0) middleware = middleware.map(i => mwares[i]({ enable: true }));
-
- router[method](zh, allPath, ...middleware, ctl);
- }
- };
|