Skip to content

Commit

Permalink
Added logic to insert district number , renamed report name
Browse files Browse the repository at this point in the history
  • Loading branch information
Khaled Smaoui committed Sep 19, 2024
1 parent a05b6b4 commit c95d408
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
12 changes: 9 additions & 3 deletions backend/src/components/sdc/sdc.js
Original file line number Diff line number Diff line change
Expand Up @@ -864,6 +864,7 @@ async function downloadSdcReport(req, res) {
['csv_dis', 'ALL_STUDENT_DIS_CSV']
];
const REPORT_TYPE_CODE_MAP = Object.freeze(new Map(reportTypeValues));
const districtOrSchoolNumber= req.params.districtOrSchoolNumber;

try {
const reportType = REPORT_TYPE_CODE_MAP.get(req.params.reportTypeCode);
Expand All @@ -872,6 +873,11 @@ async function downloadSdcReport(req, res) {
message: 'Invalid report type provided'
});
}
if (!districtOrSchoolNumber) {
return res.status(HttpStatus.BAD_REQUEST).json({
message: 'Invalid report district or school code provided'
});
}
let url;
if(req.params.sdcDistrictCollectionID){
url = `${config.get('sdc:rootURL')}/reportGeneration/sdcDistrictCollection/${req.params.sdcDistrictCollectionID}/${reportType}`;
Expand All @@ -880,7 +886,7 @@ async function downloadSdcReport(req, res) {
}

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

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

function getFileDetails(reportType) {
function getFileDetails(reportType, districtOrSchoolNumber) {
const mappings = {
'ALL_STUDENT_DIS_CSV': { filename: 'AllDistrictStudents.csv', contentType: 'text/csv' },
'ALL_STUDENT_DIS_CSV': { filename: `AllStudents_District_${districtOrSchoolNumber}.csv`, contentType: 'text/csv' },
'ALL_STUDENT_SCHOOL_CSV': { filename: 'AllSchoolStudents.csv', contentType: 'text/csv' },
'DEFAULT': { filename: 'download.pdf', contentType: 'application/pdf' }
};
Expand Down
4 changes: 2 additions & 2 deletions backend/src/routes/sdc.js

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

Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ export default {
},
downloadReportURL() {
if (this.indySchoolDistrictObject != null) {
if (this.indySchoolDistrictObject.type === 'indy') return `${Routes.sdc.BASE_URL}/${this.indySchoolDistrictObject.id}/report/csv_school/download`;
if (this.indySchoolDistrictObject.type === 'district') return `${Routes.sdc.SDC_DISTRICT_COLLECTION}/${this.indySchoolDistrictObject.id}/report/csv_dis/download`;
if (this.indySchoolDistrictObject.type === 'indy') return `${Routes.sdc.BASE_URL}/${this.indySchoolDistrictObject.id}/${this.indySchoolDistrictObject.code}/report/csv_school/download`;
if (this.indySchoolDistrictObject.type === 'district') return `${Routes.sdc.SDC_DISTRICT_COLLECTION}/${this.indySchoolDistrictObject.id}/${this.indySchoolDistrictObject.code}/report/csv_dis/download`;
}
return `${Routes.sdc.SDC_DISTRICT_COLLECTION}/${this.$route.params.sdcDistrictCollectionID}/report/csv_dis/download`;
return `${Routes.sdc.SDC_DISTRICT_COLLECTION}/${this.$route.params.sdcDistrictCollectionID}/-1/report/csv_dis/download`;
},
editStudent($event) {
const selectedStudent = cloneDeep($event);
Expand Down
21 changes: 12 additions & 9 deletions frontend/src/components/data-collection/FundingPolicyReports.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
single-line
:clearable="true"
item-title="codeName"
item-value="id"
item-value="school"
autocomplete="off"
@update:model-value="setIndySchoolsDistrictsNameNumberFilter('indy', $event)"
/>
Expand All @@ -34,7 +34,7 @@
single-line
:clearable="true"
item-title="codeName"
item-value="id"
item-value="district"
autocomplete="off"
@update:model-value="setIndySchoolsDistrictsNameNumberFilter('district', $event)"
/>
Expand Down Expand Up @@ -98,7 +98,7 @@ export default {
methods: {
setIndySchoolsDistrictsNameNumberFilter(key, $event) {
if ($event) {
this.indySchoolDistrictObject = { type: key, id: $event };
this.indySchoolDistrictObject = { type: key, id: $event.id, code :$event.code };
} else {
this.indySchoolDistrictObject = null;
}
Expand All @@ -115,13 +115,15 @@ export default {
if (school && school.authorityID != null) {
let schoolItem = {
codeName: school.schoolName + ' - ' + school.mincode,
id: schoolCollection.sdcSchoolCollectionID,
mincode: school.mincode
school: {
id: schoolCollection.sdcSchoolCollectionID,
code: school.mincode
}
};
this.indySchoolNames.push(schoolItem);
}
});
this.indySchoolNames = sortBy(this.indySchoolNames, ['mincode']);
this.indySchoolNames = sortBy(this.indySchoolNames, ['school.mincode']);
})
.catch(error => {
console.error(error);
Expand All @@ -134,13 +136,14 @@ export default {
if (district) {
let districtItem = {
codeName: district.name + ' - ' + district.districtNumber,
id: districtCollection.sdcDistrictCollectionID,
districtNumber: district.districtNumber
district: {
id: districtCollection.sdcDistrictCollectionID,
code: district.districtNumber}
};
this.districtNames.push(districtItem);
}
});
this.districtNames = sortBy(this.districtNames, ['districtNumber']);
this.districtNames = sortBy(this.districtNames, ['district.districtNumber']);
})
.catch(error => {
console.error(error);
Expand Down

0 comments on commit c95d408

Please sign in to comment.