feat: getByIdWithoutRelations in course repository

This commit is contained in:
Sergey Yarkov 2021-08-15 23:11:06 +03:00
parent 4cd2140e17
commit c8d90f84cb
2 changed files with 23 additions and 4 deletions

View File

@ -49,8 +49,8 @@ export default class CourseRepository {
.preload('teacher') .preload('teacher')
.preload('category') .preload('category')
.preload('lessons') .preload('lessons')
.preload('image'); .preload('image')
// .where('status', CourseStatusEnum.PUBLISHED); .where('status', CourseStatusEnum.PUBLISHED);
return courses; return courses;
} }
@ -68,12 +68,31 @@ export default class CourseRepository {
.preload('students') .preload('students')
.preload('image') .preload('image')
.where('id', id) .where('id', id)
// .where('status', CourseStatusEnum.PUBLISHED) .where('status', CourseStatusEnum.PUBLISHED)
.first(); .first();
return course; return course;
} }
/**
* Get course by id without relations
*
* @param id Course id
* @returns Course or null
*/
public async getByIdWithoutRelations(id: string | number, params?: any): Promise<Course | null> {
const { status }: any = params || {};
const query = this.Course.query().where('id', id);
if (status) {
query.where('status', status);
}
const course = await query.first();
return course;
}
/** /**
* Get likes count of course by id * Get likes count of course by id
* *

View File

@ -81,7 +81,7 @@ export default class LessonService {
* @returns Response * @returns Response
*/ */
public async createLesson(data: CreateLessonValidator['schema']['props']): Promise<IResponse> { public async createLesson(data: CreateLessonValidator['schema']['props']): Promise<IResponse> {
const course = await this.courseRepository.getById(data.course_id); const course = await this.courseRepository.getByIdWithoutRelations(data.course_id);
if (!course) { if (!course) {
return { return {