import { PageConfig } from 'next';
import an48 from '@mmstudio/an000048';
import anylogger from 'anylogger';
import '@mmstudio/an000042';
import an49 from '@mmstudio/an000049';
const logger = anylogger('pages/api/xxx/del.api');
export type Result = {
ok: true;
} | {
ok: false;
message: string;
};
export type Message = {
id: string;
}
const handler = an48<Result>();
handler.delete(async (req, res) => {
try {
logger.debug('msg body:', req.body);
const { id } = req.body as Message;
if (!id) {
res.status(200).json({
ok: false,
message: '关键字为空'
});
return;
}
const db = an49();
const tb1 = db<ITbxxx>('xxx');
const d = await tb1.first('id').where({
id
});
if (d) {
res.status(200).json({
ok: false,
message: '该项目类型下有项目存在,不能删除'
});
return;
}
const tb = db<ITbxxx>('xxx');
await tb.del().where({
id
});
res.status(200).json({ ok: true });
} catch (error) {
logger.error(error);
res.status(200).json({ ok: false, message: (error as Error).message });
}
});
export const config = {} as PageConfig;
export default handler;