123456789101112131415161718192021222324252627282930313233343536373839 |
- 'use strict';
- const assert = require('assert');
- const _ = require('lodash');
- const { ObjectId } = require('mongoose').Types;
- const { CrudService } = require('naf-framework-mongoose/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- class JobService extends CrudService {
- constructor(ctx) {
- super(ctx, 'job');
- this.model = this.ctx.model.Job;
- this.smodel = this.ctx.model.Student;
- }
- async update({ id }, data) {
- const job = await this.model.findById(id);
- if (!job) {
- throw new BusinessError(ErrorCode.DATA_NOT_EXIST, '任务信息不存在');
- }
- job.isstore = data.isstore;
- const res = await job.save();
- if (res) {
- console.log(11111111);
- if (data.isstore === '1') {
- console.log('&&&&&&&&&&&&');
- const studatas = JSON.parse(job.studs);
- for (const stu of studatas) {
- await this.smodel.create(stu);
- }
- }
- }
- return res;
- }
- }
- module.exports = JobService;
|