12345678910111213141516171819202122 |
- 'use strict';
- const { CrudService } = require('naf-framework-mongoose-free/lib/service');
- const { BusinessError, ErrorCode } = require('naf-core').Error;
- const _ = require('lodash');
- const assert = require('assert');
- //
- class RelationStudentSchoolService extends CrudService {
- constructor(ctx) {
- super(ctx, 'relationstudentschool');
- this.model = this.ctx.model.Relation.RelationStudentSchool;
- }
- // 创建关系前,先查下有没有,有就别创建了
- async beforeCreate(data) {
- const { student_id, school_id } = data;
- const num = await this.model.count({ student_id, school_id });
- if (num <= 0) { return data; }
- throw new BusinessError(ErrorCode.DATA_EXISTED, '学员已入学,无需重复添加');
- }
- }
- module.exports = RelationStudentSchoolService;
|