agmission/Development/server/model/obstacles.js

36 lines
863 B
JavaScript

'use strict';
const mongoose = require('mongoose'),
Schema = mongoose.Schema;
const schema = new Schema({
properties: { type: Schema.Types.Mixed },
geometry: {
type: {
type: String,
required: true,
enum: ['Point'],
default: 'Point'
},
coordinates: { type: [Number], required: true }
},
byUser: { type: Schema.Types.ObjectId, ref: 'User', required: false }
});
schema.index({ geometry: '2dsphere' });
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, // feet
amsl: doc.properties.amsl, // feet
coors: doc.geometry.coordinates
};
return ret;
}
module.exports = mongoose.model('Obstacles', schema);