Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed report filename, added logic to insert district/school number #2067

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading