Skip to content

Commit 4bf336d

Browse files
committed
level wise quiz WIP
1 parent 706d87b commit 4bf336d

File tree

6 files changed

+119
-93
lines changed

6 files changed

+119
-93
lines changed

components/meeting.component.js

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const getMeetingLink = async (emailParam) => {
2727
};
2828

2929
const contact = await axios.get(
30-
`https://www.zohoapis.com/crm/v2/Contacts/search?email=${emailParam}`,
30+
`https://www.zohoapis.com/crm/v6/Contacts/search?email=${emailParam}`,
3131
zohoConfig
3232
);
3333

@@ -48,6 +48,7 @@ const getMeetingLink = async (emailParam) => {
4848
const contactid = contact.data.data[0].id;
4949
const email = contact.data.data[0].Email;
5050
const grade = contact.data.data[0].Student_Grade;
51+
const difficultyLevel = contact.data.data[0].Difficulty;
5152

5253
let gradeGroup;
5354
if (grade == 1 || grade == 2) {
@@ -64,7 +65,8 @@ const getMeetingLink = async (emailParam) => {
6465
const gradeUpdated = contact.data.data[0].Grade_Updated;
6566
const date = new Date();
6667
const start = new Date();
67-
start.setMinutes(start.getMinutes() + 240);
68+
start.setMinutes(start.getMinutes() + 260);
69+
// start.setMinutes(start.getMinutes() + 0);
6870
const end = new Date();
6971
end.setHours(23, 59, 59, 999);
7072
const startHours = start.getHours().toString().padStart(2, "0");
@@ -76,8 +78,30 @@ const getMeetingLink = async (emailParam) => {
7678
const day = date.getDate().toString().padStart(2, "0");
7779
const formattedDateStart = `${year}-${month}-${day}T${startHours}:${startMinutes}:00+05:30`;
7880
const formattedDateEnd = `${year}-${month}-${day}T${endHours}:${endMinutes}:00+05:30`;
81+
82+
const updateGrade =
83+
source_campaign === "old olympiad data" && !gradeUpdated ? true : false;
84+
85+
if (!credits || credits === 0) {
86+
return {
87+
status: 200,
88+
mode: !gradeUpdated || updateGrade ? "oldData" : "zoomlink",
89+
email,
90+
link: freeMeetLink,
91+
name,
92+
credits: credits,
93+
grade: grade,
94+
team: "not required",
95+
address: "Temp Address",
96+
pincode,
97+
};
98+
}
99+
79100
const sessionBody = {
80-
select_query: `select Session_Grade, LMS_Activity_ID, Explanation_Meeting_Link from Sessions where Session_Date_Time between '${formattedDateStart}' and '${formattedDateEnd}' and Session_Grade = '${gradeGroup}'`,
101+
select_query:
102+
!difficultyLevel || difficultyLevel === "Level 1"
103+
? `select Session_Grade, LMS_Activity_ID,Explanation_Meeting_Link from Sessions where (((Session_Grade = '${gradeGroup}') and (Session_Date_Time between '${formattedDateStart}' and '${formattedDateEnd}')) and (Difficulty != 'Level 2'))`
104+
: `select Session_Grade, LMS_Activity_ID,Explanation_Meeting_Link from Sessions where (((Session_Grade = '${gradeGroup}') and (Session_Date_Time between '${formattedDateStart}' and '${formattedDateEnd}')) and (Difficulty = 'Level 2'))`,
81105
};
82106

83107
const session = await axios.post(
@@ -93,27 +117,24 @@ const getMeetingLink = async (emailParam) => {
93117
};
94118
}
95119

96-
const attemptBody = {
97-
select_query: `select Session.id as Session_id, Session.Name as Session_Name,Session.Subject as Subject, Session.Number_of_Questions as Total_Questions, Session_Date_Time, Quiz_Score from Attempts where Contact_Name = '${contactid}'`,
98-
};
120+
// const attemptBody = {
121+
// select_query: `select Session.id as Session_id, Session.Name as Session_Name,Session.Subject as Subject, Session.Number_of_Questions as Total_Questions, Session_Date_Time, Quiz_Score from Attempts where Contact_Name = '${contactid}'`,
122+
// };
99123

100-
const attempt = await axios.post(
101-
`https://www.zohoapis.com/crm/v3/coql`,
102-
attemptBody,
103-
zohoConfig
104-
);
105-
const updateGrade = source_campaign === "old olympiad data" ? true : false;
124+
// const attempt = await axios.post(
125+
// `https://www.zohoapis.com/crm/v6/coql`,
126+
// attemptBody,
127+
// zohoConfig
128+
// );
106129

107-
const finalAddress = address
108-
? address
109-
: attempt.status === 200 && attempt.data.info.count <= 3
110-
? "Temp Address"
111-
: null;
130+
// const finalAddress = address
131+
// ? address
132+
// : attempt.status === 200 && attempt.data.info.count <= 3
133+
// ? "Temp Address"
134+
// : null;
112135

113136
const meetLink =
114-
!credits && session.status === 200
115-
? freeMeetLink
116-
: session.status === 200
137+
session.status === 200
117138
? session.data.data[0].Explanation_Meeting_Link
118139
: null;
119140

@@ -126,7 +147,7 @@ const getMeetingLink = async (emailParam) => {
126147
credits: credits,
127148
grade: grade,
128149
team: "not required",
129-
address: finalAddress,
150+
address: "Temp Address",
130151
pincode,
131152
};
132153
};

components/quiz.component.js

Lines changed: 9 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -22,60 +22,27 @@ const getQuizLink = async (emailParam) => {
2222
},
2323
};
2424
const contact = await axios.get(
25-
`https://www.zohoapis.com/crm/v2/Contacts/search?email=${emailParam}`,
25+
`https://www.zohoapis.com/crm/v6/Contacts/search?email=${emailParam}`,
2626
zohoConfig
2727
);
2828

2929
if (contact.status >= 400) {
30-
// let oldDate = new Date().setMinutes(new Date().getMinutes() + 330);
31-
// logsData.quizLogs?.push({
32-
// email: emailParam,
33-
// description: `internalservererrorinfindinguser ${contact.status}`,
34-
// date: new Date().toDateString(),
35-
// time: new Date(oldDate).toLocaleTimeString("en-US"),
36-
// });
37-
// logsData.quizLogs
38-
// ? fs.writeFile(
39-
// "./logs.json",
40-
// JSON.stringify(logsData, null, 2),
41-
// (err) => {
42-
// if (err) throw err;
43-
// }
44-
// )
45-
// : null;
4630
return {
4731
status: contact.status,
4832
mode: "internalservererrorinfindinguser",
4933
};
5034
}
51-
// return { contact };
5235
if (contact.status === 204) {
53-
// let oldDate = new Date().setMinutes(new Date().getMinutes() + 330);
54-
// logsData.quizLogs?.push({
55-
// email: emailParam,
56-
// description: `nouser ${contact.status}`,
57-
// date: new Date().toDateString(),
58-
// time: new Date(oldDate).toLocaleTimeString("en-US"),
59-
// });
60-
// logsData.quizLogs
61-
// ? fs.writeFile(
62-
// "./logs.json",
63-
// JSON.stringify(logsData, null, 2),
64-
// (err) => {
65-
// if (err) throw err;
66-
// }
67-
// )
68-
// : null;
6936
return {
7037
status: contact.status,
7138
mode: "nouser",
7239
};
7340
}
74-
// return contact.data.data[0];
7541

7642
const contactid = contact.data.data[0].id;
7743
const email = contact.data.data[0].Email;
7844
const grade = contact.data.data[0].Student_Grade;
45+
const difficultyLevel = contact.data.data[0].Difficulty;
7946

8047
let gradeGroup;
8148
if (grade == 1 || grade == 2) {
@@ -91,7 +58,8 @@ const getQuizLink = async (emailParam) => {
9158
const pincode = contact.data.data[0].Pincode;
9259
const date = new Date();
9360
const start = new Date();
94-
start.setMinutes(start.getMinutes() + 270);
61+
start.setMinutes(start.getMinutes() + 260);
62+
// start.setMinutes(start.getMinutes() + 0);
9563
const end = new Date();
9664
end.setHours(23, 59, 59, 999);
9765
const year = date.getFullYear();
@@ -105,55 +73,26 @@ const getQuizLink = async (emailParam) => {
10573
const formattedDateEnd = `${year}-${month}-${day}T${endHours}:${endMinutes}:00+05:30`;
10674

10775
const sessionBody = {
108-
select_query: `select Session_Grade, LMS_Activity_ID from Sessions where Session_Date_Time between '${formattedDateStart}' and '${formattedDateEnd}' and Session_Grade = '${gradeGroup}'`,
76+
select_query:
77+
!difficultyLevel || difficultyLevel === "Level 1"
78+
? `select Session_Grade, LMS_Activity_ID from Sessions where (((Session_Grade = '${gradeGroup}') and (Session_Date_Time between '${formattedDateStart}' and '${formattedDateEnd}')) and (Difficulty != 'Level 2'))`
79+
: `select Session_Grade, LMS_Activity_ID from Sessions where (((Session_Grade = '${gradeGroup}') and (Session_Date_Time between '${formattedDateStart}' and '${formattedDateEnd}')) and (Difficulty = 'Level 2'))`,
10980
};
11081

11182
const session = await axios.post(
112-
`https://www.zohoapis.com/crm/v3/coql`,
83+
`https://www.zohoapis.com/crm/v6/coql`,
11384
sessionBody,
11485
zohoConfig
11586
);
11687

11788
if (session.status >= 400) {
118-
// let oldDate = new Date().setMinutes(new Date().getMinutes() + 330);
119-
// logsData.quizLogs?.push({
120-
// email: emailParam,
121-
// description: `internalservererrorinfindingsession ${session.status}`,
122-
// date: new Date().toDateString(),
123-
// time: new Date(oldDate).toLocaleTimeString("en-US"),
124-
// });
125-
// logsData.quizLogs
126-
// ? fs.writeFile(
127-
// "./logs.json",
128-
// JSON.stringify(logsData, null, 2),
129-
// (err) => {
130-
// if (err) throw err;
131-
// }
132-
// )
133-
// : null;
13489
return {
13590
status: session.status,
13691
mode: "internalservererrorinfindingsession",
13792
};
13893
}
13994

14095
if (session.status === 204) {
141-
// let oldDate = new Date().setMinutes(new Date().getMinutes() + 330);
142-
// logsData.quizLogs?.push({
143-
// email: emailParam,
144-
// description: `nosession ${session.status}`,
145-
// date: new Date().toDateString(),
146-
// time: new Date(oldDate).toLocaleTimeString("en-US"),
147-
// });
148-
// logsData.quizLogs
149-
// ? fs.writeFile(
150-
// "./logs.json",
151-
// JSON.stringify(logsData, null, 2),
152-
// (err) => {
153-
// if (err) throw err;
154-
// }
155-
// )
156-
// : null;
15796
return {
15897
status: session.status,
15998
mode: "nosession",

components/student.component.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ const getStudentDetails = async (email) => {
4848
const grade = contact.data.data[0].Student_Grade;
4949
const address = contact.data.data[0].Address || null;
5050
const createdTime = contact.data.data[0].Created_Time;
51+
const difficultyLevel = contact.data.data[0].Difficulty;
52+
5153
const joinedWisechamps = contact.data.data[0].Joined_Wisechampions
5254
? true
5355
: false;
@@ -95,6 +97,11 @@ const getStudentDetails = async (email) => {
9597

9698
const weeklyQuizzesQuery = `select Name as Session_Name, Subject, Session_Date_Time, Session_Image_Link, Session_Video_Link, Session_Video_Link_2, Vevox_Survey_Link from Sessions where Session_Grade = '${gradeGroup}' and Session_Date_Time between '${sevenDaysBefore}' and '${sevenDaysAfter}' order by Session_Date_Time asc`;
9799

100+
// const weeklyQuizzesQuery =
101+
// !difficultyLevel || difficultyLevel === "Level 1"
102+
// ? `select Name as Session_Name, Subject, Session_Date_Time, Session_Image_Link, Session_Video_Link, Session_Video_Link_2, Vevox_Survey_Link from Sessions where (((Session_Grade = '${gradeGroup}') and (Session_Date_Time between '${sevenDaysBefore}' and '${sevenDaysAfter}')) and (Difficulty != 'Level 2')) order by Session_Date_Time asc`
103+
// : `select Name as Session_Name, Subject, Session_Date_Time, Session_Image_Link, Session_Video_Link, Session_Video_Link_2, Vevox_Survey_Link from Sessions where (((Session_Grade = '${gradeGroup}') and (Session_Date_Time between '${sevenDaysBefore}' and '${sevenDaysAfter}')) and (Difficulty = 'Level 2')) order by Session_Date_Time asc`;
104+
98105
const coinsQuery = `select Coins, Updated_Date, Action_Type, Description from Coins where Contact = '${contactId}' order by Updated_Date desc limit 2000`;
99106

100107
const [referrals, attempts, coinsHistory, weeklyQuizzes] =
@@ -179,6 +186,7 @@ const getStudentDetails = async (email) => {
179186
joinedWisechamps,
180187
weeklyQuizzes: finalWeeklyQuizzes,
181188
newUser,
189+
difficulty: difficultyLevel === "Level 2",
182190
};
183191
}
184192

@@ -224,6 +232,7 @@ const getStudentDetails = async (email) => {
224232
joinedWisechamps,
225233
weeklyQuizzes: finalWeeklyQuizzes,
226234
newUser,
235+
difficulty: difficultyLevel === "Level 2",
227236
};
228237
} catch (error) {
229238
throw new Error(error);

components/user.component.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -562,11 +562,57 @@ const getReferralAnalysisData = async () => {
562562
}
563563
};
564564

565+
const updateUserDifficulty = async ({ contactId, difficulty }) => {
566+
try {
567+
const zohoToken = await getZohoTokenOptimized();
568+
const zohoConfig = {
569+
headers: {
570+
"Content-Type": "application/json",
571+
"Access-Control-Allow-Origin": "*",
572+
Authorization: `Bearer ${zohoToken}`,
573+
},
574+
};
575+
576+
const body = {
577+
data: [
578+
{
579+
id: contactId,
580+
Difficulty: difficulty ? "Level 2" : "Level 1",
581+
},
582+
],
583+
duplicate_check_fields: ["id"],
584+
apply_feature_execution: [
585+
{
586+
name: "layout_rules",
587+
},
588+
],
589+
trigger: ["workflow"],
590+
};
591+
592+
const result = await axios.post(
593+
`https://www.zohoapis.com/crm/v6/Contacts/upsert`,
594+
body,
595+
zohoConfig
596+
);
597+
598+
return {
599+
status: result.status,
600+
message: "Difficulty Updated",
601+
};
602+
} catch (error) {
603+
return {
604+
status: error.status || 500,
605+
message: "error",
606+
};
607+
}
608+
};
609+
565610
module.exports = {
566611
getZohoUserDetailsWithPhone,
567612
getZohoUserDetailsWithEmail,
568613
addUserToZoho,
569614
generateAndSendOtp,
570615
resendOTP,
571616
getReferralAnalysisData,
617+
updateUserDifficulty,
572618
};

controllers/student.controller.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const {
1616
const { default: axios } = require("axios");
1717
const studentRouter = express.Router();
1818

19-
studentRouter.post("/", async (req, res) => {
19+
studentRouter.post("/", authMiddleware, async (req, res) => {
2020
try {
2121
const { email } = req.body;
2222
const data = await getStudentDetails(email);
@@ -127,7 +127,7 @@ studentRouter.post("/feedback", authMiddleware, async (req, res) => {
127127
}
128128
});
129129

130-
studentRouter.post("/tution/create", async (req, res) => {
130+
studentRouter.post("/tution/create", authMiddleware, async (req, res) => {
131131
try {
132132
const { teacherEmail, students } = req.body;
133133
const zohoToken = await getZohoTokenOptimized();

controllers/user.controller.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const {
66
generateAndSendOtp,
77
resendOTP,
88
getReferralAnalysisData,
9+
updateUserDifficulty,
910
} = require("../components/user.component");
1011
const { default: axios } = require("axios");
1112
const { authMiddleware } = require("../components/common.component");
@@ -38,6 +39,16 @@ userRouter.post("/add", async (req, res) => {
3839
}
3940
});
4041

42+
userRouter.post("/update", authMiddleware, async (req, res) => {
43+
try {
44+
const data = await updateUserDifficulty(req.body);
45+
return res.status(200).send(data);
46+
} catch (error) {
47+
console.log(error);
48+
return res.status(500).send(error);
49+
}
50+
});
51+
4152
userRouter.post("/verify", async (req, res) => {
4253
try {
4354
const { phone, email, lead_source, source_campaign } = req.body;

0 commit comments

Comments
 (0)