schtime.js 933 B

123456789101112131415161718192021222324252627282930313233343536
  1. 'use strict';
  2. const assert = require('assert');
  3. const _ = require('lodash');
  4. const { ObjectId } = require('mongoose').Types;
  5. const { CrudService } = require('naf-framework-mongoose/lib/service');
  6. const { BusinessError, ErrorCode } = require('naf-core').Error;
  7. class SchtimeService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'schtime');
  10. this.model = this.ctx.model.Schtime;
  11. }
  12. async updateschtimes(data) {
  13. assert(data, '缺少信息项');
  14. for (const elm of data) {
  15. const schtime = await this.model.findById(elm.id);
  16. if (schtime) {
  17. schtime.schid = elm.schid;
  18. schtime.year = elm.year;
  19. schtime.planid = elm.planid;
  20. schtime.remark = elm.remark;
  21. schtime.daterange = elm.daterange;
  22. schtime.term.splice(0, schtime.term.length);
  23. schtime.term = elm.term;
  24. await schtime.save();
  25. }
  26. }
  27. }
  28. }
  29. module.exports = SchtimeService;