-
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
Showing
55 changed files
with
1,972 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 |
---|---|---|
|
@@ -34,3 +34,6 @@ yarn-error.log* | |
# typescript | ||
*.tsbuildinfo | ||
next-env.d.ts | ||
|
||
# dot env | ||
.env |
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,47 @@ | ||
import { prisma } from "@/lib/prisma"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
export async function POST(req: NextRequest) { | ||
const jsonBody = await req.json(); | ||
const user = await prisma.user.findFirst( | ||
{ | ||
where: { | ||
userName: jsonBody['display_name'] | ||
} | ||
} | ||
); | ||
|
||
var attendenace = await prisma.attendence.findFirst( | ||
{ | ||
where: { | ||
meetId: Number.parseInt(jsonBody['meetId']), | ||
userId: user?.id | ||
} | ||
} | ||
); | ||
|
||
if (!attendenace) { | ||
await prisma.attendence.create({ | ||
data: { | ||
attendenace: 25, | ||
meetId: Number.parseInt(jsonBody['meetId']), | ||
userId: user?.id!, | ||
}, | ||
}); | ||
} | ||
else { | ||
await prisma.attendence.update({ | ||
where: { | ||
id: attendenace.id, | ||
}, | ||
data: { | ||
attendenace: attendenace.attendenace + 25, | ||
} | ||
}); | ||
} | ||
|
||
|
||
return NextResponse.json({ | ||
message: "Attendance updated", | ||
}, { 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,53 @@ | ||
import { prisma } from "@/lib/prisma"; | ||
import NextAuth from "next-auth" | ||
import CredentialsProvider from "next-auth/providers/credentials" | ||
|
||
export const authOptions = { | ||
providers: [ | ||
CredentialsProvider({ | ||
name: "Student Email", | ||
credentials: { | ||
email: { label: "Email", placeholder: "Enter your Email" }, | ||
password: { label: "Password", type: "password", placeholder: "Enter Your password" }, | ||
}, | ||
async authorize(credentials) { | ||
const user = await prisma.user.findFirst({ | ||
where: { | ||
userName: credentials?.email, | ||
password: credentials?.password, | ||
} | ||
}); | ||
|
||
return { | ||
id: user!.id.toString(), | ||
userName: user?.userName, | ||
userType: user?.userType, | ||
}; | ||
} | ||
}) | ||
], | ||
secret: process.env.NEXTAUTH_SECRET, | ||
callbacks: { | ||
jwt: async ({ user, token }: any) => { | ||
if (user) { | ||
token.uid = user.id; | ||
token.userName = user.userName | ||
token.userType = user.userType | ||
} | ||
return token; | ||
}, | ||
session: ({ session, token, user }: any) => { | ||
if (session.user) { | ||
session.user.id = token.uid; | ||
session.user.userName = token.userName; | ||
session.user.userType = token.userType; | ||
} | ||
return session | ||
} | ||
}, | ||
}; | ||
|
||
const handeler = NextAuth(authOptions); | ||
|
||
export const GET = handeler; | ||
export const POST = handeler; |
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,25 @@ | ||
import { prisma } from "@/lib/prisma"; | ||
import { getServerSession } from "next-auth"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
import { authOptions } from "../../auth/[...nextauth]/route"; | ||
|
||
export async function POST(req: NextRequest) { | ||
try { | ||
var jsonBody = await req.json(); | ||
const session = await getServerSession(authOptions); | ||
|
||
var response = await prisma.class.create({ | ||
data: { | ||
userid: Number.parseInt(session.user.id), | ||
className: jsonBody["className"], | ||
}, | ||
}); | ||
|
||
return NextResponse.json({ | ||
message: "created", | ||
class: response, | ||
}); | ||
} catch (error) { | ||
return NextResponse.json(error); | ||
} | ||
} |
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,28 @@ | ||
import { prisma } from "@/lib/prisma"; | ||
import { getServerSession } from "next-auth"; | ||
import { getCsrfToken } from "next-auth/react"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
import { authOptions } from "@/app/api/auth/[...nextauth]/route"; | ||
|
||
export async function GET(req: NextRequest) { | ||
try { | ||
const session = await getServerSession(authOptions); | ||
if (!session) { | ||
return; | ||
} | ||
|
||
var response = await prisma.class.findMany({ | ||
where: { | ||
userid: Number.parseInt(session.user.id), | ||
}, | ||
}); | ||
|
||
return NextResponse.json({ | ||
message: "Success", | ||
class: response, | ||
}); | ||
} catch (error) { | ||
return NextResponse.json(error); | ||
} | ||
} |
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,31 @@ | ||
import { prisma } from "@/lib/prisma"; | ||
import { getServerSession } from "next-auth"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
import { authOptions } from "@/app/api/auth/[...nextauth]/route"; | ||
import { useSearchParams } from "next/navigation"; | ||
import { json } from "stream/consumers"; | ||
|
||
export async function GET(req: NextRequest, { params }: any) { | ||
try { | ||
const session = await getServerSession(authOptions); | ||
const MEET_ID = req.nextUrl.searchParams.get('MEET_ID') | ||
|
||
var response = await prisma.meetings.findUnique({ | ||
where: { | ||
id: Number.parseInt(MEET_ID!), | ||
}, | ||
}); | ||
|
||
if (response?.status == 2) { | ||
return NextResponse.redirect(process.env.BaseUrl + 'scheduled_class/invite/' + response.id + '/' + session.user.userName) | ||
} | ||
else { | ||
return NextResponse.json({ | ||
message: "Meeting Has been Ended" | ||
}) | ||
} | ||
} catch (error) { | ||
return NextResponse.json(error, { status: 500 }); | ||
} | ||
} |
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,56 @@ | ||
import { prisma } from "@/lib/prisma"; | ||
import { getServerSession } from "next-auth"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
import { authOptions } from "@/app/api/auth/[...nextauth]/route"; | ||
import { useSearchParams } from "next/navigation"; | ||
import { json } from "stream/consumers"; | ||
|
||
export async function GET(req: NextRequest, { params }: any) { | ||
try { | ||
const session = await getServerSession(authOptions); | ||
const classId = req.nextUrl.searchParams.get('class_id') | ||
|
||
var response = await prisma.meetings.findMany({ | ||
where: { | ||
classId: Number.parseInt(classId!), | ||
}, | ||
orderBy: { | ||
status: "asc" | ||
} | ||
}); | ||
|
||
return NextResponse.json({ | ||
message: "Meetings fetch Success", | ||
classId: classId, | ||
class: response, | ||
}); | ||
} catch (error) { | ||
return NextResponse.json(error, { status: 500 }); | ||
} | ||
} | ||
|
||
export async function POST(req: NextRequest, { params }: any) { | ||
try { | ||
const session = await getServerSession(authOptions); | ||
const json = await req.json(); | ||
|
||
var response = await prisma.meetings.create({ | ||
data: { | ||
classId: Number.parseInt(json.classId), | ||
meetingName: json.meetingName, | ||
meetingType: 'everyone', | ||
status: 0, | ||
date: new Date(json.date) | ||
|
||
} | ||
}); | ||
|
||
return NextResponse.json({ | ||
message: "Meet Save Success", | ||
meet: response, | ||
}); | ||
} catch (error) { | ||
return NextResponse.json(error, { status: 500 }); | ||
} | ||
} |
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,82 @@ | ||
|
||
import { prisma } from "@/lib/prisma"; | ||
import { getServerSession } from "next-auth"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
import { authOptions } from "@/app/api/auth/[...nextauth]/route"; | ||
import { useSearchParams } from "next/navigation"; | ||
import { json } from "stream/consumers"; | ||
import ClassStartedEmail, { mailDetails } from "@/app/emails/classstarted"; | ||
|
||
|
||
export async function POST(req: NextRequest) { | ||
try { | ||
const jsonBody = await req.json(); | ||
|
||
var students = await prisma.user.findMany({ | ||
where: { | ||
classId: jsonBody['classId'], | ||
userType: 1, | ||
} | ||
}); | ||
|
||
var teacher = await prisma.user.findFirst({ | ||
where: { | ||
classId: jsonBody['classId'], | ||
userType: 0, | ||
} | ||
}); | ||
|
||
var meeting = await prisma.meetings.findFirst({ | ||
where: { | ||
classId: jsonBody['classId'], | ||
} | ||
}); | ||
|
||
let nodemailer = require('nodemailer') | ||
const transporter = nodemailer.createTransport({ | ||
port: 465, | ||
host: "smtp.gmail.com", | ||
auth: { | ||
user: process.env.SMTP_USER || "user", | ||
pass: process.env.SMTP_PASSWORD || "pass", | ||
}, | ||
secure: true, | ||
}); | ||
|
||
students.forEach(student => { | ||
const mailData = { | ||
from: process.env.SMTP_USER, | ||
to: student.userName, | ||
subject: `Your Class Has been started`, | ||
text: 'Join the class soon', | ||
html: ClassStartedEmail({ | ||
classAjenda: jsonBody['classAjenda'], | ||
classDetail: meeting!, | ||
student: student, | ||
teacher: teacher!, | ||
}), | ||
}; | ||
|
||
transporter.sendMail(mailData, function (err: any, info: any) { | ||
if (err) console.log(err) | ||
}); | ||
}); | ||
|
||
var response = await prisma.meetings.update({ | ||
where: { | ||
id: jsonBody["meetId"], | ||
}, | ||
data: { | ||
status: 2, | ||
} | ||
}); | ||
|
||
return NextResponse.json({ | ||
message: "Success", | ||
class: response, | ||
}); | ||
} catch (error: any) { | ||
return NextResponse.json({ error }, { status: 500 }); | ||
} | ||
} |
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,21 @@ | ||
import { prisma } from "@/lib/prisma"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
export async function POST(req: NextRequest) { | ||
const jsonBody = await req.json(); | ||
|
||
var user = await prisma.user.create({ | ||
data: jsonBody, | ||
}); | ||
|
||
if (!user) { | ||
return NextResponse.json({ | ||
message: "Username alredy exist", | ||
}); | ||
} | ||
|
||
return NextResponse.json({ | ||
message: "User Creation Successfull", | ||
data: user, | ||
}, { status: 201 }); | ||
} |
Oops, something went wrong.