'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 失败' }; } };