Skip to content

Commit

Permalink
fixed the issue ECLK#146
Browse files Browse the repository at this point in the history
  • Loading branch information
yasirunilan committed Feb 16, 2020
1 parent 4487aa1 commit 2a39d89
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 1 deletion.
32 changes: 32 additions & 0 deletions client/src/modules/nomination/Nomination_review.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ import CommentIcon from '@material-ui/icons/InsertComment';
import IconButton from "@material-ui/core/IconButton";
import Slide from '@material-ui/core/Slide';
import TextField from '@material-ui/core/TextField';
import axios from "axios";
import {API_BASE_URL} from "../../config";
import download from "downloadjs";
import GetAppIcon from '@material-ui/icons/GetApp';

const drawerWidth = 240;

Expand Down Expand Up @@ -230,6 +234,25 @@ class NominationReview extends React.Component {
[name]: event.target.value,
});
};

downloadCandidateDocuments = (candidate) => {
axios.get(`${API_BASE_URL}/nominations/candidates/${candidate.id}/support-docs/download`, {responseType: 'blob'}, {
}).then((response) => {
download(new Blob([response.data]), 'candidate_support_docs_'+candidate.id+'.zip', response.headers['content-type']);
}).catch(err => {
console.log(err)
});
};

downloadNominationDocuments = (nomination) => {
axios.get(`${API_BASE_URL}/nominations/${nomination.id}/support-docs/download`, {responseType: 'blob'}, {
}).then((response) => {
download(new Blob([response.data]), 'nomination_support_docs_'+nomination.id+'.zip', response.headers['content-type']);
}).catch(err => {
console.log(err)
});
};

