12345678910111213141516171819202122232425262728293031 |
- 'use strict';
- const _ = require('lodash');
- const addRecord = async (ctx, id, method) => {
- return await ctx.service.patent.disclosure.record({ id, method });
- };
- module.exports = options => {
- return async function disclosure_record(ctx, next) {
- await next();
- const { url, method } = ctx.request;
- if (method === 'POST') {
- // 将添加,修改拦截,给加上记录
- const arr = url.split('/');
- const last = _.last(arr);
- const { data } = ctx.body;
- const id = data._id;
- let word = '';
- if (last === 'disclosure') {
- // create
- word = 'create';
- } else {
- // update
- word = 'update';
- }
- const nd = await addRecord(ctx, id, word);
- ctx.body.data = nd;
- }
- };
- };
|