Skip to content

Commit

Permalink
feat: added student batch add form
Browse files Browse the repository at this point in the history
  • Loading branch information
amjed-ali-k committed Oct 24, 2023
1 parent ae489fa commit 7b0ff42
Show file tree
Hide file tree
Showing 4 changed files with 308 additions and 95 deletions.
1 change: 1 addition & 0 deletions public/student-sample.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
name, rollNumber, regNumber, admnNumber
57 changes: 12 additions & 45 deletions src/app/api/secure/exam-seating/student-batches/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,17 @@ import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/server/db/prisma";
import { getUserId } from "@/components/auth/server";

enum SeatType {
THEORY,
DRAWING,
COMMON,
BLANK,
}

const schema = z.object({
name: z.string(),
structure: z
name: z.string().min(3, "Minimum 3 characters required"),
students: z
.array(
z
.array(
z.object({
name: z.string(),
seatCount: z.number().positive(),
structure: z.array(z.number().nonnegative()),
})
)
.min(1)
z.object({
name: z.string().optional(),
primaryNumber: z.string(),
rollNumber: z.string().optional(),
regNumber: z.string().optional(),
admnNumber: z.string().optional(),
})
)
.min(1),
});
Expand All @@ -41,42 +32,18 @@ export async function PUT(request: NextRequest) {
);
}

const results = await prisma.examHall.create({
const results = await prisma.studentBatchForExam.create({
data: {
name: body.data.name,
structure: body.data.structure,
students: body.data.students,
createdById: userId,
theoryOnlySeats: getCount(body.data.structure, SeatType.THEORY),
drawingOnlySeats: getCount(body.data.structure, SeatType.DRAWING),
commonSeats: getCount(body.data.structure, SeatType.COMMON),
studentsCount: body.data.students.length,
},
});

return NextResponse.json(results);
}

export type SeatObjectType = {
name: string;
seatCount: number;
structure: SeatType[];
};

function getCount(structure: SeatObjectType[][], type: SeatType) {
return structure.reduce((acc, curr) => {
return (
acc +
curr.reduce((acc, curr) => {
return (
acc +
curr.structure.reduce((acc, curr) => {
return curr === type ? (acc += 1) : acc;
}, 0)
);
}, 0)
);
}, 0);
}

const deleteSchema = z.object({
id: z.string(),
});
Expand Down
14 changes: 4 additions & 10 deletions src/app/dashboard/result-formatter/_components/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,10 @@ import axios from "axios";
const allowedMonths = ["April", "November"];

const fomrSchema = z.object({
month: z
.string()
.nonempty()
.refine((val) => {
return allowedMonths.includes(val);
}),
year: z
.string()
.nonempty()
.regex(/^[0-9]{4}$/),
month: z.string().refine((val) => {
return allowedMonths.includes(val);
}),
year: z.string().regex(/^[0-9]{4}$/),
upload: z.boolean(),
});

Expand Down
Loading

0 comments on commit 7b0ff42

Please sign in to comment.