45 lines
1.8 KiB
JavaScript
45 lines
1.8 KiB
JavaScript
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 { 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 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();
|
|
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();
|
|
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 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 find_for_export(baseModel.biz_usage_monthly, "biz_usage_monthly", body);
|
|
ctx.success(res);
|
|
},
|
|
};
|