Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-pajak committed Nov 8, 2024
1 parent d0e83b4 commit 51c1640
Show file tree
Hide file tree
Showing 20 changed files with 269 additions and 24 deletions.
13 changes: 12 additions & 1 deletion apps/api/src/lessons/adminLessonItems.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,18 @@ export class AdminLessonItemsService {
throw new ConflictException("Question already answered");
}

return await this.adminLessonItemsRepository.updateQuestionItem(id, body);
await this.adminLessonItemsRepository.updateQuestionItem(id, body);

if (!body?.questionAnswers) {
return;
}

for (const { isCorrect, ...restAnswer } of body.questionAnswers) {
await this.adminLessonItemsRepository.addQuestionAnswerOption({
isCorrect: isCorrect ?? false,
...restAnswer,
});
}
}

async updateFileItem(id: UUIDType, body: UpdateFileBody) {
Expand Down
1 change: 1 addition & 0 deletions apps/api/src/lessons/api/lessons.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,7 @@ export class LessonsController {
@Body() body: UpdateQuestionBody,
): Promise<BaseResponse<{ message: string }>> {
await this.adminLessonItemsService.updateQuestionItem(id, body);

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

Expand Down
31 changes: 26 additions & 5 deletions apps/api/src/lessons/repositories/adminLessonItems.repository.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Inject, Injectable } from "@nestjs/common";
import { eq, and, inArray } from "drizzle-orm";
import { and, eq, inArray } from "drizzle-orm";

import { DatabasePg, type UUIDType } from "src/common";
import { DatabasePg } from "src/common";
import {
lessonItems,
files,
questions,
textBlocks,
lessonItems,
questionAnswerOptions,
questions,
studentQuestionAnswers,
textBlocks,
} from "src/storage/schema";

import type {
Expand All @@ -19,6 +19,7 @@ import type {
UpdateTextBlockBody,
} from "../schemas/lessonItem.schema";
import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
import type { UUIDType } from "src/common";
import type * as schema from "src/storage/schema";

@Injectable()
Expand Down Expand Up @@ -256,4 +257,24 @@ export class AdminLessonItemsRepository {
},
});
}

