student.js 719 B

1234567891011121314151617181920212223
  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 StudentService extends CrudService {
  8. constructor(ctx) {
  9. super(ctx, 'student');
  10. this.model = this.ctx.model.User.Student;
  11. this.rssModel = this.ctx.model.Relation.RelationStudentSchool;
  12. }
  13. async afterCreate(body, data) {
  14. if (!_.get(body, 'school_id')) return data;
  15. const { _id: student_id } = data;
  16. const obj = { school_id: _.get(body, 'school_id'), student_id };
  17. await this.rssModel.create(obj);
  18. return data;
  19. }
  20. }
  21. module.exports = StudentService;