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/edit.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 {id, ...d} = req.body as Message;
if (!d.id || d.id === undefined) {
res.status(200).json({
ok: false,
message: '参数不完整'
});
return;
}
const db = an49();
const tb1 = db<ITbxxx>('xxx');
const data = await tb1.first('xxx').where({
xxx: d.xxx
}).andWhereNot({
id
});
if (data) {
res.status(200).json({
ok: false,
message: '数据重复'
});
return;
}
const tb2 = db<ITbxxx>('xxx');
await tb2.update(d).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;