Skip to content

Commit

Permalink
feat: add display order and types to lesson response
Browse files Browse the repository at this point in the history
  • Loading branch information
wielopolski committed Dec 23, 2024
1 parent 12fc5ed commit bb2d39d
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 40 deletions.
4 changes: 2 additions & 2 deletions apps/api/src/chapter/adminChapter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class AdminChapterService {
// },
// };
// }
// async processLessonItems(lessonItemsList: LessonItemWithContentSchema[]) {
// async processLessonItems(lessonItemsList: AdminLessonWithContentSchema[]) {
// const getFileUrl = async (url: string) => {
// if (!url || url.startsWith("https://")) return url;
// return await this.s3Service.getSignedUrl(url);
Expand Down Expand Up @@ -123,7 +123,7 @@ export class AdminChapterService {

// const lessonItemsList = await this.adminChapterRepository.getLessonItems(id);

// const items = await this.processLessonItems(lessonItemsList as LessonItemWithContentSchema[]);
// const items = await this.processLessonItems(lessonItemsList as AdminLessonWithContentSchema[]);

// return {
// ...lesson,
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/chapter/repositories/adminChapter.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { chapters, lessons, questionAnswerOptions, questions } from "src/storage

import type { UpdateChapterBody } from "../schemas/chapter.schema";
import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
import type { LessonItemWithContentSchema, QuestionSchema } from "src/lesson/lesson.schema";
import type { AdminLessonWithContentSchema, QuestionSchema } from "src/lesson/lesson.schema";
import type * as schema from "src/storage/schema";

@Injectable()
Expand Down Expand Up @@ -209,7 +209,7 @@ export class AdminChapterRepository {
// // : await this.fileService.getFileUrl(lesson.imageUrl),
// // };

async getBetaChapterLessons(chapterId: UUIDType): Promise<LessonItemWithContentSchema[]> {
async getBetaChapterLessons(chapterId: UUIDType): Promise<AdminLessonWithContentSchema[]> {
return await this.db
.select({
updatedAt: sql<string>`${lessons.updatedAt}`,
Expand Down
6 changes: 3 additions & 3 deletions apps/api/src/courses/course.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import type { CommonShowCourse } from "./schemas/showCourseCommon.schema";
import type { UpdateCourseBody } from "./schemas/updateCourse.schema";
import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
import type { Pagination, UUIDType } from "src/common";
import type { LessonItemWithContentSchema } from "src/lesson/lesson.schema";
import type { AdminLessonWithContentSchema } from "src/lesson/lesson.schema";
import type * as schema from "src/storage/schema";
import type { ProgressStatus } from "src/utils/types/progress.type";

Expand Down Expand Up @@ -490,7 +490,7 @@ export class CourseService {

const updatedCourseLessonList = await Promise.all(
courseChapterList?.map(async (chapter) => {
const lessons: LessonItemWithContentSchema[] =
const lessons: AdminLessonWithContentSchema[] =
await this.adminChapterRepository.getBetaChapterLessons(chapter.id);

const lessonsWithSignedUrls = await this.addS3SignedUrlsToLessonsAndQuestions(lessons);
Expand Down Expand Up @@ -928,7 +928,7 @@ export class CourseService {
);
}

private async addS3SignedUrlsToLessonsAndQuestions(lessons: LessonItemWithContentSchema[]) {
private async addS3SignedUrlsToLessonsAndQuestions(lessons: AdminLessonWithContentSchema[]) {
return await Promise.all(
lessons.map(async (lesson) => {
const updatedLesson = { ...lesson };
Expand Down
3 changes: 1 addition & 2 deletions apps/api/src/lesson/lesson.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ import {
import { AdminLessonService } from "./services/adminLesson.service";
import { LessonService } from "./services/lesson.service";

import type {
LessonShow} from "./lesson.schema";
import type { LessonShow } from "./lesson.schema";

@Controller("lesson")
@UseGuards(RolesGuard)
Expand Down
11 changes: 6 additions & 5 deletions apps/api/src/lesson/lesson.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Type } from "@sinclair/typebox";

import { UUIDSchema } from "src/common";

import { PhotoQuestionType, QuestionType } from "./lesson.type";
import { LESSON_TYPES, PhotoQuestionType, QuestionType } from "./lesson.type";

import type { Static } from "@sinclair/typebox";

Expand All @@ -24,7 +24,6 @@ export const questionSchema = Type.Object({
});

export const lessonSchema = Type.Object({
updatedAt: Type.Optional(Type.String()),
id: UUIDSchema,
title: Type.String(),
type: Type.String(),
Expand All @@ -33,6 +32,7 @@ export const lessonSchema = Type.Object({
fileS3Key: Type.Optional(Type.String()),
fileType: Type.Optional(Type.String()),
questions: Type.Optional(Type.Array(questionSchema)),
updatedAt: Type.Optional(Type.String()),
});

const lessonQuizSchema = Type.Object({
Expand All @@ -46,7 +46,7 @@ const lessonQuizSchema = Type.Object({
questions: Type.Optional(Type.Array(questionSchema)),
});

export const lessonItemSchema = Type.Object({
export const adminLessonSchema = Type.Object({
id: UUIDSchema,
type: Type.String(),
displayOrder: Type.Number(),
Expand Down Expand Up @@ -84,17 +84,18 @@ export const questionDetails = Type.Object({
export const lessonShowSchema = Type.Object({
id: UUIDSchema,
title: Type.String(),
type: Type.String(),
type: Type.Enum(LESSON_TYPES),
description: Type.String(),
fileType: Type.Union([Type.String(), Type.Null()]),
fileUrl: Type.Union([Type.String(), Type.Null()]),
quizDetails: Type.Optional(questionDetails),
displayOrder: Type.Number(),
});

export const updateLessonSchema = Type.Partial(createLessonSchema);
export const updateQuizLessonSchema = Type.Partial(createQuizLessonSchema);

export type LessonItemWithContentSchema = Static<typeof lessonItemSchema>;
export type AdminLessonWithContentSchema = Static<typeof adminLessonSchema>;
export type CreateLessonBody = Static<typeof createLessonSchema>;
export type UpdateLessonBody = Static<typeof updateLessonSchema>;
export type UpdateQuizLessonBody = Static<typeof updateQuizLessonSchema>;
Expand Down
9 changes: 5 additions & 4 deletions apps/api/src/lesson/services/lesson.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,29 @@ import {

import { LESSON_TYPES } from "../lesson.type";


import type { LessonShow, OptionBody, QuestionBody } from "../lesson.schema";
import type { PhotoQuestionType, QuestionType } from "../lesson.type";
import type { LessonTypes, PhotoQuestionType, QuestionType } from "../lesson.type";
import type { UUIDType } from "src/common";

@Injectable()
export class LessonService {
constructor(
@Inject("DB") private readonly db: DatabasePg,
private readonly fileService: FileService, // TODO: add event bus
) {
// private readonly eventBus: EventBus,
) {}
}

async getLessonById(id: UUIDType): Promise<LessonShow> {
const [lesson] = await this.db
.select({
id: lessons.id,
type: lessons.type,
type: sql<LessonTypes>`${lessons.type}`,
title: lessons.title,
description: sql<string>`${lessons.description}`,
fileUrl: lessons.fileS3Key,
fileType: lessons.fileType,
displayOrder: sql<number>`${lessons.displayOrder}`,
})
.from(lessons)
.where(eq(lessons.id, id));
Expand Down
2 changes: 1 addition & 1 deletion apps/api/src/scorm/services/scorm.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import { AdminChapterService } from "src/chapter/adminChapter.service";
import { DatabasePg } from "src/common";
import { FileService } from "src/file/file.service";
import { LESSON_TYPES } from "src/lesson/lesson.type";
import { AdminLessonService } from "src/lesson/services/adminLesson.service";
import { S3Service } from "src/s3/s3.service";

import { SCORM } from "../constants/scorm.consts";
import { ScormRepository } from "../repositories/scorm.repository";

import type { UUIDType } from "src/common";
import { AdminLessonService } from "src/lesson/services/adminLesson.service";

type ScormChapter = {
title: string;
Expand Down
16 changes: 7 additions & 9 deletions apps/api/src/seed/nice-data-seeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1476,7 +1476,7 @@ export const niceCourses: NiceCourseData[] = [
{
title: "Understanding AI Basics",
isPublished: true,
isFreemium: true,
isFreemium: false,
displayOrder: 1,
lessons: [
{
Expand All @@ -1490,7 +1490,7 @@ export const niceCourses: NiceCourseData[] = [
type: LESSON_TYPES.TEXT,
title: "Key Concepts and Terminologies in AI",
description:
"Learn the foundational terminologies of AI, including Machine Learning, Neural Networks, NLP, and more.",
'<p>Artificial Intelligence (AI) refers to the simulation of human intelligence in machines programmed to think, learn, and make decisions. Below are some key concepts and terminologies essential to understanding AI:</p>\n\n<ul>\n<li><strong>Machine Learning (ML):</strong> A subset of AI focused on creating algorithms that allow computers to learn from and make predictions based on data. Example: A recommendation system suggesting movies based on your viewing history.</li>\n<li><strong>Neural Networks:</strong> Inspired by the human brain, these are algorithms designed to recognize patterns and process data in layers, enabling tasks like image and speech recognition.</li>\n<li><strong>Natural Language Processing (NLP):</strong> This involves teaching machines to understand, interpret, and generate human language. Example: Virtual assistants like Alexa or Siri.</li>\n<li><strong>Computer Vision:</strong> A field of AI that enables computers to interpret and process visual data, such as images and videos. Example: Facial recognition technology.</li>\n<li><strong>Deep Learning:</strong> A more complex subset of ML that uses large neural networks to analyze massive amounts of data and solve intricate problems, such as self-driving cars.</li>\n<li><strong>Supervised vs. Unsupervised Learning:</strong><br>- <strong>Supervised Learning:</strong> The AI is trained on labeled data (e.g., images labeled as "cat" or "dog").<br>- <strong>Unsupervised Learning:</strong> The AI identifies patterns in unlabeled data without explicit instructions.</li>\n<li><strong>Big Data:</strong> The large volume of structured and unstructured data generated by businesses and devices, which is essential for training AI models.</li>\n<li><strong>Automation:</strong> AI is often used to automate repetitive tasks, freeing up human resources for more complex activities.</li>\n<li><strong>Ethics in AI:</strong> As AI becomes more powerful, ensuring its ethical use (e.g., avoiding bias in decision-making) is critical for building trust.</li>\n</ul>\n\n<h3>Why These Concepts Matter</h3>\n<p>Understanding these basic AI terms is the first step toward recognizing how AI can be applied in business. Each concept represents a building block of AI\'s potential to transform industries by increasing efficiency, improving decision-making, and creating innovative solutions.</p>',
displayOrder: 2,
},
{
Expand All @@ -1512,9 +1512,9 @@ export const niceCourses: NiceCourseData[] = [
title: "What is the primary goal of AI in business?",
options: [
{ optionText: "Replace human workers", isCorrect: false, position: 0 },
{ optionText: "Fully automate all tasks", isCorrect: false, position: 1 },
{ optionText: "Automate repetitive tasks", isCorrect: false, position: 1 },
{ optionText: "Improve decision-making", isCorrect: true, position: 2 },
{ optionText: "Eliminate all business costs", isCorrect: false, position: 3 },
{ optionText: "Eliminate operational costs", isCorrect: false, position: 3 },
],
},
],
Expand Down Expand Up @@ -1581,13 +1581,11 @@ export const niceCourses: NiceCourseData[] = [
type: QuestionType.FillInTheBlanks,
title:
"Complete the blanks: Artificial [word] refers to the ability of machines to mimic [word] intelligence.",
description:
"<p>Complete the blanks: Artificial <strong>Intelligence</strong> refers to the ability of machines to mimic <strong>Human</strong> intelligence.</p>",
options: [
{ optionText: "Intelligence", isCorrect: true, position: 0 },
{ optionText: "Human", isCorrect: true, position: 1 },
{ optionText: "Automation", isCorrect: false, position: 2 },
{ optionText: "Learning", isCorrect: false, position: 3 },
{ optionText: "Automation", isCorrect: false, position: 1 },
{ optionText: "Learning", isCorrect: false, position: 2 },
{ optionText: "Human", isCorrect: true, position: 3 },
{ optionText: "Animal", isCorrect: false, position: 4 },
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import { PROGRESS_STATUSES } from "src/utils/types/progress.type";
import type { UUIDType } from "src/common";
import type { ProgressStatus } from "src/utils/types/progress.type";


@Injectable()
export class StudentLessonProgressService {
constructor(
Expand Down
47 changes: 36 additions & 11 deletions apps/api/src/swagger/api-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4251,7 +4251,28 @@
"type": "string"
},
"type": {
"type": "string"
"anyOf": [
{
"const": "text",
"type": "string"
},
{
"const": "file",
"type": "string"
},
{
"const": "presentation",
"type": "string"
},
{
"const": "video",
"type": "string"
},
{
"const": "quiz",
"type": "string"
}
]
},
"description": {
"type": "string"
Expand Down Expand Up @@ -4324,6 +4345,9 @@
"wrongAnswerCount",
"score"
]
},
"displayOrder": {
"type": "number"
}
},
"required": [
Expand All @@ -4332,7 +4356,8 @@
"type",
"description",
"fileType",
"fileUrl"
"fileUrl",
"displayOrder"
]
}
},
Expand All @@ -4346,9 +4371,6 @@
{
"type": "object",
"properties": {
"updatedAt": {
"type": "string"
},
"title": {
"type": "string"
},
Expand Down Expand Up @@ -4458,6 +4480,9 @@
"title"
]
}
},
"updatedAt": {
"type": "string"
}
},
"required": [
Expand Down Expand Up @@ -4827,9 +4852,6 @@
{
"type": "object",
"properties": {
"updatedAt": {
"type": "string"
},
"title": {
"type": "string"
},
Expand Down Expand Up @@ -4939,6 +4961,9 @@
"title"
]
}
},
"updatedAt": {
"type": "string"
}
}
},
Expand Down Expand Up @@ -5090,9 +5115,6 @@
"items": {
"type": "object",
"properties": {
"updatedAt": {
"type": "string"
},
"id": {
"format": "uuid",
"type": "string"
Expand Down Expand Up @@ -5209,6 +5231,9 @@
"title"
]
}
},
"updatedAt": {
"type": "string"
}
},
"required": [
Expand Down

0 comments on commit bb2d39d

Please sign in to comment.