1
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
const Sequelize = require("sequelize");
|
||||
const { find_for_export, normalize_for_write, build_search_where } = require("../utils/query_helpers");
|
||||
const { normalize_for_write, build_search_where } = require("../utils/query_helpers");
|
||||
const baseModel = require("../../middleware/baseModel");
|
||||
const tokenLogic = require("../service/biz_token_logic");
|
||||
const audit = require("../utils/biz_audit");
|
||||
@@ -13,9 +13,9 @@ module.exports = {
|
||||
const pageNum = parseInt(pageOption.page, 10) || 1;
|
||||
const pageSize = parseInt(pageOption.pageSize, 10) || 20;
|
||||
const offset = (pageNum - 1) * pageSize;
|
||||
const model = baseModel.biz_user;
|
||||
const where = build_search_where(model, seachOption);
|
||||
const { count, rows } = await model.findAndCountAll({
|
||||
const biz_user = baseModel.biz_user;
|
||||
const where = build_search_where(biz_user, seachOption);
|
||||
const { count, rows } = await biz_user.findAndCountAll({
|
||||
where,
|
||||
offset,
|
||||
limit: pageSize,
|
||||
@@ -35,8 +35,9 @@ module.exports = {
|
||||
},
|
||||
"POST /biz_user/add": async (ctx) => {
|
||||
const body = ctx.getBody();
|
||||
const payload = normalize_for_write(baseModel.biz_user, body, { for_create: true });
|
||||
const row = await baseModel.biz_user.create(payload);
|
||||
const biz_user = baseModel.biz_user;
|
||||
const payload = normalize_for_write(biz_user, body, { for_create: true });
|
||||
const row = await biz_user.create(payload);
|
||||
await audit.logAudit({
|
||||
admin_user_id: audit.pickAdminId(ctx),
|
||||
biz_user_id: row.id,
|
||||
@@ -51,9 +52,10 @@ module.exports = {
|
||||
const body = ctx.getBody();
|
||||
const id = body.id;
|
||||
if (id === undefined || id === null || id === "") throw new Error("缺少 id");
|
||||
const payload = normalize_for_write(baseModel.biz_user, body, { for_create: false });
|
||||
const biz_user = baseModel.biz_user;
|
||||
const payload = normalize_for_write(biz_user, body, { for_create: false });
|
||||
delete payload.id;
|
||||
await baseModel.biz_user.update(payload, { where: { id } });
|
||||
await biz_user.update(payload, { where: { id } });
|
||||
await audit.logAudit({
|
||||
admin_user_id: audit.pickAdminId(ctx),
|
||||
biz_user_id: body.id,
|
||||
@@ -67,7 +69,8 @@ module.exports = {
|
||||
const body = ctx.getBody();
|
||||
const id = body.id !== undefined ? body.id : body;
|
||||
if (id === undefined || id === null || id === "") throw new Error("缺少 id");
|
||||
await baseModel.biz_user.destroy({ where: { id } });
|
||||
const biz_user = baseModel.biz_user;
|
||||
await biz_user.destroy({ where: { id } });
|
||||
await audit.logAudit({
|
||||
admin_user_id: audit.pickAdminId(ctx),
|
||||
biz_user_id: body.id,
|
||||
@@ -81,7 +84,8 @@ module.exports = {
|
||||
const q = ctx.query || {};
|
||||
const id = q.id || q.ID;
|
||||
if (id === undefined || id === null || id === "") throw new Error("缺少 id");
|
||||
const user = await baseModel.biz_user.findByPk(id);
|
||||
const biz_user = baseModel.biz_user;
|
||||
const user = await biz_user.findByPk(id);
|
||||
if (!user) {
|
||||
return ctx.fail("用户不存在");
|
||||
}
|
||||
@@ -107,7 +111,8 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
"GET /biz_user/all": async (ctx) => {
|
||||
const rows = await baseModel.biz_user.findAll({
|
||||
const biz_user = baseModel.biz_user;
|
||||
const rows = await biz_user.findAll({
|
||||
limit: 2000,
|
||||
order: [["id", "DESC"]],
|
||||
});
|
||||
@@ -117,7 +122,8 @@ module.exports = {
|
||||
const body = ctx.getBody();
|
||||
const id = body.id;
|
||||
if (id == null) return ctx.fail("缺少 id");
|
||||
await baseModel.biz_user.update({ status: "disabled" }, { where: { id } });
|
||||
const biz_user = baseModel.biz_user;
|
||||
await biz_user.update({ status: "disabled" }, { where: { id } });
|
||||
await audit.logAudit({
|
||||
admin_user_id: audit.pickAdminId(ctx),
|
||||
biz_user_id: id,
|
||||
@@ -131,7 +137,8 @@ module.exports = {
|
||||
const body = ctx.getBody();
|
||||
const id = body.id;
|
||||
if (id == null) return ctx.fail("缺少 id");
|
||||
await baseModel.biz_user.update({ status: "active" }, { where: { id } });
|
||||
const biz_user = baseModel.biz_user;
|
||||
await biz_user.update({ status: "active" }, { where: { id } });
|
||||
await audit.logAudit({
|
||||
admin_user_id: audit.pickAdminId(ctx),
|
||||
biz_user_id: id,
|
||||
@@ -143,8 +150,15 @@ module.exports = {
|
||||
},
|
||||
"POST /biz_user/export": async (ctx) => {
|
||||
const body = ctx.getBody();
|
||||
const res = await find_for_export(baseModel.biz_user, "biz_user", body);
|
||||
ctx.success(res);
|
||||
const param = body.param || body;
|
||||
const biz_user = baseModel.biz_user;
|
||||
const where = build_search_where(biz_user, param.seachOption || {});
|
||||
const rows = await biz_user.findAll({
|
||||
where,
|
||||
limit: 10000,
|
||||
order: [["id", "DESC"]],
|
||||
});
|
||||
ctx.success({ rows });
|
||||
},
|
||||
"POST /biz_user/revoke_all_tokens": async (ctx) => {
|
||||
const body = ctx.getBody();
|
||||
|
||||
Reference in New Issue
Block a user