render() {
const { classes, nominations, ApproveElections, partyList } = this.props;
const { expandedPanelIndex } = this.state;
Expand Down Expand Up @@ -270,6 +293,9 @@ class NominationReview extends React.Component {
<TableCell className={classes.candidate_table_cell} align="left">
{candidate.address}
</TableCell>
<TableCell onClick={() => { this.downloadCandidateDocuments(candidate) }} className={classes.candidate_table_cell} align="left">
<GetAppIcon style={{marginRight:10,marginBottom:-2}} className={classes.left_icon} />
</TableCell>
</TableRow>
</React.Fragment>
);
Expand Down Expand Up @@ -321,6 +347,7 @@ class NominationReview extends React.Component {
<TableCell align="left">Full Name</TableCell>
<TableCell align="left">Occupation</TableCell>
<TableCell align="left">Address</TableCell>
<TableCell align="left">Documents</TableCell>
</TableHead>
<TableBody>
{
Expand Down Expand Up @@ -360,6 +387,11 @@ class NominationReview extends React.Component {
</Grid>
<br />
</ExpansionPanelDetails>
<Button
onClick={() => { this.downloadNominationDocuments(nomination) }}
className={classNames(classes.button, classes.green_button)}>Download Nomination Documents
<GetAppIcon style={{marginRight:10,marginBottom:-2}} className={classes.left_icon} />
</Button>
</ExpansionPanel>
));

Expand Down
24 changes: 24 additions & 0 deletions server/api-docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,30 @@ paths:
description: ''
x-auth-type: Application & Application User
x-throttling-tier: Unlimited
'/nominations/candidates/{candidateId}/support-docs/download':
get:
parameters:
- name: candidateId
in: path
required: true
type: string
responses:
'200':
description: ''
x-auth-type: Application & Application User
x-throttling-tier: Unlimited
'/nominations/{nominationId}/support-docs/download':
get:
parameters:
- name: nominationId
in: path
required: true
type: string
responses:
'200':
description: ''
x-auth-type: Application & Application User
x-throttling-tier: Unlimited
info:
title: Nomination
version: '0.9'
Expand Down
1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"dotenv": "^2.0.0",
"express": "^4.14.0",
"express-fileupload": "^1.1.1-alpha.1",
"express-zip": "^3.0.0",
"flow-runtime": "^0.2.1",
"fraction.js": "^3.3.1",
"globule": "^1.1.0",
Expand Down
43 changes: 42 additions & 1 deletion server/src/repository/supportdoc.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ const CANDIDATE_SUPPORT_DOC_BY_DOC_ID_AND_NOMINATION_ID_SELECT_QUERY = `SELECT
FROM NOMINATION_SUPPORT_DOC WHERE SUPPORT_DOC_CONFIG_ID=:documentId AND NOMINATION_ID=:nominationId`;


const CANDIDATE_SUPPORT_DOCS_BY_CANDIDATE_ID_SELECT_QUERY = `SELECT
ID AS SUPPORT_DOC_id,
ORIGINAL_NAME AS SUPPORT_DOC_originalname,
FILE_PATH AS SUPPORT_DOC_filename
FROM CANDIDATE_SUPPORT_DOC WHERE CANDIDATE_ID=:candidateId`;


const CANDIDATE_SUPPORT_DOCS_BY_NOMINATION_ID_SELECT_QUERY = `SELECT
ID AS SUPPORT_DOC_id,
ORIGINAL_NAME AS SUPPORT_DOC_originalname,
FILE_PATH AS SUPPORT_DOC_filename
FROM NOMINATION_SUPPORT_DOC WHERE NOMINATION_ID=:nominationId`;

const getSupportDocByNomination = (nominationId) => {
const params = { nominationId: nominationId };
return DbConnection()
Expand Down Expand Up @@ -229,6 +242,32 @@ const getSupportDocByNominationIdAndDocId = (documentId, nominationId) => {
});
}

const getSupportDocsByCandidateId = (candidateId) => {
const params = { candidateId: candidateId };
return DbConnection()
.query(CANDIDATE_SUPPORT_DOCS_BY_CANDIDATE_ID_SELECT_QUERY,
{
replacements: params,
type: DbConnection().QueryTypes.SELECT,
}).catch((error) => {
throw new DBError(error);
});
}


const getSupportDocsByNominationId = (nominationId) => {
const params = { nominationId: nominationId };
return DbConnection()
.query(CANDIDATE_SUPPORT_DOCS_BY_NOMINATION_ID_SELECT_QUERY,
{
replacements: params,
type: DbConnection().QueryTypes.SELECT,
}).catch((error) => {
throw new DBError(error);
});
}




// ***************** SUPPORT_DOC_CONFIG_DATA ******************
Expand Down Expand Up @@ -308,5 +347,7 @@ export default {
updatePaymentSupportDocs,
getSupportDocByPayment,
getSupportDocByCandidateIdAndDocId,
getSupportDocByNominationIdAndDocId
getSupportDocByNominationIdAndDocId,
getSupportDocsByCandidateId,
getSupportDocsByNominationId
}
20 changes: 20 additions & 0 deletions server/src/routes/nominationRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { PaymentService, CandidateService, SupportDocService, NominationService,
import { SAVE_PAYMENT_SCHEMA, UPDATE_PAYMENT_SCHEMA, SAVE_SUPPORT_DOC_SCHEMA, UPDATE_SUPPORT_DOC_SCHEMA, SAVE_CANDIDATE_SCHEMA, SAVE_CANDIDATE_SUPPORT_DOCS_SCHEMA, SAVE_NOMINATION_APPROVE_SCHEMA } from './schema/nominationSchema';
import { HTTP_CODE_404, HTTP_CODE_201, HTTP_CODE_200 } from '../routes/constants/HttpCodes';
const multer = require('multer');
const zip = require('express-zip');


// SET STORAGE
var storage = multer.diskStorage({
Expand Down Expand Up @@ -266,6 +268,24 @@ export const initNominationRouter = (app) => {
.catch(error => next(error));
},
},
{
method: GET,
path: '/nominations/candidates/:candidateId/support-docs/download',
handler: (req, res, next) => {
return SupportDocService.getSupportDocsByCandidateIdNumber(req)
.then((result) => res.zip(result))
.catch(error => next(error));
},
},
{
method: GET,
path: '/nominations/:nominationId/support-docs/download',
handler: (req, res, next) => {
return SupportDocService.getSupportDocsByNominationIdNumber(req)
.then((result) => res.zip(result))
.catch(error => next(error));
},
},
// {
// method: POST,
// path: '/upload',
Expand Down
43 changes: 43 additions & 0 deletions server/src/service/supportDocService.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,47 @@ const getSupportDocByNominationIdAndDocId = async (req) => {

};

//Get support documents for a particular candidate
const getSupportDocsByCandidateIdNumber = async (req) => {
try {
const candidateId = req.params.candidateId;
const supportDocs = await SupportDocRepo.getSupportDocsByCandidateId(candidateId);
const docs = [];
if(!_.isEmpty(supportDocs)){
supportDocs.forEach(function(item){
docs.push({path: './src/uploads/'+item.SUPPORT_DOC_filename, name: item.SUPPORT_DOC_originalname});
});
return docs;
}else {
throw new ApiError("Support Documents not found",HTTP_CODE_404);
}
}catch (e){
throw new ServerError("server error");
}

};


//Get support documents for a particular nomination
const getSupportDocsByNominationIdNumber = async (req) => {
try {
const nominationId = req.params.nominationId;
const supportDocs = await SupportDocRepo.getSupportDocsByNominationId(nominationId);
const docs = [];
if(!_.isEmpty(supportDocs)){
supportDocs.forEach(function(item){
docs.push({path: './src/uploads/'+item.SUPPORT_DOC_filename, name: item.SUPPORT_DOC_originalname});
});
return docs;
}else {
throw new ApiError("Support Documents not found",HTTP_CODE_404);
}
}catch (e){
throw new ServerError("server error");
}

};

export default {
getsupportDocsByNominationId,
saveSupportDocsByNominationId,
Expand All @@ -267,4 +308,6 @@ export default {
getSupportDocsByPaymentId,
getSupportDocsByCandidateIdAndDocId,
getSupportDocByNominationIdAndDocId,
getSupportDocsByCandidateIdNumber,
getSupportDocsByNominationIdNumber
}

0 comments on commit 2a39d89

Please # to comment.