'use strict'; const { CrudService } = require('naf-framework-mongoose/lib/service'); const { BusinessError, ErrorCode } = require('naf-core').Error; const _ = require('lodash'); const assert = require('assert'); const { ObjectId } = require('mongoose').Types; // 成果评价申请 class Achieve_applyService extends CrudService { constructor(ctx) { super(ctx, 'achieve_apply'); this.model = this.ctx.model.AchieveApply; } async getOne(query) { const keys = Object.keys(query); if (keys.length <= 0) throw new BusinessError(ErrorCode.BADPARAM, '缺少参数'); const res = await this.model.findOne(query); return res; } async researchCreate({ id }, body) { const res = await this.model.findById(id); if (!res) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到成果评价申请数据'); res.research.push(body); await res.save(); return; } async researchUpdate({ id, research_id }, body) { const res = await this.model.findById(id); if (!res) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到成果评价申请数据'); const person = res.research.id(research_id); if (!person) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到该申请下指定的主研人员'); const keys = Object.keys(body); for (const key of keys) { person[key] = body[key]; } await res.save(); } async researchDelete({ id, research_id }) { const res = await this.model.findById(id); if (!res) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到成果评价申请数据'); res.research.remove(research_id); await res.save(); } } module.exports = Achieve_applyService;