Skip to content

Commit 6c6e1e9

Browse files
author
pedro
committed
feat:添加success扩展
1 parent f3cd07a commit 6c6e1e9

7 files changed

Lines changed: 72 additions & 132 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
<a href="http://doc.cms.7yue.pro/">
33
<img src="http://doc.cms.7yue.pro/left-logo.png" width="250"/></a>
44
<br>
5-
Lin-CMS-Koa (测试版)
5+
Lin-CMS-Koa
66
</h1>
77

88
<h4 align="center">一个简单易用的CMS后端项目 | <a href="http://doc.cms.7yue.pro/" target="_blank">Lin-CMS-Koa</a></h4>
99

1010
<p align="center">
1111
<a href="http://flask.pocoo.org/docs/1.0/" rel="nofollow">
1212
<img src="https://img.shields.io/badge/koa-2.7.0-green.svg" alt="flask version" data-canonical-src="https://img.shields.io/badge/koa-2.7.0-green.svg" style="max-width:100%;"></a>
13-
<a href="https://pypi.org/project/Lin-CMS/" rel="nofollow"><img src="https://img.shields.io/badge/lin--cms--test-0.0.1--alpha8-red.svg" alt="lin-cms version" data-canonical-src="https://img.shields.io/badge/lin--cms--test-0.0.1--alpha8-red.svg" style="max-width:100%;"></a>
13+
<a href="https://pypi.org/project/Lin-CMS/" rel="nofollow"><img src="https://img.shields.io/badge/lin--mizar-0.1.1-green.svg" alt="lin-cms version" data-canonical-src="https://img.shields.io/badge/lin--cms--test-0.0.1--alpha8-red.svg" style="max-width:100%;"></a>
1414
<a href="http://doc.cms.7yue.pro/" rel="nofollow"><img src="https://img.shields.io/badge/license-MIT-lightgrey.svg" alt="LISENCE" data-canonical-src="https://img.shields.io/badge/license-MIT-lightgrey.svg" style="max-width:100%;"></a>
1515
</p>
1616

app/api/cms/admin.js

Lines changed: 30 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ const {
44
LinRouter,
55
routeMetaInfo,
66
adminRequired,
7-
Success,
87
NotFound,
98
Failed
109
} = require("lin-mizar");
@@ -95,11 +94,9 @@ admin.linPut(
9594
async ctx => {
9695
const v = await new ResetPasswordValidator().validate(ctx);
9796
await adminDao.changeUserPassword(ctx, v);
98-
ctx.json(
99-
new Success({
100-
msg: "密码修改成功"
101-
})
102-
);
97+
ctx.success({
98+
msg: "密码修改成功"
99+
});
103100
}
104101
);
105102

@@ -116,11 +113,9 @@ admin.linDelete(
116113
const v = await new PositiveIdValidator().validate(ctx);
117114
const id = v.get("path.id");
118115
await adminDao.deleteUser(ctx, id);
119-
ctx.json(
120-
new Success({
121-
msg: "操作成功"
122-
})
123-
);
116+
ctx.success({
117+
msg: "操作成功"
118+
});
124119
}
125120
);
126121

@@ -136,11 +131,9 @@ admin.linPut(
136131
async ctx => {
137132
const v = await new UpdateUserInfoValidator().validate(ctx);
138133
await adminDao.updateUserInfo(ctx, v);
139-
ctx.json(
140-
new Success({
141-
msg: "操作成功"
142-
})
143-
);
134+
ctx.success({
135+
msg: "操作成功"
136+
});
144137
}
145138
);
146139

@@ -221,17 +214,13 @@ admin.linPost(
221214
const v = await new NewGroupValidator().validate(ctx);
222215
const ok = await adminDao.createGroup(ctx, v);
223216
if (!ok) {
224-
ctx.json(
225-
new Failed({
226-
msg: "新建分组失败"
227-
})
228-
);
217+
throw new Failed({
218+
msg: "新建分组失败"
219+
});
229220
} else {
230-
ctx.json(
231-
new Success({
232-
msg: "新建分组成功"
233-
})
234-
);
221+
ctx.success({
222+
msg: "新建分组成功"
223+
});
235224
}
236225
}
237226
);
@@ -248,11 +237,9 @@ admin.linPut(
248237
async ctx => {
249238
const v = await new UpdateGroupValidator().validate(ctx);
250239
await adminDao.updateGroup(ctx, v);
251-
ctx.json(
252-
new Success({
253-
msg: "更新分组成功"
254-
})
255-
);
240+
ctx.success({
241+
msg: "更新分组成功"
242+
});
256243
}
257244
);
258245

