День Добрый. Пишу небольшой сервис для локального osm сервера. Встала проблема с пост запросом на добавление записи в базу. в данном скрипте заносится uuid и тип метки но координаты не пишутся, и не могу понять как их занести туда :(
Код Сервиса:
// BASE SETUP
// =============================================================================
// call the packages we need
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var morgan = require('morgan');
// configure app
app.use(morgan('dev')); // log requests to the console
// configure body parser
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
var port = process.env.PORT || 80; // set our port
var mongoose = require('mongoose');
mongoose.connect('mongodb://admin@192.168.0.206:27017/monitor'); // connect to our database
var Device = require('./models/device');
// ROUTES FOR OUR API
// =============================================================================
// create our router
var router = express.Router();
// middleware to use for all requests
router.use(function(req, res, next) {
// do logging
console.log('Something is happening.');
next();
});
// test route to make sure everything is working (accessed at GET http://localhost:8080/api)
router.get('/', function(req, res) {
res.render({ message: 'hooray! welcome to our api!' });
});
// ----------------------------------------------------
router.route('/devices')
.post(function(req, res) {
var device = new Device();
device.uuid = req.body.uuid;
device.location.coordinates = req.body.location.coordinates;
device.location.type = req.body.location.type;
device.save(function(err) {
if (err)
res.send(err);
res.json({ message: 'Device created!' });
});
})
.get(function(req, res) {
Device.find(function(err, devices) {
if (err)
res.send(err);
res.json(devices);
});
});
router.route('/devices/:device_id')
.get(function(req, res) {
Device.findById(req.params.device_id, function(err, device) {
if (err)
res.send(err);
res.json(device);
});
})
.put(function(req, res) {
Device.findById(req.params.device_id, function(err, device) {
if (err)
res.send(err);
device.uuid = req.body.uuid;
device.save(function(err) {
if (err)
res.send(err);
res.json({ message: 'Device updated!' });
});
});
})
.delete(function(req, res) {
Device.remove({
_id: req.params.device_id
}, function(err, device) {
if (err)
res.send(err);
res.json({ message: 'Successfully deleted' });
});
});
// REGISTER OUR ROUTES -------------------------------
app.use('/api', router);
// START THE SERVER
// =============================================================================
app.listen(port);
console.log('Magic happens on port ' + port);
Код Модели
// app/models/device.js
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var DevicesSchema = new Schema({
uuid: String,
location : {
type: {
type: String,
default: 'Point'
},
coordinates: [Number]
}
},{
versionKey: false
});
module.exports = mongoose.model('Device', DevicesSchema);
Буду благодарен за любые подсказки и помощь. Заранее всем спасибо