Skip to content

Commit 4adaf80

Browse files
authored
Merge pull request #63 from TaleLin/braver
feat(version): upgrade to version 0.3.0
2 parents c462795 + 8540571 commit 4adaf80

73 files changed

Lines changed: 2130 additions & 2045 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.babelrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"presets": [
3+
["env", {"targets": {"node": "current"}}]
4+
],
5+
"plugins": [
6+
["@babel/plugin-proposal-decorators", { "legacy": true }]
7+
]
8+
}

.eslintrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ module.exports = {
44
rules: {
55
semi: ['warn', 'always'],
66
quotes: ['warn', 'single'],
7+
'camelcase': 0,
78
'eol-last': 0,
89
'jest/no-disabled-tests': 'warn',
910
'jest/no-focused-tests': 'error',
1011
'jest/no-identical-title': 'error',
1112
'jest/prefer-to-have-length': 'warn',
12-
'jest/valid-expect': 'error'
13+
'jest/valid-expect': 'error',
1314
},
1415
env: {
1516
jest: true

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,16 @@ QQ 群号:643205479
5959

6060
<img class="QR-img" src="http://imglf6.nosdn0.126.net/img/YUdIR2E3ME5weEdlNThuRmI4TFh3UWhiNmladWVoaTlXUXpicEFPa1F6czFNYkdmcWRIbGRRPT0.jpg?imageView&thumbnail=500x0&quality=96&stripmeta=0&type=jpg">
6161

62-
### Lin CMS 的特点
62+
## 版本日志
63+
64+
最新版本 `0.3.0`
65+
66+
### 0.3.0
67+
68+
1. `A` 将模型层抽离核心库进行重构
69+
70+
71+
## Lin CMS 的特点
6372

6473
Lin CMS 的构筑思想是有其自身特点的。下面我们阐述一些 Lin 的主要特点。
6574

app/api/cms/admin.js

Lines changed: 56 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,21 @@
1-
'use strict';
2-
3-
const {
4-
LinRouter,
5-
routeMetaInfo,
6-
adminRequired,
7-
NotFound,
8-
Failed
9-
} = require('lin-mizar');
10-
11-
const { has, set } = require('lodash');
12-
13-
const {
14-
DispatchAuthsValidator,
15-
RemoveAuthsValidator,
16-
UpdateGroupValidator,
17-
ResetPasswordValidator,
1+
import { LinRouter, Failed, NotFound } from 'lin-mizar';
2+
import {
183
AdminUsersValidator,
4+
ResetPasswordValidator,
195
UpdateUserInfoValidator,
206
NewGroupValidator,
21-
DispatchAuthValidator
22-
} = require('../../validators/admin');
23-
24-
const {
7+
UpdateGroupValidator,
8+
DispatchPermissionValidator,
9+
DispatchPermissionsValidator,
10+
RemovePermissionsValidator
11+
} from '../../validators/admin';
12+
import {
2513
PositiveIdValidator,
2614
PaginateValidator
27-
} = require('../../validators/common');
15+
} from '../../validators/common';
2816

29-
const { AdminDao } = require('../../dao/admin');
17+
import { adminRequired } from '../../middleware/jwt';
18+
import { AdminDao } from '../../dao/admin';
3019

3120
const admin = new LinRouter({
3221
prefix: '/cms/admin'
@@ -35,25 +24,17 @@ const admin = new LinRouter({
3524
const adminDao = new AdminDao();
3625

3726
admin.linGet(
38-
'getAuthority',
39-
'/authority',
27+
'getAllPermissions',
28+
'/permission',
4029
{
4130
auth: '查询所有可分配的权限',
4231
module: '管理员',
4332
mount: false
4433
},
4534
adminRequired,
46-
ctx => {
47-
const res = {};
48-
routeMetaInfo.forEach((v, k) => {
49-
const au = v['auth'];
50-
if (!has(res, `${v['module']}.${au}`)) {
51-
set(res, `${v['module']}.${au}`, [k]);
52-
} else {
53-
res[v['module']][au].push(k);
54-
}
55-
});
56-
ctx.json(res);
35+
async ctx => {
36+
const permissions = await adminDao.getAllPermissions();
37+
ctx.json(permissions);
5738
}
5839
);
5940

@@ -69,25 +50,22 @@ admin.linGet(
6950
async ctx => {
7051
const v = await new AdminUsersValidator().validate(ctx);
7152
const { users, total } = await adminDao.getUsers(
72-
ctx,
7353
v.get('query.group_id'),
7454
v.get('query.page'),
7555
v.get('query.count')
7656
);
7757
ctx.json({
7858
items: users,
79-
// 超级管理员不算入总数
80-
total: total,
81-
page: v.get('query.page'),
59+
total,
8260
count: v.get('query.count'),
83-
total_page: Math.ceil(total / parseInt(v.get('query.count')))
61+
page: v.get('query.page')
8462
});
8563
}
8664
);
8765

8866
admin.linPut(
8967
'changeUserPassword',
90-
'/password/:id',
68+
'/user/:id/password',
9169
{
9270
auth: '修改用户密码',
9371
module: '管理员',
@@ -98,14 +76,15 @@ admin.linPut(
9876
const v = await new ResetPasswordValidator().validate(ctx);
9977
await adminDao.changeUserPassword(ctx, v);
10078
ctx.success({
101-
msg: '密码修改成功'
79+
msg: '密码修改成功',
80+
errorCode: 2
10281
});
10382
}
10483
);
10584

10685
admin.linDelete(
10786
'deleteUser',
108-
'/:id',
87+
'/user/:id',
10988
{
11089
auth: '删除用户',
11190
module: '管理员',
@@ -117,14 +96,15 @@ admin.linDelete(
11796
const id = v.get('path.id');
11897
await adminDao.deleteUser(ctx, id);
11998
ctx.success({
120-
msg: '操作成功'
99+
msg: '删除用户成功',
100+
errorCode: 3
121101
});
122102
}
123103
);
124104

125105
admin.linPut(
126106
'updateUser',
127-
'/:id',
107+
'/user/:id',
128108
{
129109
auth: '管理员更新用户信息',
130110
module: '管理员',
@@ -135,14 +115,15 @@ admin.linPut(
135115
const v = await new UpdateUserInfoValidator().validate(ctx);
136116
await adminDao.updateUserInfo(ctx, v);
137117
ctx.success({
138-
msg: '操作成功'
118+
msg: '更新用户成功',
119+
errorCode: 4
139120
});
140121
}
141122
);
142123

143124
admin.linGet(
144125
'getAdminGroups',
145-
'/groups',
126+
'/group',
146127
{
147128
auth: '查询所有权限组及其权限',
148129
module: '管理员',
@@ -165,8 +146,7 @@ admin.linGet(
165146
items: groups,
166147
total: total,
167148
page: v.get('query.page'),
168-
count: v.get('query.count'),
169-
total_page: Math.ceil(total / parseInt(v.get('query.count')))
149+
count: v.get('query.count')
170150
});
171151
}
172152
);
@@ -181,7 +161,7 @@ admin.linGet(
181161
},
182162
adminRequired,
183163
async ctx => {
184-
const groups = await ctx.manager.groupModel.findAll();
164+
const groups = await adminDao.getAllGroups();
185165
if (!groups || groups.length < 1) {
186166
throw new NotFound({
187167
msg: '未找到任何权限组'
@@ -225,7 +205,8 @@ admin.linPost(
225205
});
226206
}
227207
ctx.success({
228-
msg: '新建分组成功'
208+
msg: '新建分组成功',
209+
errorCode: 13
229210
});
230211
}
231212
);
@@ -243,7 +224,8 @@ admin.linPut(
243224
const v = await new UpdateGroupValidator().validate(ctx);
244225
await adminDao.updateGroup(ctx, v);
245226
ctx.success({
246-
msg: '更新分组成功'
227+
msg: '更新分组成功',
228+
errorCode: 5
247229
});
248230
}
249231
);
@@ -262,63 +244,67 @@ admin.linDelete(
262244
const id = v.get('path.id');
263245
await adminDao.deleteGroup(ctx, id);
264246
ctx.success({
265-
msg: '删除分组成功'
247+
msg: '删除分组成功',
248+
errorCode: 6
266249
});
267250
}
268251
);
269252

270253
admin.linPost(
271-
'dispatchAuth',
272-
'/dispatch',
254+
'dispatchPermission',
255+
'/permission/dispatch',
273256
{
274257
auth: '分配单个权限',
275258
module: '管理员',
276259
mount: false
277260
},
278261
adminRequired,
279262
async ctx => {
280-
const v = await new DispatchAuthValidator().validate(ctx);
281-
await adminDao.dispatchAuth(ctx, v);
263+
const v = await new DispatchPermissionValidator().validate(ctx);
264+
await adminDao.dispatchPermission(ctx, v);
282265
ctx.success({
283-
msg: '添加权限成功'
266+
msg: '添加权限成功',
267+
errorCode: 6
284268
});
285269
}
286270
);
287271

288272
admin.linPost(
289-
'dispatchAuths',
290-
'/dispatch/patch',
273+
'dispatchPermissions',
274+
'/permission/dispatch/batch',
291275
{
292276
auth: '分配多个权限',
293277
module: '管理员',
294278
mount: false
295279
},
296280
adminRequired,
297281
async ctx => {
298-
const v = await new DispatchAuthsValidator().validate(ctx);
299-
await adminDao.dispatchAuths(ctx, v);
282+
const v = await new DispatchPermissionsValidator().validate(ctx);
283+
await adminDao.dispatchPermissions(ctx, v);
300284
ctx.success({
301-
msg: '添加权限成功'
285+
msg: '添加权限成功',
286+
errorCode: 7
302287
});
303288
}
304289
);
305290

306291
admin.linPost(
307-
'removeAuths',
308-
'/remove',
292+
'removePermissions',
293+
'/permission/remove',
309294
{
310295
auth: '删除多个权限',
311296
module: '管理员',
312297
mount: false
313298
},
314299
adminRequired,
315300
async ctx => {
316-
const v = await new RemoveAuthsValidator().validate(ctx);
317-
await adminDao.removeAuths(ctx, v);
301+
const v = await new RemovePermissionsValidator().validate(ctx);
302+
await adminDao.removePermissions(ctx, v);
318303
ctx.success({
319-
msg: '删除权限成功'
304+
msg: '删除权限成功',
305+
errorCode: 8
320306
});
321307
}
322308
);
323309

324-
module.exports = { admin };
310+
export { admin };

app/api/cms/file.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
'use strict';
1+
import { LinRouter, ParametersException } from 'lin-mizar';
22

3-
const { LinRouter, ParametersException, loginRequired } = require('lin-mizar');
4-
const { LocalUploader } = require('../../extensions/file/local-uploader');
3+
import { loginRequired } from '../../middleware/jwt';
4+
import { LocalUploader } from '../../extensions/file/local-uploader';
55

66
const file = new LinRouter({
77
prefix: '/cms/file'
@@ -17,4 +17,4 @@ file.linPost('upload', '/', {}, loginRequired, async ctx => {
1717
ctx.json(arr);
1818
});
1919

20-
module.exports = { file };
20+
export { file };

0 commit comments

Comments
 (0)