Skip to content

Commit

Permalink
Renamed report filename, added logic to insert district/school number
Browse files Browse the repository at this point in the history
  • Loading branch information
Khaled Smaoui committed Sep 23, 2024
1 parent a05b6b4 commit ae0ae66
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
27 changes: 23 additions & 4 deletions backend/src/components/sdc/sdc.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,16 @@ async function getSDCSchoolCollectionDetail(req, res) {
}
}

async function getSDCDistrictCollectionDetail(req, res) {
try {
let sdcDistrictCollectionData = await getData(`${config.get('sdc:districtCollectionURL')}/${req.params.sdcDistrictCollectionID}`);
return res.status(HttpStatus.OK).json(sdcDistrictCollectionData);
} catch (e) {
logApiError(e, 'Error getting sdc district collection detail');
return errorResponse(res);
}
}

async function getSDCSchoolCollectionStudentDetail(req, res) {
try {
let sdcSchoolCollectionStudentData = await getData(`${config.get('sdc:schoolCollectionStudentURL')}/${req.params.sdcSchoolCollectionStudentID}`);
Expand Down Expand Up @@ -873,14 +883,22 @@ async function downloadSdcReport(req, res) {
});
}
let url;
let schoolOrDistrictNumber;
if(req.params.sdcDistrictCollectionID){
url = `${config.get('sdc:rootURL')}/reportGeneration/sdcDistrictCollection/${req.params.sdcDistrictCollectionID}/${reportType}`;
let districtResponse = await getData(`${config.get('sdc:districtCollectionURL')}/${req.params.sdcDistrictCollectionID}`);
let districtId = districtResponse.districtID;
schoolOrDistrictNumber = cacheService.getDistrictJSONByDistrictId(districtId).districtNumber;
} else {
url = `${config.get('sdc:rootURL')}/reportGeneration/sdcSchoolCollection/${req.params.sdcSchoolCollectionID}/${reportType}`;
let schoolResponse = await getData(`${config.get('sdc:schoolCollectionURL')}/${req.params.sdcSchoolCollectionID}`);
let schoolId = schoolResponse.schoolID;
schoolOrDistrictNumber = cacheService.getSchoolBySchoolID(schoolId).mincode;
}


const resData = await getData(url);
const fileDetails = getFileDetails(reportType);
const fileDetails = getFileDetails(reportType, schoolOrDistrictNumber);

setResponseHeaders(res, fileDetails);
const buffer = Buffer.from(resData.documentData, 'base64');
Expand Down Expand Up @@ -916,10 +934,10 @@ async function getDistrictHeadcounts(req, res) {
}
}

function getFileDetails(reportType) {
function getFileDetails(reportType, schoolOrDistrictNumber) {
const mappings = {
'ALL_STUDENT_DIS_CSV': { filename: 'AllDistrictStudents.csv', contentType: 'text/csv' },
'ALL_STUDENT_SCHOOL_CSV': { filename: 'AllSchoolStudents.csv', contentType: 'text/csv' },
'ALL_STUDENT_DIS_CSV': { filename: `AllStudents_District_${schoolOrDistrictNumber}`, contentType: 'text/csv' },
'ALL_STUDENT_SCHOOL_CSV': { filename: `AllStudents_School_${schoolOrDistrictNumber}`, contentType: 'text/csv' },
'DEFAULT': { filename: 'download.pdf', contentType: 'application/pdf' }
};
return mappings[reportType] || mappings['DEFAULT'];
Expand All @@ -939,6 +957,7 @@ module.exports = {
unsubmitSdcDistrictCollection,
unsubmitSdcSchoolCollection,
getSDCSchoolCollectionDetail,
getSDCDistrictCollectionDetail,
getSDCSchoolCollectionStudentPaginated,
getSDCSchoolCollectionStudentDetail,
getInDistrictDuplicates,
Expand Down
3 changes: 2 additions & 1 deletion backend/src/routes/sdc.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ae0ae66

Please sign in to comment.