Skip to content

Commit c284561

Browse files
Vellore wasn't being set in the form data
1 parent 88d189b commit c284561

File tree

2 files changed

+43
-15
lines changed

2 files changed

+43
-15
lines changed

src/app/api/ai-upload/route.ts

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,50 @@ export async function POST(req: Request) {
6060
const campus = formData.get("campus") as string
6161
const semester = finalTags.semester;
6262

63-
if (
64-
!(
65-
courses.includes(subject) &&
66-
slots.includes(slot) &&
67-
exam.includes(exam) &&
68-
years.includes(year) &&
69-
campuses.includes(campus) &&
70-
semesters.includes(semester)
71-
)
72-
) {
63+
if (!courses.includes(subject)) {
7364
return NextResponse.json(
74-
{ message: "AI couldn't set tags" },
75-
{ status: 400 },
65+
{ message: "The course subject is invalid." },
66+
{ status: 400 }
67+
);
68+
}
69+
70+
if (!slots.includes(slot)) {
71+
return NextResponse.json(
72+
{ message: "The slot is invalid." },
73+
{ status: 400 }
74+
);
75+
}
76+
77+
if (!exam.includes(exam)) {
78+
return NextResponse.json(
79+
{ message: "The exam type is invalid." },
80+
{ status: 400 }
81+
);
82+
}
83+
84+
if (!years.includes(year)) {
85+
return NextResponse.json(
86+
{ message: "The year is invalid." },
87+
{ status: 400 }
88+
);
89+
}
90+
91+
if (!campuses.includes(campus)) {
92+
return NextResponse.json(
93+
{ message:`The ${campus} is invalid.` },
94+
{ status: 400 }
95+
);
96+
}
97+
98+
if (!semesters.includes(semester)) {
99+
return NextResponse.json(
100+
{ message: "The semester is invalid." },
101+
{ status: 400 }
76102
);
77103
}
104+
105+
// If all checks pass, continue with the rest of the logic
106+
78107
await connectToDatabase();
79108
let finalUrl: string | undefined = "";
80109
let public_id_cloudinary: string | undefined = "";

src/app/upload/page.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import { PDFDocument } from "pdf-lib";
4040
}
4141

4242
const Page = () => {
43-
const [campus, setCampus] = useState("");
43+
const [campus, setCampus] = useState("Vellore");
4444

4545
const [files, setFiles] = useState<File[]>([]);
4646
const [isUploading, setIsUploading] = useState(false);
@@ -73,8 +73,7 @@ const Page = () => {
7373
// }
7474
if (!campus) {
7575
setCampus("Vellore")
76-
// toast.error("Campus is required");
77-
// return;
76+
7877
}
7978
// if (!semester) {
8079
// toast.error("Semester is required");

0 commit comments

Comments
 (0)