achieve_apply.js 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. 'use strict';
  2. const { CrudService } = require('naf-framework-mongoose/lib/service');
  3. const { BusinessError, ErrorCode } = require('naf-core').Error;
  4. const _ = require('lodash');
  5. const assert = require('assert');
  6. const { ObjectId } = require('mongoose').Types;
  7. // 成果评价申请
  8. class Achieve_applyService extends CrudService {
  9. constructor(ctx) {
  10. super(ctx, 'achieve_apply');
  11. this.model = this.ctx.model.AchieveApply;
  12. }
  13. async getOne(query) {
  14. const keys = Object.keys(query);
  15. if (keys.length <= 0) throw new BusinessError(ErrorCode.BADPARAM, '缺少参数');
  16. const res = await this.model.findOne(query);
  17. return res;
  18. }
  19. async researchCreate({ id }, body) {
  20. const res = await this.model.findById(id);
  21. if (!res) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到成果评价申请数据');
  22. res.research.push(body);
  23. await res.save();
  24. return;
  25. }
  26. async researchUpdate({ id, research_id }, body) {
  27. const res = await this.model.findById(id);
  28. if (!res) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到成果评价申请数据');
  29. const person = res.research.id(research_id);
  30. if (!person) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到该申请下指定的主研人员');
  31. const keys = Object.keys(body);
  32. for (const key of keys) {
  33. person[key] = body[key];
  34. }
  35. await res.save();
  36. }
  37. async researchDelete({ id, research_id }) {
  38. const res = await this.model.findById(id);
  39. if (!res) throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '未找到成果评价申请数据');
  40. res.research.remove(research_id);
  41. await res.save();
  42. }
  43. }
  44. module.exports = Achieve_applyService;