Skip to content

Commit 05e3081

Browse files
Merge pull request #2328 from bcgov/feature/eac-96
EAC-96: CSV output for Assessment Results by school.
2 parents d27f042 + d4772c4 commit 05e3081

File tree

3 files changed

+58
-19
lines changed

3 files changed

+58
-19
lines changed

backend/src/components/assessments/assessments.js

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ async function updateAssessmentStudentByID(req, res) {
201201
async function downloadXamFile(req, res) {
202202
try {
203203
const token = getAccessToken(req);
204-
const url = `${config.get('assessments:rootURL')}/report/${req.params.sessionID}/school/${req.params.schoolID}/download`;
204+
const url = `${config.get('assessments:rootURL')}/report/${req.params.sessionID}/school/${req.params.schoolID}/XAM_FILE/download`;
205205

206206
const data = await getData(token, url);
207207

@@ -222,6 +222,30 @@ async function downloadXamFile(req, res) {
222222
}
223223
}
224224

225+
async function downloadAssessmentSessionResultsCSVFile(req, res) {
226+
try {
227+
const token = getAccessToken(req);
228+
const url = `${config.get('assessments:rootURL')}/report/${req.params.sessionID}/school/${req.params.schoolID}/SESSION_RESULTS/download`;
229+
230+
const data = await getData(token, url);
231+
232+
const fileName = `${data?.reportType || 'SessionResults.csv'}`;
233+
res.setHeader('Content-Type', 'text/csv');
234+
res.setHeader('Content-Disposition', `attachment; filename=${fileName}`);
235+
236+
if (data && data.documentData) {
237+
const buffer = Buffer.from(data.documentData, 'base64');
238+
return res.send(buffer);
239+
} else {
240+
const emptyBuffer = Buffer.from('');
241+
return res.send(emptyBuffer);
242+
}
243+
} catch (e) {
244+
log.error(e, 'downloadAssessmentSessionResultsCSVFile', 'An error occurred while attempting to download the Assessment Session Results CSV file.');
245+
return handleExceptionResponse(e, res);
246+
}
247+
}
248+
225249
function getSchoolName(school) {
226250
return school.mincode + ' - ' + school.schoolName;
227251
}
@@ -253,6 +277,7 @@ module.exports = {
253277
removeAssessmentStudents,
254278
getAssessmentSpecialCases,
255279
postAssessmentStudent,
256-
downloadXamFile
280+
downloadXamFile,
281+
downloadAssessmentSessionResultsCSVFile
257282
};
258283

backend/src/routes/assessments.js

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/src/components/assessments/reports/AssessmentReports.vue

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@
178178
<v-col cols="12">
179179
<DownloadLink
180180
label="Session Results.csv"
181-
:download-action="() => downloadDetailedDOARReport()"
181+
:download-action="() => downloadAssessmentResultCSV()"
182182
/>
183183
</v-col>
184184
</v-row>
@@ -290,22 +290,23 @@ export default {
290290
schoolNameNumberFilter: null,
291291
schoolSearchNames: [],
292292
selectedSessionID: null,
293-
isDistrictUser: false,
294-
schoolUserSchoolID: null
295293
};
296294
},
297295
computed: {
298296
...mapState(appStore, ['schoolsMap']),
299297
...mapState(authStore, ['userInfo']),
300298
disableCondition() {
301299
return this.userInfo.activeInstituteType === 'DISTRICT' ? (!this.schoolNameNumberFilter || !this.selectedSessionID) : !this.selectedSessionID;
300+
},
301+
schoolIdentifierForReports() {
302+
if (this.userInfo.activeInstituteType === 'SCHOOL') {
303+
return this.userInfo.activeInstituteIdentifier;
304+
}
305+
return this.schoolNameNumberFilter;
302306
}
303307
},
304308
async created() {
305-
authStore().getUserInfo().then(() => {
306-
this.isDistrictUser = this.userInfo.activeInstituteType !== 'SCHOOL';
307-
this.schoolUserSchoolID = this.userInfo.activeInstituteType === 'SCHOOL' ? this.userInfo.activeInstituteIdentifier : null;
308-
});
309+
authStore().getUserInfo();
309310
await this.getAllSessions();
310311
this.setupSchoolLists();
311312
},
@@ -377,7 +378,21 @@ export default {
377378
this.isSearchingStudent = false;
378379
});
379380
},
380-
381+
async downloadAssessmentResultCSV() {
382+
this.isLoading = true;
383+
try {
384+
const url = `${ApiRoutes.assessments.BASE_REPORTS_URL}/${this.userInfo.activeInstituteType.toLowerCase()}/${this.selectedSessionID}/school/${this.schoolIdentifierForReports}/sessionResultsCSV/download`;
385+
window.open(url);
386+
} catch (error) {
387+
console.error(error);
388+
this.setFailureAlert(
389+
error?.response?.data?.message ? error?.response?.data?.message : 'An error occurred while trying to retrieve your school\'s report.'
390+
);
391+
} finally {
392+
this.isLoading = false;
393+
}
394+
395+
},
381396
async downloadStudentReport() {
382397
383398
},
@@ -388,20 +403,17 @@ export default {
388403
389404
},
390405
async downloadAssessmentResults() {
391-
406+
392407
},
393408
async downloadXamFile() {
394409
this.isLoading = true;
395410
try {
396-
const url = `${ApiRoutes.assessments.BASE_REPORTS_URL}/${this.userInfo.activeInstituteType}/${this.selectedSessionID}/school/${
397-
this.isDistrictUser ? this.schoolNameNumberFilter : this.schoolUserSchoolID}/download`;
411+
const url = `${ApiRoutes.assessments.BASE_REPORTS_URL}/${this.userInfo.activeInstituteType.toLowerCase()}/${this.selectedSessionID}/school/${this.schoolIdentifierForReports}/xam/download`;
398412
window.open(url);
399413
} catch (error) {
400414
console.error(error);
401415
this.setFailureAlert(
402-
error?.response?.data?.message
403-
? error?.response?.data?.message
404-
: 'An error occurred while trying to retrieve your school\'s report.'
416+
error?.response?.data?.message ? error?.response?.data?.message : 'An error occurred while trying to retrieve your school\'s report.'
405417
);
406418
} finally {
407419
this.isLoading = false;

0 commit comments

Comments
 (0)