Skip to content

Commit

Permalink
fix(event): refactored event validation
Browse files Browse the repository at this point in the history
  • Loading branch information
serge1peshcoff committed Feb 12, 2019
1 parent 1dcebde commit e7bf8fd
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions models/Event.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,8 @@ const Event = sequelize.define('event', {
throw new Error('Body is malformed.');
}

if (typeof body.body_id === 'undefined') {
throw new Error('body_id should be presented.');
}

if (typeof body.body_id !== 'number') {
throw new Error('body_id should be a number.');
throw new Error('body_id should be an integer.');
}
}
}
Expand All @@ -134,19 +130,23 @@ const Event = sequelize.define('event', {
throw new Error('Position is malformed.');
}

if (!position.name) {
if (typeof position.name !== 'string') {
throw new Error('Name is invalid.');
}

if (position.name.trim().length === 0) {
throw new Error('Name should be presented.');
}

if (typeof position.position !== 'object' || position.position === null) {
throw new Error('Position.position is malformed.');
}

if (!position.position.lat || typeof position.position.lat !== 'number') {
if (typeof position.position.lat !== 'number') {
throw new Error('Latitude is malformed.');
}

if (!position.position.lng || typeof position.position.lng !== 'number') {
if (typeof position.position.lng !== 'number') {
throw new Error('Longitude is malformed.');
}
}
Expand Down

0 comments on commit e7bf8fd

Please sign in to comment.