12345678910111213141516171819202122232425 |
- '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 RelationCoachSchoolService extends CrudService {
- constructor(ctx) {
- super(ctx, 'relationcoachschool');
- this.model = this.ctx.model.Relation.RelationCoachSchool;
- }
- // 创建关系前,先查下有没有,有就别创建了
- async beforeCreate(data) {
- const { coach_id, school_id } = data;
- const num = await this.model.count({ coach_id, school_id });
- if (num <= 0) {
- return data;
- }
- throw new BusinessError(ErrorCode.DATA_EXISTED, '教练已在学校备案,无需重复添加');
- }
- }
- module.exports = RelationCoachSchoolService;
|