mirror of
https://github.com/sergeyyarkov/educt-server.git
synced 2026-10-11 18:29:15 +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('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
|
||||||
*
|
*
|
||||||
|
|||||||
@ -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 {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user