async addQuestionAnswerOption(answer: {
isStudentAnswer?: boolean;
isCorrect: boolean;
optionText: string;
position: number | null;
questionId: string;
}): Promise<void> {
console.log({ mariusz: answer });
const result = await this.db
.insert(questionAnswerOptions)
.values(answer)
.onConflictDoUpdate({
target: questionAnswerOptions.id,
set: answer,
})
.returning();

console.log({ result });
}
}
3 changes: 1 addition & 2 deletions apps/api/src/swagger/api-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,9 @@
"parameters": [
{
"name": "userId",
"required": false,
"required": true,
"in": "query",
"schema": {
"format": "uuid",
"type": "string"
}
}
Expand Down
5 changes: 2 additions & 3 deletions apps/api/src/users/api/users.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ import { deleteUsersSchema, type DeleteUsersSchema } from "../schemas/delete-use
import { type UpdateUserBody, updateUserSchema } from "../schemas/update-user.schema";
import { USER_ROLES } from "../schemas/user-roles";
import {
type AllUsersResponse,
allUsersSchema,
type UserDetails,
userDetailsSchema,
type AllUsersResponse,
type UserResponse,
type UserDetails,
} from "../schemas/user.schema";
import { SortUserFieldsOptions } from "../schemas/userQuery";
import { UsersService } from "../users.service";
Expand Down Expand Up @@ -120,7 +120,6 @@ export class UsersController {
@Get("user-details")
@Validate({
response: baseResponse(userDetailsSchema),
request: [{ type: "query", name: "userId", schema: UUIDSchema }],
})
async getUserDetails(@Query("userId") userId: UUIDType): Promise<BaseResponse<UserDetails>> {
const userDetails = await this.usersService.getUserDetails(userId);
Expand Down
25 changes: 25 additions & 0 deletions apps/web/app/api/queries/useTutorCourses.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useQuery, useSuspenseQuery } from "@tanstack/react-query";

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

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

export const tutorCourses = (authorId: string) => {
return {
queryKey: ["tutor-courses", authorId],
queryFn: async () => {
const response = await ApiClient.api.coursesControllerGetTutorCourses({ authorId });

return response.data;
},
select: (data: GetTutorCoursesResponse) => data.data,
};
};

export function useTutorCourses(authorId: string) {
return useQuery(tutorCourses(authorId));
}

export function useTutorCoursesSuspense(authorId: string) {
return useSuspenseQuery(tutorCourses(authorId));
}
25 changes: 25 additions & 0 deletions apps/web/app/api/queries/useUserDetails.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useQuery, useSuspenseQuery } from "@tanstack/react-query";

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

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

export const userDetails = (userId: string) => {
return {
queryKey: ["user-details", userId],
queryFn: async () => {
const response = await ApiClient.api.usersControllerGetUserDetails({ userId });

return response.data;
},
select: (data: GetUserDetailsResponse) => data.data,
};
};

export function useUserDetails(userId: string) {
return useQuery(userDetails(userId));
}

export function useUserDetailsSuspense(userId: string) {
return useSuspenseQuery(userDetails(userId));
}
3 changes: 3 additions & 0 deletions apps/web/app/assets/svgs/email.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions apps/web/app/assets/svgs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ export { default as Course } from "./course.svg?react";
export { default as Category } from "./category.svg?react";
export { default as Lesson } from "./lesson.svg?react";
export { default as LessonContent } from "./lesson-content.svg?react";
export { default as Email } from "./email.svg?react";
export { default as Phone } from "./phone.svg?react";
3 changes: 3 additions & 0 deletions apps/web/app/assets/svgs/phone.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { courseQueryOptions } from "~/api/queries/useCourse";
import { queryClient } from "~/api/queryClient";
import CourseProgress from "~/components/CourseProgress";
import Viewer from "~/components/RichText/Viever";
import { Avatar, AvatarFallback, AvatarImage } from "~/components/ui/avatar";
import { Button } from "~/components/ui/button";
import { CategoryChip } from "~/components/ui/CategoryChip";
import { toast } from "~/components/ui/use-toast";
Expand Down Expand Up @@ -80,6 +81,13 @@ export const CourseViewMainCard = ({ course }: { course: GetCourseResponse["data
courseLessonCount={courseLessonCount}
/>
<h4 className="text-2xl font-bold mt-4 lg:mt-6 leading-10 text-neutral-950">{title}</h4>
<a href={`/tutors/${""}`} className="flex items-center gap-x-1.5 mt-3 mb-4">
<Avatar className="h-6 w-6">
<AvatarImage src="https://s3-alpha-sig.figma.com/img/9d6d/cfc1/fb8cd40116ca161e463af1ee400a729e?Expires=1731888000&Key-Pair-Id=APKAQ4GOSFWCVNEHN3O4&Signature=hW~mDlz4ijNlLYIqE0BSS~iAYAUiHmepYUBkv9zW-cyW1soL~JQWu7SHl8A2w9OcEmdJhrzriJSvG-ANAi9-ksJSNRw84oV2UUOrG9SNdb5yj4TQUYWAa8LCO~yrBGo0PDrZg2erzdH~glIN1irnVVQd9~n3T5VsZAajkT49ryWiAxydo7l-18zpdnbnERj2qVjq-pD3W5~GvHUftPiYoVafVgktSrWvk9-veZukLMVJureiQvpeRS1CSo1NhwCLO-gbchX13LjOmHhpNEcEhI5r52bw4BJyhm54dZyoFYs8NoaZklUmRv~hshFwN8NAjql~qrLjUlrAaqgA0mM3Fg__" />
<AvatarFallback>CN</AvatarFallback>
</Avatar>
<span className="text-primary-700">Rylee Bean</span>
</a>
<div className="min-h-0 scrollbar-thin overflow-auto">
<Viewer content={description} />
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,10 @@ export const Question = ({ isSubmitted, content, questionsArray }: QuestionProps

const getFillInTheBlanksDndAnswers = () => {
if ("questionAnswers" in content && isDraggableFillInTheBlanks) {
const items1: DndWord[] = [];

Check warning on line 114 in apps/web/app/modules/Courses/Lesson/LessonItems/Question/Question.tsx

View workflow job for this annotation

GitHub Actions / Lint

'items1' is assigned a value but never used. Allowed unused vars must match /^_/u
const items: DndWord[] = [];

const items2: DndWord[] = [];

Check warning on line 116 in apps/web/app/modules/Courses/Lesson/LessonItems/Question/Question.tsx

View workflow job for this annotation

GitHub Actions / Lint

'items2' is assigned a value but never used. Allowed unused vars must match /^_/u
console.log({ questions: content.questionAnswers });
for (const {
id,
optionText,
Expand All @@ -131,7 +133,6 @@ export const Question = ({ isSubmitted, content, questionsArray }: QuestionProps
isStudentAnswer,
});
}

items.push({
id,
index: position,
Expand All @@ -150,7 +151,11 @@ export const Question = ({ isSubmitted, content, questionsArray }: QuestionProps

return acc;
}, []);

console.log({
studentAnswers,
returnedValue: items.filter(({ value }) => !studentAnswers.includes(value)),
items,
});
return items.filter(({ value }) => !studentAnswers.includes(value));
}

Expand Down
1 change: 1 addition & 0 deletions apps/web/app/modules/Dashboard/Courses/CardCourseList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const CardCourseList = ({ availableCourses }: CardCourseListProps) => {
enrolled={enrolled}
priceInCents={priceInCents}
currency={currency}
withAuthor
/>
);
}
Expand Down
15 changes: 14 additions & 1 deletion apps/web/app/modules/Dashboard/Courses/CourseCard.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Link } from "@remix-run/react";

import CourseProgress from "~/components/CourseProgress";
import { Avatar, AvatarFallback, AvatarImage } from "~/components/ui/avatar";
import { CategoryChip } from "~/components/ui/CategoryChip";
import { useUserRole } from "~/hooks/useUserRole";
import { cn } from "~/lib/utils";
Expand All @@ -24,6 +25,7 @@ type CourseCardProps = Pick<
> & {
href: string;
completedLessonCount?: number;
withAuthor?: boolean;
};

const CourseCard = ({
Expand All @@ -37,14 +39,15 @@ const CourseCard = ({
completedLessonCount,
currency,
priceInCents,
withAuthor = false,
}: CourseCardProps) => {
const { isAdmin } = useUserRole();

return (
<Link
to={href}
className={cn(
"flex flex-col w-full max-w-[320px] overflow-hidden rounded-lg transition hover:shadow-primary h-full bg-white lg:bg-none border",
"flex flex-col w-full max-w-[320px] overflow-hidden rounded-lg transition hover:shadow-primary h-auto bg-white lg:bg-none border",
{
"border-secondary-200 hover:border-secondary-500": enrolled,
"border-primary-200 hover:border-primary-500": !enrolled,
Expand Down Expand Up @@ -80,6 +83,16 @@ const CourseCard = ({
/>
)}
<CourseCardTitle title={title} />
{/*TODO: Change to avatar from api*/}
{withAuthor && (
<div className="flex items-center gap-x-1.5">
<Avatar className="h-4 w-4">
<AvatarImage src="https://s3-alpha-sig.figma.com/img/9d6d/cfc1/fb8cd40116ca161e463af1ee400a729e?Expires=1731888000&Key-Pair-Id=APKAQ4GOSFWCVNEHN3O4&Signature=hW~mDlz4ijNlLYIqE0BSS~iAYAUiHmepYUBkv9zW-cyW1soL~JQWu7SHl8A2w9OcEmdJhrzriJSvG-ANAi9-ksJSNRw84oV2UUOrG9SNdb5yj4TQUYWAa8LCO~yrBGo0PDrZg2erzdH~glIN1irnVVQd9~n3T5VsZAajkT49ryWiAxydo7l-18zpdnbnERj2qVjq-pD3W5~GvHUftPiYoVafVgktSrWvk9-veZukLMVJureiQvpeRS1CSo1NhwCLO-gbchX13LjOmHhpNEcEhI5r52bw4BJyhm54dZyoFYs8NoaZklUmRv~hshFwN8NAjql~qrLjUlrAaqgA0mM3Fg__" />
<AvatarFallback>CN</AvatarFallback>
</Avatar>
<span>Rylee Bean</span>
</div>
)}
<div className="text-neutral-500 text-sm flex-grow">
<span className="line-clamp-3">
<div dangerouslySetInnerHTML={{ __html: description }} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ export const StudentCoursesCarousel = ({ studentCourses }: StudentCoursesCarouse
return (
<CarouselItem
key={studentCourse.id}
className="max-w-[calc(100%-24px)] xs:max-w-[320px] w-full shrink-0 mr-3 sm:mr-6 sm:last:mr-0"
className="max-w-[calc(100%-24px)] xs:max-w-[320px] *:h-full w-full shrink-0 mr-3 sm:mr-6 sm:last:mr-0"
>
<CourseCard {...studentCourse} href={`/course/${studentCourse.id}`} />
<CourseCard {...studentCourse} href={`/course/${studentCourse.id}`} withAuthor />
</CarouselItem>
);
}
Expand Down
13 changes: 8 additions & 5 deletions apps/web/app/modules/Dashboard/Dashboard.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ export default function DashboardPage() {
<StudentCoursesCarousel studentCourses={studentCourses} />
</div>
</div>
<div className="flex flex-col px-6">
<div className="flex flex-col px-6 lg:px-0">
<div className="flex flex-col lg:p-0">
<h4 className="text-neutral-950 text-2xl font-bold leading-10 pb-1">Available Courses</h4>
<p className="text-lg leading-7 text-neutral-800">
Expand Down Expand Up @@ -211,10 +211,13 @@ export default function DashboardPage() {
</div>
<div
data-testid="unenrolled-courses"
className={cn("lg:p-8 gap-6 rounded-lg drop-shadow-primary lg:bg-white", {
"flex flex-wrap": courseListLayout === "card",
block: courseListLayout === "table",
})}
className={cn(
"lg:p-8 gap-6 rounded-lg drop-shadow-primary lg:bg-white",
{
"flex flex-wrap": courseListLayout === "card",
block: courseListLayout === "table",
},
)}
>
{availableCourses && !isEmpty(availableCourses) && (
<CourseList availableCourses={availableCourses} courseListLayout={courseListLayout} />
Expand Down
Loading

0 comments on commit 51c1640

Please sign in to comment.