disclosure_record.js 766 B

12345678910111213141516171819202122232425262728293031
  1. 'use strict';
  2. const _ = require('lodash');
  3. const addRecord = async (ctx, id, method) => {
  4. return await ctx.service.patent.disclosure.record({ id, method });
  5. };
  6. module.exports = options => {
  7. return async function disclosure_record(ctx, next) {
  8. await next();
  9. const { url, method } = ctx.request;
  10. if (method === 'POST') {
  11. // 将添加,修改拦截,给加上记录
  12. const arr = url.split('/');
  13. const last = _.last(arr);
  14. const { data } = ctx.body;
  15. const id = data._id;
  16. let word = '';
  17. if (last === 'disclosure') {
  18. // create
  19. word = 'create';
  20. } else {
  21. // update
  22. word = 'update';
  23. }
  24. const nd = await addRecord(ctx, id, word);
  25. ctx.body.data = nd;
  26. }
  27. };
  28. };