import { app } from '@/app.ts'; import { Config } from './model/config.ts'; app .route({ path: 'config', key: 'list', }) .define(async (ctx) => { ctx.body = await Config.findAll(); }) .addTo(app); app .route({ path: 'config', key: 'meGet', }) .define(async (ctx) => { const config = await Config.findOne({ where: { key: 'me', }, logging: false, }); ctx.body = config; }) .addTo(app); app .route({ path: 'config', key: 'meSet', }) .define(async (ctx) => { const { data } = ctx.query; if (!data) { ctx.throw(400, 'data is required'); } let config = await Config.findOne({ where: { key: 'me' }, // 自定义条件 logging: false, }); if (!config) { config = await Config.create({ key: 'me', value: data, }); ctx.body = config; return; } else { config.value = data; await config.save(); ctx.body = config; } }) .addTo(app);