From c8d90f84cb3072ec80f1cc75c51f43176477fa95 Mon Sep 17 00:00:00 2001 From: Sergey Yarkov Date: Sun, 15 Aug 2021 23:11:06 +0300 Subject: [PATCH] feat: getByIdWithoutRelations in course repository --- app/Repositories/CourseRepository.ts | 25 ++++++++++++++++++++++--- app/Services/LessonService.ts | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/app/Repositories/CourseRepository.ts b/app/Repositories/CourseRepository.ts index 685be29..ef28045 100644 --- a/app/Repositories/CourseRepository.ts +++ b/app/Repositories/CourseRepository.ts @@ -49,8 +49,8 @@ export default class CourseRepository { .preload('teacher') .preload('category') .preload('lessons') - .preload('image'); - // .where('status', CourseStatusEnum.PUBLISHED); + .preload('image') + .where('status', CourseStatusEnum.PUBLISHED); return courses; } @@ -68,12 +68,31 @@ export default class CourseRepository { .preload('students') .preload('image') .where('id', id) - // .where('status', CourseStatusEnum.PUBLISHED) + .where('status', CourseStatusEnum.PUBLISHED) .first(); 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 { + 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 * diff --git a/app/Services/LessonService.ts b/app/Services/LessonService.ts index bdd0f3c..de16465 100644 --- a/app/Services/LessonService.ts +++ b/app/Services/LessonService.ts @@ -81,7 +81,7 @@ export default class LessonService { * @returns Response */ public async createLesson(data: CreateLessonValidator['schema']['props']): Promise { - const course = await this.courseRepository.getById(data.course_id); + const course = await this.courseRepository.getByIdWithoutRelations(data.course_id); if (!course) { return {