ruifeng_liu 3 år sedan
förälder
incheckning
51952974b4
2 ändrade filer med 11 tillägg och 6 borttagningar
  1. 10 6
      app/middleware/patentapply_record.js
  2. 1 0
      app/service/patent/patentapply.js

+ 10 - 6
app/middleware/patentapply_record.js

@@ -2,14 +2,14 @@
 const _ = require('lodash');
 const { ObjectId } = require('mongoose').Types;
 
-const addRecord = async (ctx, service, ...args) => {
+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);
+  return await s[service_method](args);
 };
 
 module.exports = options => {
@@ -17,8 +17,8 @@ module.exports = options => {
     const { url, method } = ctx.request;
     let id;
     if (method === 'POST') {
-      const { data } = ctx.body;
-      id = data._id;
+      const data = _.get(ctx.body, 'data');
+      if (data && data.id)id = data._id;
     }
     await next();
     if (method === 'POST') {
@@ -27,8 +27,12 @@ module.exports = options => {
       const last = _.last(arr);
       let word = '';
       if (ObjectId.isValid(last)) word = 'update';
-      else word = 'create';
-      await addRecord(ctx, id, word, options);
+      else {
+        word = 'create';
+        id = _.get(ctx.body, 'data._id');
+      }
+      const nd = await addRecord(ctx, options, { id, method: word });
+      ctx.body.data = nd;
     }
   };
 };

+ 1 - 0
app/service/patent/patentapply.js

@@ -31,6 +31,7 @@ class PatentapplyService extends CrudService {
     return await this.record({ id, method: status, remark });
   }
   async record({ id, method, remark }) {
+    console.log(id, method);
     let word = '';
     switch (`${method}`) {
       case 'create':