Skip to content

Commit

Permalink
Merge pull request #105 from gazaskygeeks/forms
Browse files Browse the repository at this point in the history
mentor.info obj
  • Loading branch information
Salam-Dalloul authored Mar 19, 2018
2 parents c0a99f0 + aa114a1 commit 6c0d9f5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/client/components/mentorForm/MentorForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ class MentorForm extends Component {
type={type}
name={title}
onBlur={this.handleInputChange}/>}
{ type === 'email' &&
<input
type={type}
name={title}
onBlur={this.handleInputChange}/>}
{ type === 'checkbox' &&
<Checkbox
name={title}
Expand Down
27 changes: 18 additions & 9 deletions src/server/controllers/postForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,22 @@ module.exports = (req, res) => {
const formattedBody = {
formName: `${req.body.name} : ${req.body.title}`,
entryDate: new Date().toString().slice(0, 24),
nodes: req.body.nodes.map(node => {
return ({
[node.composed]:
nodes: req.body.nodes
.map(node => {
return ({
[node.composed]:
(node.value !== undefined ? node.value : 'NOT AVAIL'),
required: (node.required !== undefined ? node.required : 'NOT AVAIL')
});
}).filter(node => Object.keys(node)[0] !== 'undefined' && Object.keys(node)[0] !== 'null'),
required: (node.required !== undefined ? node.required : 'NOT AVAIL')
});
}).filter(node => {
return Object.keys(node)[0] !== 'undefined' &&
Object.keys(node)[0] !== 'null' &&
Object.keys(node)[0] !== 'first_name' &&
Object.keys(node)[0] !== 'surname' &&
Object.keys(node)[0] !== 'email_address';
}),
mentorID: req.body.mentorID
};
delete formattedBody.nodes.null;
selectSingleMentor(formattedBody.mentorID, (selectErr, selectRes) => {
if (selectErr) throw new Error(selectErr);
const singleMentor = selectRes.rows[0];
Expand All @@ -28,8 +34,11 @@ module.exports = (req, res) => {
date_of_departure: singleMentor.date_of_departure,
info: singleMentor.info
};
const index = Object.keys(mentorObj).length;
mentorObj.info[index] = formattedBody;
const lastSavedInfo = { ...mentorObj.info };
formattedBody.nodes.forEach(node => {
mentorObj.info[Object.keys(node)[0]] = Object.values(node)[0];
});
mentorObj.info.lastSavedInfo = lastSavedInfo;
updateMentor(mentorObj, (updateErr, updateRes) => {
if (updateErr) throw new Error(updateErr);
res.send(updateRes.rowCount === 1 ? 'MentorUpdated' : 'MentorNotFound');
Expand Down

0 comments on commit 6c0d9f5

Please sign in to comment.