Skip to content

Commit 3129fd8

Browse files
committed
start of psi report download
1 parent d519cc0 commit 3129fd8

File tree

5 files changed

+104
-2
lines changed

5 files changed

+104
-2
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
'use strict';
2+
const {
3+
getAccessToken,
4+
getData,
5+
handleExceptionResponse
6+
} = require('../utils');
7+
const HttpStatus = require('http-status-codes');
8+
const config = require('../../config');
9+
const log = require('../logger');
10+
const {doesSchoolBelongToDistrict} = require('../institute-cache');
11+
12+
13+
async function downloadPsiSelectionReport(req, res) {
14+
try {
15+
console.log(req.params.schoolID);
16+
if(req.session.activeInstituteType === 'DISTRICT'){
17+
if(!doesSchoolBelongToDistrict(req.params.schoolID, req.session.activeInstituteIdentifier)){
18+
return res.status(HttpStatus.CONFLICT).json({
19+
status: HttpStatus.CONFLICT,
20+
message: 'The school is not within your district. The report cannot be accessed.'
21+
});
22+
} else {
23+
return res.status(HttpStatus.CONFLICT).json({
24+
status: HttpStatus.CONFLICT,
25+
message: 'This report is only available to schools.'
26+
});
27+
}
28+
}else if(req.session.activeInstituteType === 'SCHOOL'){
29+
if(req.params.schoolID !== req.session.activeInstituteIdentifier){
30+
return res.status(HttpStatus.CONFLICT).json({
31+
status: HttpStatus.CONFLICT,
32+
message: 'Your school is not your school. The report cannot be accessed.'
33+
});
34+
}
35+
}
36+
37+
38+
const token = getAccessToken(req);
39+
40+
let url = `${config.get('psiSelection:rootURL')}/report/school/${req.params.schoolID}`;
41+
42+
const resData = await getData(token, url);
43+
const fileDetails = getFileDetails('psi', null, null);
44+
45+
setResponseHeaders(res, fileDetails);
46+
const buffer = Buffer.from(resData.documentData, 'base64');
47+
return res.status(HttpStatus.OK).send(buffer);
48+
} catch (e) {
49+
log.error('downloadPsiReport Error', e.stack);
50+
return handleExceptionResponse(e, res);
51+
}
52+
}
53+
54+
function setResponseHeaders(res, { filename, contentType }) {
55+
res.setHeader('Content-Disposition', `attachment; filename=${filename}`);
56+
res.setHeader('Content-Type', contentType);
57+
}
58+
59+
60+
function getFileDetails(reportType) {
61+
const mappings = {
62+
63+
'DEFAULT': { filename: 'download.csv', contentType: 'text/csv' }
64+
};
65+
return mappings[reportType] || mappings['DEFAULT'];
66+
}
67+
68+
module.exports = {
69+
downloadPsiSelectionReport
70+
};
71+

backend/src/config/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ nconf.defaults({
174174
assessmentSpecialCaseTypeCodeURL: process.env.ASSESSMENT_API_ENDPOINT+ '/assessment-specialcase-types',
175175
assessmentStudentsURL: process.env.ASSESSMENT_API_ENDPOINT+ '/student',
176176
},
177+
psiSelection:{
178+
rootURL: process.env.PSI_SELECTION_API_ENDPOINT,
179+
},
177180
challengeReports:{
178181
rootURL: process.env.CHALLENGE_REPORTS_API_ENDPOINT
179182
}

backend/src/routes/psiSelection.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const express = require('express');
2+
const router = express.Router();
3+
const { downloadPsiSelectionReport } = require('../components/psiSelection');
4+
const auth = require('../components/auth');
5+
const isValidBackendToken = auth.isValidBackendToken();
6+
const { isValidUUIDParam, validateAccessToken, checkEdxUserPermission } = require('../components/permissionUtils');
7+
const { PERMISSION } = require('../util/Permission');
8+
9+
10+
router.get('/psi/reports/school/:schoolID', auth.refreshJWT, isValidBackendToken, validateAccessToken, isValidUUIDParam('schoolID'), checkEdxUserPermission(PERMISSION.EAS_SCH_VIEW), downloadPsiSelectionReport);
11+
12+
module.exports = router;

frontend/src/components/graduation/school/GraduationSchoolTabs.vue

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@
3636
>
3737
Current Students in GRAD System
3838
</v-tab>
39+
<v-tab
40+
id="psiSelections"
41+
value="psiSelections"
42+
prepend-icon="mdi-account-school-outline"
43+
>
44+
PSI Selections
45+
</v-tab>
3946
</v-tabs>
4047
</v-col>
4148
</v-row>
@@ -81,6 +88,15 @@
8188
:school-i-d="schoolID"
8289
/>
8390
</v-window-item>
91+
<v-window-item
92+
value="psiSelections"
93+
transition="false"
94+
reverse-transition="false"
95+
>
96+
<div>
97+
todo
98+
</div>
99+
</v-window-item>
84100
</v-window>
85101
</v-card-text>
86102
</v-col>

0 commit comments

Comments
 (0)