|
@@ -0,0 +1,41 @@
|
|
|
+'use strict';
|
|
|
+const _ = require('lodash');
|
|
|
+const { ObjectId } = require('mongoose').Types;
|
|
|
+
|
|
|
+const checkReport = async (ctx, data) => {
|
|
|
+ return await ctx.service.patent.report.checkReport(data);
|
|
|
+};
|
|
|
+
|
|
|
+module.exports = options => {
|
|
|
+ return async function disclosure_report(ctx, next) {
|
|
|
+ await next();
|
|
|
+ const { method } = ctx.request;
|
|
|
+ if (method === 'GET') {
|
|
|
+ let { data } = ctx.body;
|
|
|
+ if (data || data.length > 0) {
|
|
|
+ data = JSON.parse(JSON.stringify(data));
|
|
|
+ const ids = [];
|
|
|
+ if (_.isArray(data)) {
|
|
|
+ for (const i of data) {
|
|
|
+ ids.push(i._id);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ids.push(data._id);
|
|
|
+ }
|
|
|
+ const res = await checkReport(ctx, ids);
|
|
|
+ if (_.isArray(data)) {
|
|
|
+ for (const i of data) {
|
|
|
+ const r = res.find(f => ObjectId(f).equals(i._id));
|
|
|
+ if (r) i.has_report = true;
|
|
|
+ else i.has_report = false;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (res.length > 0) data.has_report = true;
|
|
|
+ else data.has_report = false;
|
|
|
+ }
|
|
|
+ ctx.body.data = data;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ };
|
|
|
+};
|