'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; let id; if (method === 'POST') { const { data } = ctx.body; id = data._id; } await next(); if (method === 'POST') { // 将添加,修改拦截,给加上记录 const arr = url.split('/'); const last = _.last(arr); let word = ''; if (ObjectId.isValid(last)) word = 'update'; else word = 'create'; await addRecord(ctx, id, word, options); } }; };