'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) { if (data.isstore === '1') { const studatas = JSON.parse(job.studs); for (const stu of studatas) { await this.smodel.create(stu); } } } return res; } } module.exports = JobService;