Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 490 curriculum styles #304

Merged
merged 5 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions apps/api/src/chapter/adminChapter.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { chapters } from "src/storage/schema";

import { AdminChapterRepository } from "./repositories/adminChapter.repository";

import type { CreateChapterBody } from "./schemas/chapter.schema";
import type { CreateChapterBody, UpdateChapterBody } from "./schemas/chapter.schema";
import type { UUIDType } from "src/common";

@Injectable()
Expand Down Expand Up @@ -237,11 +237,12 @@ export class AdminChapterService {
newDisplayOrder,
);
}
// async updateLesson(id: string, body: UpdateLessonBody) {
// const [lesson] = await this.adminChapterRepository.updateLesson(id, body);

// if (!lesson) throw new NotFoundException("Lesson not found");
// }
async updateChapter(id: string, body: UpdateChapterBody) {
const [chapter] = await this.adminChapterRepository.updateChapter(id, body);

if (!chapter) throw new NotFoundException("Lesson not found");
}

// async toggleLessonAsFree(courseId: UUIDType, lessonId: UUIDType, isFree: boolean) {
// return await this.adminChapterRepository.toggleLessonAsFree(courseId, lessonId, isFree);
Expand Down
29 changes: 28 additions & 1 deletion apps/api/src/chapter/chapter.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ import { ChapterService } from "./chapter.service";
import {
CreateChapterBody,
createChapterSchema,
showChapterSchema,
UpdateChapterBody,
updateChapterSchema,
showChapterSchema
} from "./schemas/chapter.schema";

import type { ShowChapterResponse } from "./schemas/chapter.schema";
Expand Down Expand Up @@ -89,6 +91,31 @@ export class ChapterController {
return new BaseResponse({ id, message: "Chapter created successfully" });
}

@Patch()
@Roles(USER_ROLES.TEACHER, USER_ROLES.ADMIN)
@Validate({
request: [
{
type: "query",
name: "id",
schema: UUIDSchema,
},
{
type: "body",
schema: updateChapterSchema,
},
],
response: baseResponse(Type.Object({ message: Type.String() })),
})
async updateChapter(
@Query("id") id: UUIDType,
@Body() updateChapterBody: UpdateChapterBody,
): Promise<BaseResponse<{ message: string }>> {
await this.adminChapterService.updateChapter(id, updateChapterBody);

return new BaseResponse({ message: "Chapter updated successfully" });
}

