Skip to content

Commit

Permalink
feat: add lesson endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
wielopolski authored and piotr-pajak committed Dec 27, 2024
1 parent f285eae commit f6f0f89
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
2 changes: 1 addition & 1 deletion apps/api/src/lesson/lesson.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Body, Controller, Delete, Patch, Post, Query, UseGuards } from "@nestjs/common";
import { Body, Controller, Delete, Get, Param, Patch, Post, Query, UseGuards } from "@nestjs/common";
import { Type } from "@sinclair/typebox";
import { Validate } from "nestjs-typebox";

Expand Down
30 changes: 14 additions & 16 deletions apps/api/src/lesson/services/lesson.service.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { Inject, Injectable, NotFoundException } from "@nestjs/common";
import { and, eq, sql } from "drizzle-orm";
import { eq, sql } from "drizzle-orm";

import { DatabasePg } from "src/common";
import { FileService } from "src/file/file.service";
import {
chapters,
lessons,
questionAnswerOptions,
questions,
studentCourses,
} from "src/storage/schema";

import { LESSON_TYPES } from "../lesson.type";
Expand Down Expand Up @@ -144,19 +142,19 @@ export class LessonService {
// return true;
// }

async checkLessonAssignment(id: UUIDType, userId: UUIDType) {
return this.db
.select({
isAssigned: sql<boolean>`CASE WHEN ${studentCourses.id} IS NOT NULL THEN TRUE ELSE FALSE END`,
})
.from(lessons)
.leftJoin(chapters, eq(lessons.chapterId, chapters.id))
.leftJoin(
studentCourses,
and(eq(studentCourses.courseId, chapters.courseId), eq(studentCourses.studentId, userId)),
)
.where(and(eq(chapters.isPublished, true), eq(lessons.id, id)));
}
// async checkLessonAssignment(id: UUIDType, userId: UUIDType) {
// return this.db
// .select({
// isAssigned: sql<boolean>`CASE WHEN ${studentCourses.id} IS NOT NULL THEN TRUE ELSE FALSE END`,
// })
// .from(lessons)
// .leftJoin(chapters, eq(lessons.chapterId, chapters.id))
// .leftJoin(
// studentCourses,
// and(eq(studentCourses.courseId, chapters.courseId), eq(studentCourses.studentId, userId)),
// )
// .where(and(eq(chapters.isPublished, true), eq(lessons.id, id)));
// }

// private async evaluationsQuestions(courseId: UUIDType, lessonId: UUIDType, userId: UUIDType) {
// const lesson = await this.chapterRepository.getLessonForUser(courseId, lessonId, userId);
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/swagger/api-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -5761,4 +5761,4 @@
}
}
}
}
}

0 comments on commit f6f0f89

Please sign in to comment.