-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9767948
commit f3735b4
Showing
28 changed files
with
865 additions
and
215 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"use server"; | ||
|
||
import { cookies } from "next/headers"; | ||
|
||
export async function setPlanCookie(plan: string) { | ||
//@ts-ignore | ||
(await cookies()).set("plan", plan); | ||
} | ||
|
||
export async function getPlanCookie() { | ||
const cookieStore = await cookies(); | ||
//@ts-ignore | ||
const plan = await cookieStore.get("plan"); | ||
|
||
const out = plan ? plan.value : undefined; | ||
|
||
return out; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// api/test.ts | ||
import { NextResponse, NextRequest } from "next/server"; | ||
import prisma from "@/lib/prisma"; | ||
import { getServerSession } from "next-auth/next"; | ||
import { auth } from "@/lib/auth"; | ||
|
||
export async function POST(request: NextRequest) { | ||
const data = await request.json(); | ||
const session = await auth(); | ||
|
||
//@ts-ignore | ||
const user = await prisma.user.findUnique({ | ||
where: { | ||
//@ts-ignore | ||
uuid: session?.user?.id, | ||
}, | ||
}); | ||
|
||
const plan = await prisma.coursePlan.create({ | ||
data: { | ||
//@ts-ignore | ||
name: data.planName, | ||
year: "F2024", | ||
User: { | ||
connect: { | ||
id: user?.id, | ||
}, | ||
}, | ||
}, | ||
}); | ||
|
||
return NextResponse.json(plan, { status: 200 }); | ||
} | ||
|
||
export async function GET(request: NextRequest) { | ||
const session = await auth(); | ||
const user = await prisma.user.findUnique({ | ||
where: { | ||
//@ts-ignore | ||
uuid: session?.user?.id, | ||
}, | ||
}); | ||
const courses = await prisma.coursePlan.findMany({ | ||
where: { | ||
User: { | ||
//@ts-ignore | ||
id: user.id, | ||
}, | ||
}, | ||
include: { | ||
courses: true, | ||
}, | ||
}); | ||
//console.log(plans); | ||
return NextResponse.json(courses, { status: 200 }); | ||
} | ||
|
||
export async function DELETE(request: NextRequest) { | ||
const data = await request.json(); | ||
|
||
//@ts-ignore | ||
const plan = await prisma.coursePlan.delete({ | ||
where: { | ||
//@ts-ignore | ||
id: parseInt(data.planId), | ||
}, | ||
}); | ||
|
||
return NextResponse.json(plan, { status: 200 }); | ||
} | ||
|
||
// To handle a POST request to /api | ||
/* | ||
export async function POST(request: NextRequest) { | ||
return NextResponse.json(output, { status: 200 }); | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { NextResponse, NextRequest } from "next/server"; | ||
import prisma from "@/lib/prisma"; | ||
import { auth } from "@/lib/auth"; | ||
|
||
export async function GET(request: NextRequest) { | ||
const session = await auth(); | ||
const user = await prisma.user.findUnique({ | ||
where: { | ||
//@ts-ignore | ||
uuid: session?.user?.id, | ||
}, | ||
}); | ||
let courses: any; | ||
if (user) { | ||
courses = await prisma.coursePlan.findMany({ | ||
where: { | ||
User: { | ||
//@ts-ignore | ||
id: user.id, | ||
}, | ||
}, | ||
include: { | ||
courses: true, | ||
}, | ||
}); | ||
} else { | ||
courses = null; | ||
} | ||
//console.log(plans); | ||
return NextResponse.json(courses, { status: 200 }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// api/test.ts | ||
import { NextResponse, NextRequest } from "next/server"; | ||
import prisma from "@/lib/prisma"; | ||
import { getServerSession } from "next-auth/next"; | ||
import { auth } from "@/lib/auth"; | ||
import { getPlanCookie } from "@/app/actions"; | ||
|
||
export async function GET(request: NextRequest) { | ||
let planCookie: any = await getPlanCookie(); | ||
const session = await auth(); | ||
|
||
let courses = await prisma.coursePlan.findMany({ | ||
where: { | ||
AND: { | ||
User: { | ||
//@ts-ignore | ||
uuid: session?.user.id, | ||
}, | ||
id: parseInt(planCookie), | ||
}, | ||
}, | ||
include: { | ||
courses: true, | ||
}, | ||
}); | ||
return NextResponse.json(courses, { status: 200 }); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// api/test.ts | ||
import { NextResponse, NextRequest } from "next/server"; | ||
import prisma from "@/lib/prisma"; | ||
import { getServerSession } from "next-auth/next"; | ||
import { auth } from "@/lib/auth"; | ||
import { getPlanCookie } from "@/app/actions"; | ||
|
||
export async function POST(request: NextRequest) { | ||
const course = await request.json(); | ||
const planId = await getPlanCookie(); | ||
|
||
if (planId) { | ||
let plan: any; | ||
|
||
if (planId) { | ||
plan = await prisma.coursePlan.update({ | ||
where: { | ||
id: parseInt(planId), | ||
}, | ||
data: { | ||
courses: { | ||
connect: { | ||
id: course.course.id, | ||
}, | ||
}, | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
return NextResponse.json(planId, { status: 200 }); | ||
} | ||
|
||
export async function GET(request: NextRequest) { | ||
const session = await auth(); | ||
const user = await prisma.user.findUnique({ | ||
where: { | ||
//@ts-ignore | ||
uuid: session?.user?.id, | ||
}, | ||
}); | ||
const courses = await prisma.coursePlan.findMany({ | ||
where: { | ||
User: { | ||
//@ts-ignore | ||
id: user.id, | ||
}, | ||
}, | ||
include: { | ||
courses: true, | ||
}, | ||
}); | ||
console.log(courses); | ||
return NextResponse.json(courses, { status: 200 }); | ||
} | ||
|
||
export async function DELETE(request: NextRequest) { | ||
const data = await request.json(); | ||
|
||
//@ts-ignore | ||
const plan = await prisma.coursePlan.delete({ | ||
where: { | ||
//@ts-ignore | ||
id: parseInt(data.planId), | ||
}, | ||
}); | ||
|
||
return NextResponse.json(plan, { status: 200 }); | ||
} | ||
|
||
// To handle a POST request to /api | ||
/* | ||
export async function POST(request: NextRequest) { | ||
return NextResponse.json(output, { status: 200 }); | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// api/test.ts | ||
import { NextResponse, NextRequest } from "next/server"; | ||
import prisma from "@/lib/prisma"; | ||
|
||
export async function POST(request: NextRequest) { | ||
const data = await request.json(); | ||
//@ts-ignore | ||
const session = data?.session; | ||
|
||
const user = await prisma.user.upsert({ | ||
where: { | ||
//@ts-ignore | ||
uuid: session?.user?.id, | ||
}, | ||
update: { | ||
//@ts-ignore | ||
uuid: session?.user?.id, | ||
email: session?.user?.email, | ||
name: session?.user?.name, | ||
}, | ||
create: { | ||
//@ts-ignore | ||
uuid: session?.user?.id, | ||
email: session?.user?.email, | ||
name: session?.user?.name, | ||
}, | ||
}); | ||
|
||
return NextResponse.json(user, { status: 200 }); | ||
} | ||
|
||
export async function GET(request: NextRequest) { | ||
/* | ||
const session = data.session; | ||
const user = await prisma.user.findUnique({ | ||
where: { | ||
//@ts-ignore | ||
id: session?.user?.id, | ||
}, | ||
}); | ||
*/ | ||
return NextResponse.json("HI", { status: 200 }); | ||
} | ||
// To handle a POST request to /api | ||
/* | ||
export async function POST(request: NextRequest) { | ||
return NextResponse.json(output, { status: 200 }); | ||
} | ||
*/ |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.