Skip to content

Commit

Permalink
fix: read only children
Browse files Browse the repository at this point in the history
  • Loading branch information
AcipenserSturio committed Nov 12, 2024
1 parent 0dc6335 commit 27a77e0
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/repos/lesson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ const READ = `
WHERE lesson_id = ($1);
`;

const READ_BY_COURSE = `
SELECT *
FROM v1.lessons
WHERE lesson_course = ($1);
`;

const READ_ALL = `
SELECT *
FROM v1.lessons;
Expand All @@ -32,6 +38,10 @@ export class LessonsRepository {
return await this.db.oneOrNone(READ, id);
}

async readByCourse(courseId: string): Promise<LessonsT[] | null> {
return await this.db.manyOrNone(READ_BY_COURSE, courseId);
}

async readAll(): Promise<LessonsT[] | null> {
return await this.db.any(READ_ALL);
}
Expand Down
10 changes: 10 additions & 0 deletions src/repos/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ const READ = `
WHERE task_id = ($1);
`;

const READ_BY_LESSON = `
SELECT *
FROM v1.tasks
WHERE task_lesson = ($1);
`;

const READ_ALL = `
SELECT *
FROM v1.tasks;
Expand Down Expand Up @@ -34,6 +40,10 @@ export class TasksRepository {
return await this.db.oneOrNone(READ, id);
}

async readByLesson(lessonId: string): Promise<TasksT[] | null> {
return await this.db.manyOrNone(READ_BY_LESSON, lessonId);
}

async readAll(): Promise<TasksT[] | null> {
return await this.db.any(READ_ALL);
}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/app/lessons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ export async function getLessons(
}

// TODO: implement availability based on user progress
let lessons = await db.lessons.readAll();
let lessons = await db.lessons.readByCourse(body.courseId);
return apiSuccess(res, 200, { lessons: lessons });
}
2 changes: 1 addition & 1 deletion src/routes/app/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export async function getTasks(
return apiError(res, 400, ApiResponseCode.LessonNotFound);
}

let tasks = await db.tasks.readAll();
let tasks = await db.tasks.readByLesson(body.lessonId);
// TODO: figure out what data to show/hide.
// TODO: Handle task types.
return apiSuccess(res, 200, { tasks: tasks });
Expand Down

0 comments on commit 27a77e0

Please sign in to comment.