Skip to content

Commit

Permalink
Merge pull request #221 from Project-Juniors-Club/fix-bug
Browse files Browse the repository at this point in the history
fix: fix cart bug
  • Loading branch information
sltsheryl authored Jan 9, 2024
2 parents 1cf9b8d + 9437fff commit d8ac0ab
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 18 deletions.
7 changes: 0 additions & 7 deletions components/navbar/NavBarAdmin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ const NavBarAdmin = () => {
<div className='flex h-full flex-row'>
<JuniorsClubLogo />

{/* TO UPDATE LINK */}
<div className={`main-nav-menu ml-7 flex h-full items-center gap-6 ${navBarItemStyle}`}>
<Link href='/courses' className='menu-item text-base'>
User Management
</Link>
</div>

{/* TO UPDATE LINK */}
<div className={`main-nav-menu ml-7 flex h-full items-center gap-6 ${navBarItemStyle}`}>
<Link href='/courses' className='menu-item text-base'>
Expand Down
4 changes: 2 additions & 2 deletions lib/server/course.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export const addCourseToCart = async (userId: string, courseId: string) => {
id: courseId,
},
data: {
userCourses: {
users: {
connect: {
id: userId,
},
Expand Down Expand Up @@ -327,7 +327,7 @@ export const deleteCourseToCart = async (userId: string, courseId: string) => {
id: courseId,
},
data: {
userCourses: {
users: {
disconnect: {
id: userId,
},
Expand Down
29 changes: 29 additions & 0 deletions prisma/migrations/20240109135427_fix/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Warnings:
- You are about to drop the column `userId` on the `courses` table. All the data in the column will be lost.
*/
-- DropForeignKey
ALTER TABLE "courses" DROP CONSTRAINT "courses_userId_fkey";

-- AlterTable
ALTER TABLE "courses" DROP COLUMN "userId";

-- CreateTable
CREATE TABLE "_CoursesInCart" (
"A" TEXT NOT NULL,
"B" TEXT NOT NULL
);

-- CreateIndex
CREATE UNIQUE INDEX "_CoursesInCart_AB_unique" ON "_CoursesInCart"("A", "B");

-- CreateIndex
CREATE INDEX "_CoursesInCart_B_index" ON "_CoursesInCart"("B");

-- AddForeignKey
ALTER TABLE "_CoursesInCart" ADD CONSTRAINT "_CoursesInCart_A_fkey" FOREIGN KEY ("A") REFERENCES "courses"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_CoursesInCart" ADD CONSTRAINT "_CoursesInCart_B_fkey" FOREIGN KEY ("B") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE;
17 changes: 8 additions & 9 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ model VerificationToken {
@@unique([identifier, token])
}

model User {
id String @id @default(cuid())
email String @unique
Expand Down Expand Up @@ -97,16 +96,17 @@ model CourseEditor {
@@map("courseEditors")
}


model UserCourse {
id String @id @default(cuid())
userId String
courseId String
progress Int
correctQns Int
stars Int
lastSeenBy DateTime
course Course @relation(fields: [courseId], references: [id])
user User @relation(fields: [userId], references: [id])
lastSeenBy DateTime
@@unique([userId, courseId])
@@map("userCourses")
Expand All @@ -129,18 +129,17 @@ model Course {
createDate DateTime @default(now())
lastUpdatedUserId String
lastUpdatedDate DateTime @updatedAt
coverImage Image? @relation(fields: [coverImageAssetId], references: [assetId])
status CourseStatus @default(DRAFT)
categoryId String?
coverImageAssetId String?
chapters Chapter[]
courseEditor CourseEditor[]
category Category? @relation(fields: [categoryId], references: [id])
coverImage Image? @relation(fields: [coverImageAssetId], references: [assetId])
createdBy Admin @relation("createdBy", fields: [creatorId], references: [userId])
lastUpdatedBy Admin @relation("updatedBy", fields: [lastUpdatedUserId], references: [userId])
category Category? @relation(fields: [categoryId], references: [id])
chapters Chapter[]
userCourses UserCourse[]
User User? @relation("CoursesInCart", fields: [userId], references: [id])
userId String?
courseEditor CourseEditor[]
coverImageAssetId String?
users User[] @relation("CoursesInCart")
@@map("courses")
}
Expand Down

0 comments on commit d8ac0ab

Please sign in to comment.