'use strict'; const _ = require('lodash'); const { ObjectId } = require('mongoose').Types; const addRecord = async (ctx, service, args) => { const arr = service.split('.'); let s = ctx.service; for (const key of arr) { s = s[key]; } const service_method = 'record'; return await s[service_method](args); }; module.exports = options => { return async function patentapply_record(ctx, next) { const { url, method } = ctx.request; await next(); let id; if (method === 'POST') { // 将添加,修改拦截,给加上记录 const arr = url.split('/'); const last = _.last(arr); let word = ''; if (ObjectId.isValid(last) && url.includes('update')) word = 'update'; else { word = 'create'; } id = _.get(ctx.body, 'data._id'); const nd = await addRecord(ctx, options, { id, method: word }); ctx.body.data = nd; } }; };