1
This commit is contained in:
@@ -1,35 +1,44 @@
|
||||
const crud = require("../service/biz_admin_crud");
|
||||
|
||||
const baseModel = require("../../middleware/baseModel");
|
||||
const { find_page, find_for_export, normalize_for_write } = require("../service/biz_query_helpers");
|
||||
|
||||
module.exports = {
|
||||
"POST /biz_usage/page": async (ctx) => {
|
||||
const body = ctx.getBody();
|
||||
const data = await crud.page("biz_usage_monthly", body);
|
||||
ctx.success({ rows: data.rows, count: data.count });
|
||||
const { count, rows } = await find_page(baseModel.biz_usage_monthly, "biz_usage_monthly", body);
|
||||
ctx.success({ rows, count });
|
||||
},
|
||||
"POST /biz_usage/add": async (ctx) => {
|
||||
const body = ctx.getBody();
|
||||
const row = await crud.add("biz_usage_monthly", body);
|
||||
const payload = normalize_for_write(baseModel.biz_usage_monthly, body, { for_create: true });
|
||||
const row = await baseModel.biz_usage_monthly.create(payload);
|
||||
ctx.success(row);
|
||||
},
|
||||
"POST /biz_usage/edit": async (ctx) => {
|
||||
const body = ctx.getBody();
|
||||
await crud.edit("biz_usage_monthly", body);
|
||||
const id = body.id;
|
||||
if (id === undefined || id === null || id === "") throw new Error("缺少 id");
|
||||
const payload = normalize_for_write(baseModel.biz_usage_monthly, body, { for_create: false });
|
||||
delete payload.id;
|
||||
await baseModel.biz_usage_monthly.update(payload, { where: { id } });
|
||||
ctx.success({});
|
||||
},
|
||||
"POST /biz_usage/del": async (ctx) => {
|
||||
const body = ctx.getBody();
|
||||
await crud.del("biz_usage_monthly", body);
|
||||
const id = body.id !== undefined ? body.id : body;
|
||||
if (id === undefined || id === null || id === "") throw new Error("缺少 id");
|
||||
await baseModel.biz_usage_monthly.destroy({ where: { id } });
|
||||
ctx.success({});
|
||||
},
|
||||
"GET /biz_usage/detail": async (ctx) => {
|
||||
const q = ctx.query || {};
|
||||
const row = await crud.detail("biz_usage_monthly", { id: q.id || q.ID });
|
||||
const id = q.id || q.ID;
|
||||
if (id === undefined || id === null || id === "") throw new Error("缺少 id");
|
||||
const row = await baseModel.biz_usage_monthly.findByPk(id);
|
||||
ctx.success(row);
|
||||
},
|
||||
"POST /biz_usage/export": async (ctx) => {
|
||||
const body = ctx.getBody();
|
||||
const res = await crud.exportCsv("biz_usage_monthly", body);
|
||||
const res = await find_for_export(baseModel.biz_usage_monthly, "biz_usage_monthly", body);
|
||||
ctx.success(res);
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user