tryLessonApply.js 897 B

123456789101112131415161718192021222324252627
  1. 'use strict';
  2. const { CrudService } = require('naf-framework-mongoose-free/lib/service');
  3. const { BusinessError, ErrorCode } = require('naf-core').Error;
  4. const _ = require('lodash');
  5. const assert = require('assert');
  6. //
  7. class TryLessonApplyService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'trylessonapply');
  10. this.model = this.ctx.model.Apply.TryLessonApply;
  11. this.lessonStudentService = this.ctx.service.business.lessonStudent;
  12. }
  13. // 处理审核成功的情况
  14. async afterUpdate(filter, body, data) {
  15. const { status } = data;
  16. // 审核不通过, 不处理
  17. if (status !== '1') return data;
  18. // 通过,则需要在 lessonStudent中添加数据
  19. const obj = _.pick(data, [ 'school_id', 'lesson_id', 'student_id' ]);
  20. obj.is_try = '1';
  21. await this.lessonStudentService.create(obj);
  22. return data;
  23. }
  24. }
  25. module.exports = TryLessonApplyService;