I'm building an application in node.js using Hapi and database in Mongodb using Mongoose. I have the following message schema:
var schema = {
from : {
type : Schema.ObjectId,
ref : 'User'
},
content : {
type : String,
required : true
},
group : {
type : Schema.ObjectId,
ref : 'Group'
},
created : {
type : Number,
default : Date.now()
}
};
I want the created
field in the schema to be a timestamp and always be in UTC. For this my client always converts its current timestamp into its UTC timestamp and then sends to the server. However, I can't find a possible way on the server to verify whether the timestamp provided has been converted into UTC or not. Is there any way I could impose that validation in Hapi/Mongoose?
Thanks in advance.
Edit:
- Changed the type of
created
field to beNumber
since I want to store thetimestamp
and not the date string.
Hapi allows you to have a
validate
property on each route. Under the hood this uses Joi to validate the schema provided in this property to the payload, parameters, query string and headers: Route ConfigurationUsing this you can validate your
created
field to a particular date format: date.format()For example this will validate it to ISO 8601 format: