@@ -14,6 +14,7 @@ const config = require('../../config');
14
14
const cacheService = require ( '../cache-service' ) ;
15
15
const { createMoreFiltersSearchCriteria} = require ( './studentFilters' ) ;
16
16
const moment = require ( 'moment' ) ;
17
+ const { doesSchoolBelongToDistrict} = require ( '../institute-cache' ) ;
17
18
const { DateTimeFormatter, LocalDate, LocalDateTime} = require ( '@js-joda/core' ) ;
18
19
const { FILTER_OPERATION , VALUE_TYPE , CONDITION , ASSESSMENTS_REPORT_TYPE_CODE_MAP ,
19
20
ASSESSMENTS_STUDENT_REPORT_TYPE_CODE_MAP
@@ -291,6 +292,33 @@ async function downloadAssessmentStudentReport(req, res) {
291
292
292
293
const token = getAccessToken ( req ) ;
293
294
295
+ if ( reportType === 'ISR' ) {
296
+ let student = await getData ( token , `${ config . get ( 'gradCurrentStudents:rootURL' ) } /stdid/${ req . params . studentID } ` ) ;
297
+
298
+ if ( student . studentStatus === 'MER' ) {
299
+ return res . status ( HttpStatus . CONFLICT ) . json ( {
300
+ status : HttpStatus . CONFLICT ,
301
+ message : 'Student was merged to another student. You must specify an active student PEN.'
302
+ } ) ;
303
+ }
304
+
305
+ if ( req . session . activeInstituteType === 'DISTRICT' ) {
306
+ if ( ! doesSchoolBelongToDistrict ( student . schoolOfRecordId , req . session . activeInstituteIdentifier ) ) {
307
+ return res . status ( HttpStatus . CONFLICT ) . json ( {
308
+ status : HttpStatus . CONFLICT ,
309
+ message : 'The student\'s current School of Record is not within your district. The student’s reports cannot be accessed.'
310
+ } ) ;
311
+ }
312
+ } else if ( req . session . activeInstituteType === 'SCHOOL' ) {
313
+ if ( student . schoolOfRecordId !== req . session . activeInstituteIdentifier ) {
314
+ return res . status ( HttpStatus . CONFLICT ) . json ( {
315
+ status : HttpStatus . CONFLICT ,
316
+ message : 'Your school is not currently the student\'s School of Record. The student’s reports cannot be accessed.'
317
+ } ) ;
318
+ }
319
+ }
320
+ }
321
+
294
322
let url = `${ config . get ( 'assessments:rootURL' ) } /report/student/${ req . params . studentID } /${ reportType } /download` ;
295
323
296
324
const resData = await getData ( token , url ) ;
0 commit comments