Skip to content

Commit eee4ddd

Browse files
committed
get test series by grade and subject
1 parent 9761d16 commit eee4ddd

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

components/student.component.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,39 @@ const sendStudentFeedback = async ({
736736
}
737737
};
738738

739+
const getTestSeriesByGrade = async (grade, subject) => {
740+
try {
741+
const accessToken = await getZohoTokenOptimized();
742+
const zohoConfig = {
743+
headers: {
744+
"Content-Type": "application/json",
745+
"Access-Control-Allow-Origin": "*",
746+
Authorization: `Bearer ${accessToken}`,
747+
},
748+
};
749+
750+
const testSeriesQuery = `select Name, Activate_Date, Image, Survey_Link from Test_Series, Subject where Subject = '${subject}' and Grade like '%${grade}%' order by Activate_Date asc limit 200`;
751+
752+
const [testSeries] = await Promise.all([
753+
limit(() => getAnalysisData(testSeriesQuery, zohoConfig)),
754+
]);
755+
756+
if (testSeries.status >= 204) {
757+
return {
758+
status: testSeries.status,
759+
data: [],
760+
};
761+
}
762+
763+
return {
764+
status: 200,
765+
data: testSeries.data.data,
766+
};
767+
} catch (error) {
768+
throw new Error(error);
769+
}
770+
};
771+
739772
module.exports = {
740773
getStudentDetails,
741774
getStudentOrders,
@@ -744,4 +777,5 @@ module.exports = {
744777
getWeeklyWinners,
745778
getPaymentHistory,
746779
sendStudentFeedback,
780+
getTestSeriesByGrade,
747781
};

controllers/student.controller.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const {
77
getWeeklyWinners,
88
getPaymentHistory,
99
sendStudentFeedback,
10+
getTestSeriesByGrade,
1011
} = require("../components/student.component");
1112
const {
1213
getZohoTokenOptimized,
@@ -57,6 +58,20 @@ studentRouter.get("/store", authMiddleware, async (req, res) => {
5758
}
5859
});
5960

61+
studentRouter.post("/test-series", authMiddleware, async (req, res) => {
62+
try {
63+
const { grade, subject } = req.body;
64+
const data = await getTestSeriesByGrade(grade, subject);
65+
return res.status(200).send(data);
66+
} catch (error) {
67+
return res.status(error.status || 500).send({
68+
status: "error",
69+
message: error.message,
70+
code: error.status || 500,
71+
});
72+
}
73+
});
74+
6075
studentRouter.post("/store/orders", authMiddleware, async (req, res) => {
6176
try {
6277
const { contactId } = req.body;

0 commit comments

Comments
 (0)