Skip to content

Commit c4039b4

Browse files
author
pedro
committed
fix: 修复sequelize升级带来的版本问题
1 parent 12a02f3 commit c4039b4

7 files changed

Lines changed: 16 additions & 16 deletions

File tree

app/api/cms/admin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ admin.linGet(
7474
const { users, total } = await adminDao.getUsers(
7575
ctx,
7676
v.get("query.group_id"),
77-
v.get("query.start"),
77+
v.get("query.page"),
7878
v.get("query.count")
7979
);
8080
ctx.json({
@@ -159,7 +159,7 @@ admin.linGet(
159159
const v = await new PaginateValidator().validate(ctx);
160160
const { groups, total } = await adminDao.getGroups(
161161
ctx,
162-
v.get("query.start"),
162+
v.get("query.page"),
163163
v.get("query.count")
164164
);
165165
if (total < 1) {

app/api/cms/log.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ log.linGet(
7474
groupRequired,
7575
async ctx => {
7676
const v = await new PaginateValidator().validate(ctx);
77-
const arr = await logDao.getUserNames(v.get("query.start"), v.get("query.count"));
77+
const arr = await logDao.getUserNames(v.get("query.page"), v.get("query.count"));
7878
ctx.json(arr);
7979
}
8080
);

app/api/v1/book.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ exports.bookApi = bookApi;
2828
const bookDto = new BookDao();
2929

3030
bookApi.get("/:id", async ctx => {
31-
const v = await new PositiveIdValidator().validate();
31+
const v = await new PositiveIdValidator().validate(ctx);
3232
const id = v.get("path.id");
3333
const book = await bookDto.getBook(id);
3434
if (!book) {
@@ -89,7 +89,7 @@ bookApi.linDelete(
8989
},
9090
groupRequired,
9191
async ctx => {
92-
const v = await new PositiveIdValidator().validate();
92+
const v = await new PositiveIdValidator().validate(ctx);
9393
const id = v.get("path.id");
9494
await bookDto.deleteBook(id);
9595
ctx.json(

app/dao/admin.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const {
1111

1212
const { has, set, get } = require("lodash");
1313
const { db } = require("lin-mizar/lin/db");
14+
const { Op } = require("sequelize");
1415
const dayjs = require("dayjs");
1516

1617
class AdminDao {
@@ -19,7 +20,7 @@ class AdminDao {
1920
"SELECT lin_user.*,lin_group.`name` as group_name FROM lin_user LEFT JOIN lin_group ON lin_user.group_id = lin_group.id WHERE";
2021
groupId && (sql += " lin_user.group_id = :id AND");
2122
let users = await db.query(
22-
sql + " lin_user.admin = :admin LIMIT :count OFFSET :start ",
23+
sql + " lin_user.admin = :admin AND lin_user.delete_time IS NULL LIMIT :count OFFSET :start ",
2324
{
2425
replacements: groupId
2526
? {
@@ -37,7 +38,7 @@ class AdminDao {
3738
}
3839
);
3940
let total = await db.query(
40-
"SELECT COUNT(*) as count FROM lin_user WHERE lin_user.admin=:admin",
41+
"SELECT COUNT(*) as count FROM lin_user WHERE lin_user.admin=:admin AND lin_user.delete_time IS NULL",
4142
{
4243
replacements: {
4344
admin: UserAdmin.COMMON
@@ -86,8 +87,7 @@ class AdminDao {
8687
msg: "用户不存在"
8788
});
8889
}
89-
// 推荐调用软删除,即下面注释代码
90-
user.softDelete();
90+
user.destroy();
9191
}
9292

9393
async updateUserInfo (ctx, v) {
@@ -295,7 +295,7 @@ class AdminDao {
295295
msg: "分组不存在"
296296
});
297297
}
298-
v.get("auths").forEach(async item => {
298+
v.get("body.auths").forEach(async item => {
299299
const one = await ctx.manager.authModel.findOne({
300300
where: {
301301
group_id: v.get("body.group_id"),
@@ -324,7 +324,7 @@ class AdminDao {
324324
where: {
325325
group_id: v.get("body.group_id"),
326326
auth: {
327-
[db.Op.in]: v.get("body.auths")
327+
[Op.in]: v.get("body.auths")
328328
}
329329
}
330330
});

app/dao/book.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class BookDao {
8787
msg: "没有找到相关书籍"
8888
});
8989
}
90-
book.softDelete();
90+
book.destroy();
9191
}
9292
}
9393

app/dao/log.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const Sequelize = require("sequelize");
77

88
class LogDao {
99
async getLogs (v) {
10-
const start = v.get("query.start");
10+
const start = v.get("query.page");
1111
const count1 = v.get("query.count");
1212
let condition = {};
1313
v.get("body.name") && set(condition, "user_name", v.get("body.name"));
@@ -29,7 +29,7 @@ class LogDao {
2929
}
3030

3131
async searchLogs (v, keyword) {
32-
const start = v.get("query.start");
32+
const start = v.get("query.page");
3333
const count1 = v.get("query.count");
3434
let condition = {};
3535
v.get("body.name") && set(condition, "user_name", v.get("body.name"));
@@ -38,7 +38,7 @@ class LogDao {
3838
set(condition, "time", {
3939
[Sequelize.Op.between]: [v.get("body.start"), v.get("body.end")]
4040
});
41-
let { rows, count } = await Log.findAndCount({
41+
let { rows, count } = await Log.findAndCountAll({
4242
where: Object.assign({}, condition, {
4343
message: {
4444
[Sequelize.Op.like]: `%${keyword}%`

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@
3939
"@koa/cors": "^2.2.3",
4040
"koa": "^2.7.0",
4141
"koa-bodyparser": "^4.2.1",
42-
"lin-mizar": "^0.0.1-alpha.4"
42+
"lin-mizar": "^0.0.1-alpha.9"
4343
}
4444
}

0 commit comments

Comments
 (0)