33 lines
852 B
JavaScript
33 lines
852 B
JavaScript
module.exports = function (mongoose) {
|
|
const Schema = mongoose.Schema;
|
|
|
|
var schema = new Schema({
|
|
properties: { type: Schema.Types.Mixed },
|
|
geometry: {
|
|
type: {
|
|
type: String,
|
|
required: true,
|
|
enum: ['Point'],
|
|
default: 'Point'
|
|
},
|
|
coordinates: { type: [Number], index: '2dsphere' }
|
|
},
|
|
byUser: { type: Schema.Types.ObjectId, ref: 'User', required: false }
|
|
});
|
|
|
|
if (!schema.options.toObject) schema.options.toObject = {};
|
|
schema.options.toObject.transform = function (doc, ret, options) {
|
|
ret = {
|
|
_id: doc._id,
|
|
name: doc.properties.name,
|
|
type: doc.properties.type,
|
|
agl: doc.properties.agl,
|
|
amsl: doc.properties.amsl,
|
|
coors: doc.geometry.coordinates
|
|
};
|
|
return ret;
|
|
}
|
|
|
|
return module.exports = mongoose.model('Obstacles', schema);
|
|
}
|