1234567891011121314151617181920212223242526272829303132333435363738394041 |
- '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.disclosure_id).equals(i._id));
- if (r) i.has_report = r._id;
- else i.has_report = false;
- }
- } else {
- if (res.length > 0) data.has_report = res[0]._id;
- else data.has_report = false;
- }
- ctx.body.data = data;
- }
- }
- };
- };
|