refactor: fetch courses by status

This commit is contained in:
Sergey Yarkov 2021-10-13 20:05:58 +03:00
parent 1a86fda94b
commit 30fdfa08b6

View File

@ -47,16 +47,18 @@ export default class CourseRepository {
* @returns List of courses
*/
public async getAll(params?: FetchCoursesValidator['schema']['props']): Promise<Course[]> {
const { status = CourseStatusEnum.PUBLISHED, category_id } = params || {};
const { status, category_id } = params || {};
const query = this.Course.query();
query.where('status', status);
if (category_id) {
query.andWhereHas('category', q => q.where('id', category_id));
}
if (status) {
query.andWhere('status', status);
}
const courses = await query
.preload('category')
.preload('image')