-
Notifications
You must be signed in to change notification settings - Fork 0
/
gtu.js
98 lines (88 loc) · 2.73 KB
/
gtu.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const { defaultHeaders, hostUrl } = require('./config')
const { default: axios } = require('axios')
const qs = require('querystring')
const generateDeviceId = require('./utils/deviceId')
const populateResult = require('./formatters/populate')
const getBranchById = require('./utils/branchById')
class GTUResults {
constructor() { }
static async getSessions() {
const data = {
'ReqOperation': 'GetSession'
}
const res = await axios({
method: 'POST',
url: hostUrl,
headers: defaultHeaders,
data: qs.stringify(data),
responseType: 'json'
})
return res.data
}
static async getCourse(examSession) {
const data = {
'ReqOperation': 'GetCourse',
'ExSession': examSession
}
const res = await axios({
method: 'POST',
url: hostUrl,
headers: defaultHeaders,
data: qs.stringify(data),
responseType: 'json'
})
return res.data
}
static async getExam(examSession, examType) {
const data = {
'ReqOperation': 'GetExamName',
'ExSession': examSession,
'ExType': examType
}
const res = await axios({
method: 'POST',
url: hostUrl,
headers: defaultHeaders,
data: qs.stringify(data),
responseType: 'json'
})
return res.data
}
/**
*
* @param {string|number} enrollment Your Enrollment number
* @param {number} examId exam id from @function getExam
* @param {object} options branchBy: 'id' | 'name'
* @returns
*/
static async fromEnrollment(enrollment, examId) {
const data = {
'ReqOperation': 'StudentResult',
'ExamID': String(examId),
'EnrNo': String(enrollment),
'DeviceId': generateDeviceId(),
'OSversion': '29',
'LatLong': '0',
'MobileNo': '916929696969',
'IMEI_NO': '0',
'IPAddress': '7a54:8059:4d78:551f:6065:9eda:7720:f6eb%dummy0',
'IsCurrent': '0'
}
const res = await axios({
method: 'POST',
url: hostUrl,
headers: defaultHeaders,
data: qs.stringify(data),
responseType: 'json'
})
// check if contains json
if(res.data == "No Results Found") {
return { message: res.data }
}
// formatting data
const fullResult = await populateResult(res.data, enrollment, examId)
fullResult.BR_NAME = getBranchById(fullResult.BR_CODE).name
return fullResult
}
}
module.exports = GTUResults