Skip to content

Commit

Permalink
started implementing #12
Browse files Browse the repository at this point in the history
  • Loading branch information
Michel Wohlert committed Feb 21, 2017
1 parent ae60305 commit 44d6dd1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/client/component/pages/ContestantForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ class ContestantForm extends Component {
this.setState({lastName_error: 'Bitte gebe Nachnamen an'});
errors++;
}
if ($course.val().length < 1) {
/* if ($course.val().length < 1) {
this.setState({course_error: 'Bitte gebe einen Studiengang an'});
errors++;
}
if ($year.val().length < 1) {
this.setState({year_error: 'Bitte gebe einen Jahrgang an'});
errors++;
}
}*/
if ($description.val().length < 1) {
this.setState({description_error: 'Bitte gebe eine Beschreibung an'});
errors++;
Expand Down
42 changes: 20 additions & 22 deletions src/server/controller/api/contestant/contestantApiController.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,34 @@ module.exports = class ContestantApiController {
static save(request, response, next) {
// TODO: check if strings are empty


if (request.body.firstName === undefined || request.body.lastName === undefined) {
if (request.body.firstName === undefined || request.body.lastName === undefined || request.body.description === undefined ||
request.file === undefined) {
return response.status(400).json({success: false,
error: {text: 'Es wurden nicht alle notwendingen Felder ausgefüllt'}});
}
if (request.body.description.length > 1500) {
return response.status(400).json({success: false,
error: {text: 'Bewerbungstext ist zu lang'}});
}

StudentApiController.unique(request.body.firstName, request.body.lastName, (result) => {
if (result === false) {
return response.status(200).json({
success: false,
error: {text: 'not_unique'}
});
if (request.body.course === undefined || request.body.year === undefined) {
return response.status(200).json({
success: false,
error: {text: 'not_unique'}
});
}
const contestantJSON = request.body;
ContestantApiController.save_2(contestantJSON, response, next);
} else {

const contestantJSON = request.body;
ContestantApiController.save_2(contestantJSON, response, next);
}
});
}



if (request.body.firstName === undefined || request.body.lastName === undefined || request.body.course === undefined || request.body.year === undefined ||
request.body.description === undefined || request.file === undefined) {
return response.status(400).json({success: false,
error: {text: 'Es wurden nicht alle notwendingen Felder ausgefüllt'}});
}
if (request.body.description.length > 1500) {
return response.status(400).json({success: false,
error: {text: 'Bewerbungstext ist zu lang'}});
}
const contestantJSON = request.body;

static save_2(contestantJSON, response, next) {
Contestant.count({firstName: {$regex: ContestantHelper.buildNameRegex(contestantJSON.firstName),
$options: 'g'},
lastName: contestantJSON.lastName}).exec((countError, count) => {
Expand All @@ -67,7 +65,7 @@ module.exports = class ContestantApiController {
if (validated === true) {
contestantJSON.activated = false;
contestantJSON.image = request.file.filename;
// sanitize user inputs
// sanitize user inputs
contestantJSON.firstName = xss(contestantJSON.firstName);
contestantJSON.lastName = xss(contestantJSON.lastName);
contestantJSON.course = student.course;
Expand Down Expand Up @@ -95,7 +93,7 @@ module.exports = class ContestantApiController {
error: {text: 'Deine Angaben konnten nicht validiert werden. \nVersuche es erneut'}
});
}
// return next('error');
// return next('error');
});
});
}
Expand Down

0 comments on commit 44d6dd1

Please sign in to comment.