Files
wechatWeb/api/controller_admin/biz_token.js
张成 494555a6e1 1
2026-04-01 10:13:22 +08:00

51 lines
1.6 KiB
JavaScript

const crud = require("../service/biz_admin_crud");
const tokenLogic = require("../service/biz_token_logic");
const audit = require("../service/biz_audit_service");
module.exports = {
"POST /biz_token/page": async (ctx) => {
const body = ctx.getBody();
const data = await crud.page("biz_api_token", body);
ctx.success({ rows: data.rows, count: data.count });
},
"POST /biz_token/create": async (ctx) => {
const body = ctx.getBody();
const result = await tokenLogic.createToken(body);
await audit.logAudit({
admin_user_id: audit.pickAdminId(ctx),
biz_user_id: result.row.user_id,
action: "biz_token.create",
resource_type: "biz_api_token",
resource_id: result.row.id,
detail: { token_name: result.row.token_name },
});
ctx.success({
id: result.row.id,
user_id: result.row.user_id,
plan_id: result.row.plan_id,
token_name: result.row.token_name,
expire_at: result.row.expire_at,
plain_token: result.plain_token,
warn: result.warn,
});
},
"POST /biz_token/revoke": async (ctx) => {
const body = ctx.getBody();
const row = await tokenLogic.revokeToken(body);
await audit.logAudit({
admin_user_id: audit.pickAdminId(ctx),
biz_user_id: row.user_id,
action: "biz_token.revoke",
resource_type: "biz_api_token",
resource_id: row.id,
});
ctx.success({ id: row.id, status: row.status });
},
"POST /biz_token/export": async (ctx) => {
const body = ctx.getBody();
const res = await crud.exportCsv("biz_api_token", body);
ctx.success(res);
},
};