@Patch("chapter-display-order")
@Roles(USER_ROLES.TEACHER, USER_ROLES.ADMIN)
@Validate({
Expand Down
7 changes: 4 additions & 3 deletions apps/api/src/chapter/repositories/adminChapter.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { and, eq, gte, lte, sql } from "drizzle-orm";
import { DatabasePg, type UUIDType } from "src/common";
import { chapters, lessons, questionAnswerOptions, questions } from "src/storage/schema";

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 * as schema from "src/storage/schema";
Expand Down Expand Up @@ -302,9 +303,9 @@ export class AdminChapterRepository {
// .returning();
// }

// async updateLesson(id: string, body: UpdateLessonBody) {
// return await this.db.update(lessons).set(body).where(eq(lessons.id, id)).returning();
// }
async updateChapter(id: string, body: UpdateChapterBody) {
return await this.db.update(chapters).set(body).where(eq(chapters.id, id)).returning();
}

// async getLessonsCount(conditions: any[]) {
// return await this.db
Expand Down
110 changes: 110 additions & 0 deletions apps/api/src/swagger/api-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1798,6 +1798,41 @@
}
}
},
"patch": {
"operationId": "ChapterController_updateChapter",
"parameters": [
{
"name": "id",
"required": false,
"in": "query",
"schema": {
"format": "uuid",
"type": "string"
}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UpdateChapterBody"
}
}
}
},
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/UpdateChapterResponse"
}
}
}
}
}
},
"delete": {
"operationId": "ChapterController_removeChapter",
"parameters": [
Expand Down Expand Up @@ -5138,6 +5173,81 @@
"data"
]
},
"UpdateChapterBody": {
"type": "object",
"allOf": [
{
"type": "object",
"properties": {
"title": {
"type": "string"
},
"chapterProgress": {
"anyOf": [
{
"const": "completed",
"type": "string"
},
{
"const": "in_progress",
"type": "string"
},
{
"const": "not_started",
"type": "string"
}
]
},
"isFreemium": {
"type": "boolean"
},
"enrolled": {
"type": "boolean"
},
"isPublished": {
"type": "boolean"
},
"isSubmitted": {
"type": "boolean"
},
"createdAt": {
"type": "string"
},
"quizCount": {
"type": "number"
}
}
},
{
"type": "object",
"properties": {
"courseId": {
"format": "uuid",
"type": "string"
}
}
}
]
},
"UpdateChapterResponse": {
"type": "object",
"properties": {
"data": {
"type": "object",
"properties": {
"message": {
"type": "string"
}
},
"required": [
"message"
]
}
},
"required": [
"data"
]
},
"UpdateChapterDisplayOrderBody": {
"type": "object",
"properties": {
Expand Down
46 changes: 46 additions & 0 deletions apps/web/app/api/generated-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,26 @@ export interface BetaCreateChapterResponse {
};
}

export type UpdateChapterBody = {
title?: string;
chapterProgress?: "completed" | "in_progress" | "not_started";
isFreemium?: boolean;
enrolled?: boolean;
isPublished?: boolean;
isSubmitted?: boolean;
createdAt?: string;
quizCount?: number;
} & {
/** @format uuid */
courseId?: string;
};

export interface UpdateChapterResponse {
data: {
message: string;
};
}

export interface UpdateChapterDisplayOrderBody {
/** @format uuid */
chapterId: string;
Expand Down Expand Up @@ -1667,6 +1687,8 @@ export class API<SecurityDataType extends unknown> extends HttpClient<SecurityDa
*/
courseControllerGetStudentCourses: (
query?: {
/** @format uuid */
excludeCourseId?: string;
title?: string;
category?: string;
author?: string;
Expand Down Expand Up @@ -2078,6 +2100,30 @@ export class API<SecurityDataType extends unknown> extends HttpClient<SecurityDa
...params,
}),

/**
* No description
*
* @name ChapterControllerUpdateChapter
* @request PATCH:/api/chapter
*/
chapterControllerUpdateChapter: (
data: UpdateChapterBody,
query?: {
/** @format uuid */
id?: string;
},
params: RequestParams = {},
) =>
this.request<UpdateChapterResponse, any>({
path: `/api/chapter`,
method: "PATCH",
query: query,
body: data,
type: ContentType.Json,
format: "json",
...params,
}),

/**
* No description
*
Expand Down
42 changes: 42 additions & 0 deletions apps/web/app/api/mutations/admin/useUpdateChapter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { useMutation } from "@tanstack/react-query";
import { AxiosError } from "axios";

import { useToast } from "~/components/ui/use-toast";

import { ApiClient } from "../../api-client";

import type { UpdateChapterBody } from "../../generated-api";

type UpdateChapterOptions = {
chapterId: string;
data: UpdateChapterBody;
};

export function useUpdateChapter() {
const { toast } = useToast();

return useMutation({
mutationFn: async (options: UpdateChapterOptions) => {
const response = await ApiClient.api.chapterControllerUpdateChapter(options.data, {
id: options.chapterId,
});

return response.data;
},
onSuccess: () => {
toast({ description: "Chapter updated successfully" });
},
onError: (error) => {
if (error instanceof AxiosError) {
return toast({
description: error.response?.data.message,
variant: "destructive",
});
}
toast({
description: error.message,
variant: "destructive",
});
},
});
}
3 changes: 3 additions & 0 deletions apps/web/app/assets/svgs/eye.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions apps/web/app/assets/svgs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export { default as Checkmark } from "./checkmark.svg?react";
export { default as Flame } from "./flame.svg?react";
export { default as FreeRight } from "./free-right.svg?react";
export { default as NoData } from "./no-data.svg?react";
export { default as Eye } from "./eye.svg?react";

export * from "./lesson-types";
export * from "./arrows";
Expand Down
15 changes: 11 additions & 4 deletions apps/web/app/components/ui/checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,28 @@ import { cn } from "~/lib/utils";

const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root> & { isSquareCheck?: boolean }
>(({ className, isSquareCheck, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
isSquareCheck
? "mb-1 border border-primary-700 rounded-sm h-4 w-4 shrink-0 flex items-center justify-center align-middle"
: "peer h-4 w-4 shrink-0 rounded-sm border border-primary ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
className,
)}
{...props}
>
<CheckboxPrimitive.Indicator className={cn("flex items-center justify-center text-current")}>
<Check className="h-4 w-4" />
{isSquareCheck ? (
<div className="h-4 w-4 bg-primary-700 border-[2.5px] border-white rounded-sm" />
) : (
<Check className="h-4 w-4" />
)}
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
));

Checkbox.displayName = CheckboxPrimitive.Root.displayName;

export { Checkbox };
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { match } from "ts-pattern";
import { QuestionType } from "./NewLesson/QuizLessonForm/QuizLessonForm.types";

export const mapItemType = (itemType: string | undefined): string =>
match(itemType)
Expand All @@ -15,3 +16,14 @@ export const mapTypeToIcon = (itemType: string): string =>
.with("presentation", () => "Presentation")
.with("question", () => "Quiz")
.otherwise(() => "Quiz");

export const mapQuestionTypeToLabel = (questionType: QuestionType): string =>
match(questionType)
.with(QuestionType.SINGLE_CHOICE, () => "Single Select")
.with(QuestionType.MULTIPLE_CHOICE, () => "Multiple Select")
.with(QuestionType.TRUE_OR_FALSE, () => "True or False")
.with(QuestionType.BRIEF_RESPONSE, () => "Brief Response")
.with(QuestionType.DETAILED_RESPONSE, () => "Detailed Response")
.with(QuestionType.PHOTO_QUESTION, () => "Photo Question")
.with(QuestionType.FILL_IN_THE_BLANKS, () => "Fill in the Blanks")
.otherwise(() => "");
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ const CourseLessons = ({ chapters, canRefetchChapterList }: CourseLessonsProps)
setContentTypeToDisplay={setContentTypeToDisplay}
setSelectedChapter={setSelectedChapter}
setSelectedLesson={setSelectedLesson}
selectedChapter={selectedChapter}
selectedLesson={selectedLesson}
/>
</div>
<Button
Expand Down
Loading
Loading