import { PageConfig } from 'next';
import an48 from '@mmstudio/an000048';
import anylogger from 'anylogger';
import '@mmstudio/an000042';
import an49 from '@mmstudio/an000049';
import an8 from '@mmstudio/an000008';
const logger = anylogger('pages/api/xxx/add.api');
export type Result = {
ok: boolean;
message?: string;
};
export type Message = ITbxxx;
const handler = an48<Result>();
handler.put(async (req, res) => {
try {
logger.debug('msg body:', req.body);
const d = req.body as Message;
if (!d.xxx || !d.xxx === undefined) {
res.status(200).json({
ok: false,
message: '参数不完整'
});
return;
}
const db = an49();
const tb1 = db<ITxxx>('xxx');
const data = await tb1.first('xxx').where({
xxx: d.xxx
});
if (data) {
res.status(200).json({
ok: false,
message: '数据重复'
});
return;
}
const id = an8();
const tb2 = db<ITbxxx>('xxx');
await tb2.insert({
...d,
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;