ai-query对接新版freesun-agent接口的分支
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

47 lines
1.6 KiB

'use strict';
const { parsePagination } = require('./helpers');
module.exports.getSchemaVersions = async (ctx, next) => {
try {
const { models, ORM: { Op } } = ctx.app.fs.dc;
const { offset, limit } = parsePagination(ctx.request.query);
const where = {};
const versionName = String(ctx.request.query.versionName || '').trim();
if (versionName) {
where.versionName = { [Op.like]: `%${versionName}%` };
}
const list = await models.ReportSchemaVersion.findAndCountAll({
where,
order: [['id', 'DESC']],
offset,
limit,
raw: true,
});
ctx.body = { count: list.count, rows: list.rows };
ctx.status = 200;
} catch (error) {
ctx.logger.log(error);
ctx.status = 400;
ctx.body = { message: typeof error === 'string' ? error : '获取 schema version 列表失败' };
}
};
module.exports.createSchemaVersion = async (ctx, next) => {
try {
const { models } = ctx.app.fs.dc;
const { versionName, schemaDefinition } = ctx.request.body || {};
if (!String(versionName || '').trim()) throw '缺少参数: versionName';
if (schemaDefinition === null || schemaDefinition === undefined) throw '缺少参数: schemaDefinition';
const created = await models.ReportSchemaVersion.create({
versionName: String(versionName).trim(),
schemaDefinition,
}, { returning: true });
ctx.body = created;
ctx.status = 200;
} catch (error) {
ctx.logger.log(error);
ctx.status = 400;
ctx.body = { message: typeof error === 'string' ? error : '创建 schema version 失败' };
}
};