mirror of
https://github.com/sergeyyarkov/educt-server.git
synced 2026-10-11 10:19:20 +03:00
feat: getByIdWithoutRelations in course repository
This commit is contained in:
parent
4cd2140e17
commit
c8d90f84cb
@ -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<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
|
||||
*
|
||||
|
||||
@ -81,7 +81,7 @@ export default class LessonService {
|
||||
* @returns Response
|
||||
*/
|
||||
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) {
|
||||
return {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user