job.js 997 B

123456789101112131415161718192021222324252627282930313233343536373839
  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 JobService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'job');
  10. this.model = this.ctx.model.Job;
  11. this.smodel = this.ctx.model.Student;
  12. }
  13. async update({ id }, data) {
  14. const job = await this.model.findById(id);
  15. if (!job) {
  16. throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '任务信息不存在');
  17. }
  18. job.isstore = data.isstore;
  19. const res = await job.save();
  20. if (res) {
  21. console.log(11111111);
  22. if (data.isstore === '1') {
  23. console.log('&&&&&&&&&&&&');
  24. const studatas = JSON.parse(job.studs);
  25. for (const stu of studatas) {
  26. await this.smodel.create(stu);
  27. }
  28. }
  29. }
  30. return res;
  31. }
  32. }
  33. module.exports = JobService;