|
1 | | -import { Request, Response } from "express"; |
2 | | -import { DB, resultsCollection, studentsCollection } from "../../../db"; |
3 | | -import { GetRankingResponse, Result, Student } from "types"; |
| 1 | +import { Request, Response } from 'express'; |
| 2 | +import { DB, resultsCollection, studentsCollection } from '../../../db'; |
| 3 | +import { GetRankingResponse, Result, Student } from 'types'; |
4 | 4 |
|
5 | 5 | const getStudentDetailByAdmissionNo = async (admissionNo: string) => { |
6 | 6 | const student = await DB.collection(studentsCollection) |
@@ -32,15 +32,15 @@ export async function rankingController(req: Request, res: Response) { |
32 | 32 | if (isNaN(numericClass)) { |
33 | 33 | // For string classes like 'ukg', 'lkg', 'nursery' |
34 | 34 | classQuery = DB.collection(collection).where( |
35 | | - "currentClass", |
36 | | - "==", |
| 35 | + 'currentClass', |
| 36 | + '==', |
37 | 37 | className |
38 | 38 | ); |
39 | 39 | } else { |
40 | 40 | // For numeric classes like 1, 2, etc |
41 | 41 | classQuery = DB.collection(collection) |
42 | | - .where("currentClass", "==", numericClass) |
43 | | - .where("isCompleted", "==", true); |
| 42 | + .where('currentClass', '==', numericClass) |
| 43 | + .where('isCompleted', '==', true); |
44 | 44 | } |
45 | 45 |
|
46 | 46 | const results = await classQuery.get(); |
@@ -86,26 +86,26 @@ export async function rankingController(req: Request, res: Response) { |
86 | 86 | (a, b) => Number(b.percentage) - Number(a.percentage) |
87 | 87 | ); |
88 | 88 |
|
89 | | - if (content === "csv") { |
90 | | - const csvHeader = "name,roll,totalMarks,obtainedMarks,percentage,rank\n"; |
| 89 | + if (content === 'csv') { |
| 90 | + const csvHeader = 'name,roll,totalMarks,obtainedMarks,percentage,rank\n'; |
91 | 91 | const csvRows = sortedDetails.map( |
92 | 92 | (detail, index) => |
93 | 93 | `${detail.name},${detail.roll},${detail.totalMarks},${ |
94 | 94 | detail.obtainedMarks |
95 | 95 | },${detail.percentage},${index + 1}` |
96 | 96 | ); |
97 | | - const csvContent = csvHeader + csvRows.join("\n"); |
| 97 | + const csvContent = csvHeader + csvRows.join('\n'); |
98 | 98 |
|
99 | | - res.setHeader("Content-Type", "text/csv"); |
| 99 | + res.setHeader('Content-Type', 'text/csv'); |
100 | 100 | res.setHeader( |
101 | | - "Content-Disposition", |
| 101 | + 'Content-Disposition', |
102 | 102 | `attachment; filename=ranking-${batch}-${term}-${className}.csv` |
103 | 103 | ); |
104 | | - return res.status(200).send(csvContent); |
| 104 | + res.status(200).send(csvContent); |
105 | 105 | } |
106 | 106 |
|
107 | 107 | const response: GetRankingResponse = { |
108 | | - message: "success", |
| 108 | + message: 'success', |
109 | 109 | success: true, |
110 | 110 | data: sortedDetails.map((detail, index) => ({ |
111 | 111 | name: detail.name, |
|
0 commit comments