2020-08-14 10:43:57 +00:00
|
|
|
var mongoose = require('mongoose');
|
2020-08-14 20:15:12 +00:00
|
|
|
var uniqueValidator = require('mongoose-unique-validator');
|
|
|
|
var slug = require('slug');
|
2020-08-14 10:43:57 +00:00
|
|
|
|
|
|
|
var TrackDataSchema = new mongoose.Schema({
|
2020-08-14 20:15:12 +00:00
|
|
|
slug: {type: String, lowercase: true, unique: true},
|
2020-08-14 10:43:57 +00:00
|
|
|
points: [ {
|
|
|
|
date: String,
|
|
|
|
time : String,
|
|
|
|
latitude: Number,
|
|
|
|
longitude: Number,
|
|
|
|
course: Number,
|
|
|
|
speed: Number,
|
|
|
|
d1: Number,
|
|
|
|
d2: Number,
|
|
|
|
flag: Number,
|
|
|
|
private: Number
|
|
|
|
}]
|
|
|
|
}, {timestamps: true});
|
|
|
|
|
2020-08-14 20:15:12 +00:00
|
|
|
TrackDataSchema.plugin(uniqueValidator, {message: 'is already taken'});
|
|
|
|
|
|
|
|
TrackDataSchema.pre('validate', function(next){
|
|
|
|
if(!this.slug) {
|
|
|
|
this.slugify();
|
|
|
|
}
|
|
|
|
next();
|
|
|
|
});
|
|
|
|
|
|
|
|
TrackDataSchema.methods.slugify = function() {
|
|
|
|
this.slug = slug("td") + '-' + (Math.random() * Math.pow(36, 6) | 0).toString(36);
|
|
|
|
};
|
|
|
|
|
2020-08-14 10:43:57 +00:00
|
|
|
mongoose.model('TrackData', TrackDataSchema);
|