@@ -269,11 +256,9 @@ admin.linDelete(
269256
const v = await new PositiveIdValidator().validate(ctx);
270257
const id = v.get("path.id");
271258
await adminDao.deleteGroup(ctx, id);
272-
ctx.json(
273-
new Success({
274-
msg: "删除分组成功"
275-
})
276-
);
259+
ctx.success({
260+
msg: "删除分组成功"
261+
});
277262
}
278263
);
279264

@@ -289,11 +274,9 @@ admin.linPost(
289274
async ctx => {
290275
const v = await new DispatchAuthValidator().validate(ctx);
291276
await adminDao.dispatchAuth(ctx, v);
292-
ctx.json(
293-
new Success({
294-
msg: "添加权限成功"
295-
})
296-
);
277+
ctx.success({
278+
msg: "添加权限成功"
279+
});
297280
}
298281
);
299282

@@ -309,11 +292,9 @@ admin.linPost(
309292
async ctx => {
310293
const v = await new DispatchAuthsValidator().validate(ctx);
311294
await adminDao.dispatchAuths(ctx, v);
312-
ctx.json(
313-
new Success({
314-
msg: "添加权限成功"
315-
})
316-
);
295+
ctx.success({
296+
msg: "添加权限成功"
297+
});
317298
}
318299
);
319300

@@ -329,11 +310,9 @@ admin.linPost(
329310
async ctx => {
330311
const v = await new RemoveAuthsValidator().validate(ctx);
331312
await adminDao.removeAuths(ctx, v);
332-
ctx.json(
333-
new Success({
334-
msg: "删除权限成功"
335-
})
336-
);
313+
ctx.success({
314+
msg: "删除权限成功"
315+
});
337316
}
338317
);
339318

app/api/cms/user.js

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ const {
66
getTokens,
77
loginRequired,
88
adminRequired,
9-
Success,
109
refreshTokenRequiredWithUnifyException,
1110
Failed,
12-
logger,
13-
checkUserIsActive
11+
logger
1412
} = require("lin-mizar");
1513

1614
const {
@@ -41,11 +39,9 @@ user.linPost(
4139
async ctx => {
4240
const v = await new RegisterValidator().validate(ctx);
4341
await userDao.createUser(ctx, v);
44-
ctx.json(
45-
new Success({
46-
msg: "用户创建成功"
47-
})
48-
);
42+
ctx.success({
43+
msg: "用户创建成功"
44+
});
4945
}
5046
);
5147

@@ -58,7 +54,6 @@ user.linPost(
5854
mount: false
5955
},
6056
async ctx => {
61-
checkUserIsActive(ctx.currentUser);
6257
const v = await new LoginValidator().validate(ctx);
6358
let user = await ctx.manager.userModel.verify(
6459
v.get("body.nickname"),
@@ -84,11 +79,9 @@ user.linPut(
8479
async ctx => {
8580
const v = await new UpdateInfoValidator().validate(ctx);
8681
await userDao.updateUser(ctx, v);
87-
ctx.json(
88-
new Success({
89-
msg: "操作成功"
90-
})
91-
);
82+
ctx.success({
83+
msg: "操作成功"
84+
});
9285
}
9386
);
9487

@@ -110,17 +103,13 @@ user.linPut(
110103
);
111104
if (ok) {
112105
user.save();
113-
ctx.json(
114-
new Success({
115-
msg: "密码修改成功"
116-
})
117-
);
106+
ctx.success({
107+
msg: "密码修改成功"
108+
});
118109
} else {
119-
ctx.json(
120-
new Failed({
121-
msg: "修改密码失败"
122-
})
123-
);
110+
throw new Failed({
111+
msg: "修改密码失败"
112+
});
124113
}
125114
}
126115
);

app/api/v1/book.js

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
const {
44
LinRouter,
55
NotFound,
6-
Success,
76
groupRequired,
87
disableLoading
98
} = require("lin-mizar");
@@ -61,22 +60,18 @@ bookApi.get("/search/one", async ctx => {
6160
bookApi.post("/", async ctx => {
6261
const v = await new CreateOrUpdateBookValidator().validate(ctx);
6362
await bookDto.createBook(v);
64-
ctx.json(
65-
new Success({
66-
msg: "新建图书成功"
67-
})
68-
);
63+
ctx.success({
64+
msg: "新建图书成功"
65+
});
6966
});
7067

7168
bookApi.put("/:id", async ctx => {
7269
const v = await new CreateOrUpdateBookValidator().validate(ctx);
7370
const id = getSafeParamId(ctx);
7471
await bookDto.updateBook(v, id);
75-
ctx.json(
76-
new Success({
77-
msg: "更新图书成功"
78-
})
79-
);
72+
ctx.success({
73+
msg: "更新图书成功"
74+
});
8075
});
8176

8277
bookApi.linDelete(
@@ -92,11 +87,9 @@ bookApi.linDelete(
9287
const v = await new PositiveIdValidator().validate(ctx);
9388
const id = v.get("path.id");
9489
await bookDto.deleteBook(id);
95-
ctx.json(
96-
new Success({
97-
msg: "删除图书成功"
98-
})
99-
);
90+
ctx.success({
91+
msg: "删除图书成功"
92+
});
10093
}
10194
);
10295

app/plugins/notify/app/message.js

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
"use strict";
22

3-
const {
4-
LinRouter,
5-
loginRequired,
6-
NotFound,
7-
paginate,
8-
Success
9-
} = require("lin-mizar");
3+
const { LinRouter, loginRequired, NotFound, paginate } = require("lin-mizar");
104
const { getSafeParamId } = require("../../../libs/util");
115
const { IdsValidator } = require("./validators");
126
const { MessageDao } = require("./message-dao");
@@ -53,11 +47,9 @@ messageApi.linPut(
5347
async ctx => {
5448
const id = getSafeParamId(ctx);
5549
await messageDao.readMessage(id);
56-
ctx.json(
57-
new Success({
58-
msg: "操作成功"
59-
})
60-
);
50+
ctx.success({
51+
msg: "操作成功"
52+
});
6153
}
6254
);
6355

@@ -73,11 +65,9 @@ messageApi.linPut(
7365
async ctx => {
7466
const v = await new IdsValidator().validate(ctx);
7567
await messageDao.readMessages(v);
76-
ctx.json(
77-
new Success({
78-
msg: "操作成功"
79-
})
80-
);
68+
ctx.success({
69+
msg: "操作成功"
70+
});
8171
}
8272
);
8373

@@ -93,11 +83,9 @@ messageApi.linDelete(
9383
async ctx => {
9484
const id = getSafeParamId(ctx);
9585
await messageDao.deleteMessage(id);
96-
ctx.json(
97-
new Success({
98-
msg: "操作成功"
99-
})
100-
);
86+
ctx.success({
87+
msg: "操作成功"
88+
});
10189
}
10290
);
10391

app/plugins/notify/app/sse.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
"use strict";
22

3-
const {
4-
LinRouter,
5-
groupRequired,
6-
adminRequired,
7-
Success
8-
} = require("lin-mizar");
3+
const { LinRouter, groupRequired, adminRequired } = require("lin-mizar");
94
const { SSE } = require("lin-mizar/lin/sse");
105
const dayjs = require("dayjs");
116
const { EventsValidator } = require("./validators");
@@ -102,11 +97,9 @@ sseApi.linPost(
10297
async ctx => {
10398
const v = await new EventsValidator().validate(ctx);
10499
await eventDao.createEvents(v);
105-
ctx.json(
106-
new Success({
107-
msg: "创建成功"
108-
})
109-
);
100+
ctx.success({
101+
msg: "创建成功"
102+
});
110103
}
111104
);
112105

@@ -122,11 +115,9 @@ sseApi.linPut(
122115
async ctx => {
123116
const v = await new EventsValidator().validate(ctx);
124117
await eventDao.updateEvents(v);
125-
ctx.json(
126-
new Success({
127-
msg: "更新成功"
128-
})
129-
);
118+
ctx.success({
119+
msg: "更新成功"
120+
});
130121
}
131122
);
132123

0 commit comments

Comments
 (0)