Skip to content

Commit

Permalink
BA-1069 - Opportunities - remove code dupes
Browse files Browse the repository at this point in the history
  • Loading branch information
sutherlanda committed Mar 27, 2019
1 parent d486cfa commit b3ebf23
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,12 @@ class OpportunitiesCommonService implements IOpportunitiesCommonService {
return accum;
}, []);

if (opportunity.opportunityTypeCd === 'code-with-us') {
fields.cwu.forEach(elem => {
if (!elem[0]) {
errorFields.push(elem[1]);
}
});
} else {
fields.swu.forEach(elem => {
if (!elem[0]) {
errorFields.push(elem[1]);
}
});
}
const fieldSource = opportunity.opportunityTypeCd === 'code-with-us' ? fields.cwu : fields.swu;
fieldSource.forEach((elem: any) => {
if (!elem[0]) {
errorFields.push(elem[1]);
}
});
return errorFields;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -576,12 +576,7 @@ class OpportunitiesServerController {
zip.folder(opportunityName)
.folder(proponentName)
.file('index.html', content);
files.forEach(file => {
zip.folder(opportunityName)
.folder(proponentName)
.folder('docs')
.file(file.name, fs.readFileSync(file.path), { binary: true });
});
this.addFilesToZip(zip, opportunityName, proponentName, files);
});

res.setHeader('Content-Type', 'application/zip');
Expand Down Expand Up @@ -703,12 +698,7 @@ class OpportunitiesServerController {
zip.folder(opportunityName)
.folder(proponentName)
.file('proposal-summary.html', content);
files.forEach(file => {
zip.folder(opportunityName)
.folder(proponentName)
.folder('docs')
.file(file.name, fs.readFileSync(file.path), { binary: true });
});
this.addFilesToZip(zip, opportunityName, proponentName, files);

res.setHeader('Content-Type', 'application/zip');
res.setHeader('Content-Type', 'application/octet-stream');
Expand Down Expand Up @@ -1078,6 +1068,15 @@ The opportunity closes on <b>${deadline}</b>.</p>
.populate('addenda.createdBy', 'displayName')
.execPopulate();
};

private addFilesToZip(zip: JSZip, opportunityName: string, proponentName: string, files: IAttachmentModel[]): void {
files.forEach(file => {
zip.folder(opportunityName)
.folder(proponentName)
.folder('docs')
.file(file.name, fs.readFileSync(file.path), { binary: true });
});
}
}

export default OpportunitiesServerController.getInstance();

0 comments on commit b3ebf23

Please sign in to comment.