Skip to content

Instantly share code, notes, and snippets.

@dcbartlett
Created August 21, 2014 02:05
Show Gist options
  • Save dcbartlett/45e60a637a102a798fb2 to your computer and use it in GitHub Desktop.
Save dcbartlett/45e60a637a102a798fb2 to your computer and use it in GitHub Desktop.
// Model
module.exports = {
connection: '',
tableName: 'events',
attributes: {
start_time: {
type: 'datetime',
required: true,
before: function() {
return this.end_time;
},
columnName: 'start_time'
},
end_time: {
type: 'datetime',
required: true,
after: function() {
return this.start_time;
},
columnName: 'end_time'
}
}
};
// URI hit
POST http://127.0.0.1:1337/event/create
// POST data
{
"user_id": "1",
"name": "Test Event",
"timezone": "Chicago",
"location": "Chicago",
"start_time": "Aug, 13, 2014 11:00 Am",
"end_time": "Aug, 13, 2014 11:01 Am",
"status": "unverified"
}
// Response
{
"error": "E_VALIDATION",
"status": 400,
"summary": "1 attribute is invalid",
"model": "Event",
"invalidAttributes": {
"end_time": [
{
"rule": "after",
"message": "\"after\" validation rule failed for input: Wed Aug 13 2014 11:01:00 GMT-0500 (CDT)"
}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment