1
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
const crud = require("../service/biz_admin_crud");
|
||||
|
||||
const baseModel = require("../../middleware/baseModel");
|
||||
const audit = require("../service/biz_audit_service");
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
const Sequelize = require("sequelize");
|
||||
const crud = require("../service/biz_admin_crud");
|
||||
|
||||
const baseModel = require("../../middleware/baseModel");
|
||||
@@ -7,8 +8,31 @@ const audit = require("../service/biz_audit_service");
|
||||
module.exports = {
|
||||
"POST /biz_user/page": async (ctx) => {
|
||||
const body = ctx.getBody();
|
||||
const data = await crud.page("biz_user", body);
|
||||
ctx.success({ rows: data.rows, count: data.count });
|
||||
const param = body.param || body;
|
||||
const pageOption = param.pageOption || {};
|
||||
const seachOption = param.seachOption || {};
|
||||
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 = crud.buildSearchWhere(model, seachOption);
|
||||
const { count, rows } = await model.findAndCountAll({
|
||||
where,
|
||||
offset,
|
||||
limit: pageSize,
|
||||
order: [["id", "DESC"]],
|
||||
attributes: {
|
||||
include: [
|
||||
[
|
||||
Sequelize.literal(
|
||||
`(SELECT COUNT(*) FROM biz_api_tokens WHERE biz_api_tokens.user_id = biz_user.id)`
|
||||
),
|
||||
"token_count",
|
||||
],
|
||||
],
|
||||
},
|
||||
});
|
||||
ctx.success({ rows, count });
|
||||
},
|
||||
"POST /biz_user/add": async (ctx) => {
|
||||
const body = ctx.getBody();
|
||||
@@ -62,10 +86,17 @@ module.exports = {
|
||||
const tokenCount = await baseModel.biz_api_token.count({
|
||||
where: { user_id: id },
|
||||
});
|
||||
const tokens = await baseModel.biz_api_token.findAll({
|
||||
where: { user_id: id },
|
||||
order: [["id", "DESC"]],
|
||||
limit: 200,
|
||||
attributes: ["id", "user_id", "plan_id", "token_name", "status", "expire_at", "last_used_at"],
|
||||
});
|
||||
ctx.success({
|
||||
user,
|
||||
subscriptions,
|
||||
tokenCount,
|
||||
tokens,
|
||||
});
|
||||
},
|
||||
"GET /biz_user/all": async (ctx) => {
|
||||
|
||||
Reference in New Issue
Block a user