|
@@ -1,19 +1,34 @@
|
|
|
-import { Provide } from '@midwayjs/decorator';
|
|
|
+import { Provide, Inject } from '@midwayjs/decorator';
|
|
|
import { InjectEntityModel } from '@midwayjs/typegoose';
|
|
|
import { ReturnModelType } from '@typegoose/typegoose';
|
|
|
-import { BaseService } from 'free-midway-component';
|
|
|
+import { BaseService, ServiceError } from 'free-midway-component';
|
|
|
import { Course } from '../../entity/core/course.entity';
|
|
|
import { get } from 'lodash';
|
|
|
import { Teacher } from '../../entity/core/teacher.entity';
|
|
|
+import { I18nService } from '../i18n.service';
|
|
|
+import { FrameErrorEnum } from '../../error/frame.error';
|
|
|
type modelType = ReturnModelType<typeof Course>;
|
|
|
@Provide()
|
|
|
export class CourseService extends BaseService<modelType> {
|
|
|
@InjectEntityModel(Course)
|
|
|
model: modelType;
|
|
|
|
|
|
+ @Inject()
|
|
|
+ i18n: I18nService;
|
|
|
+
|
|
|
@InjectEntityModel(Teacher)
|
|
|
tModel: ReturnModelType<typeof Teacher>;
|
|
|
|
|
|
+ // 创建前判断改教师是否审核成功
|
|
|
+ async createBefore(data) {
|
|
|
+ const { teacher } = data;
|
|
|
+ const teacherInfo = await this.tModel.findById(teacher).lean();
|
|
|
+ if (teacherInfo && teacherInfo._id) {
|
|
|
+ if (teacherInfo.status === '0') throw new ServiceError(this.i18n.translateError(FrameErrorEnum.TEACHER_STATUS), FrameErrorEnum.TEACHER_STATUS);
|
|
|
+ if (teacherInfo.is_show === '1') throw new ServiceError(this.i18n.translateError(FrameErrorEnum.TEACHER_SHOW), FrameErrorEnum.TEACHER_SHOW);
|
|
|
+ } else throw new ServiceError(this.i18n.translateError(FrameErrorEnum.USER_NOT_FOUND), FrameErrorEnum.USER_NOT_FOUND);
|
|
|
+ }
|
|
|
+
|
|
|
// 列表
|
|
|
async list(query) {
|
|
|
const { skip = 0, limit = 0, ...info } = query;
|