mirror of
https://github.com/sergeyyarkov/educt-server.git
synced 2026-10-11 10:19:20 +03:00
refactor: fetch courses by status
This commit is contained in:
parent
1a86fda94b
commit
30fdfa08b6
@ -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')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user