Store events
This commit is contained in:
parent
b55cfc913f
commit
33a6ea99de
9
models/event.js
Normal file
9
models/event.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
class Event {
|
||||||
|
date
|
||||||
|
latitude
|
||||||
|
longitude
|
||||||
|
speed
|
||||||
|
direction
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = Event;
|
||||||
@ -1,4 +1,5 @@
|
|||||||
const Constants = require('../data_providers/constants');
|
const Constants = require('../data_providers/constants');
|
||||||
|
const Event = require('./event');
|
||||||
|
|
||||||
class Vehicle {
|
class Vehicle {
|
||||||
brand
|
brand
|
||||||
@ -18,6 +19,7 @@ class Vehicle {
|
|||||||
addedDate
|
addedDate
|
||||||
addedBy
|
addedBy
|
||||||
ownershipPeriods
|
ownershipPeriods
|
||||||
|
events
|
||||||
|
|
||||||
static fromAvtocod(report) {
|
static fromAvtocod(report) {
|
||||||
//console.log(JSON.stringify(report));
|
//console.log(JSON.stringify(report));
|
||||||
|
|||||||
20
routes/events.js
Normal file
20
routes/events.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
const express = require('express');
|
||||||
|
const router = express.Router();
|
||||||
|
|
||||||
|
const makeError = error => ({ success: false, error });
|
||||||
|
|
||||||
|
router.post('/', async (req, res) => {
|
||||||
|
const { number, event } = req.body;
|
||||||
|
|
||||||
|
try {
|
||||||
|
let collection = req.db.collection('vehicles');
|
||||||
|
await collection.updateOne({ number }, { $push: { events: event } });
|
||||||
|
let vehicle = await collection.findOne({ number });
|
||||||
|
res.send({ success: true, data: vehicle });
|
||||||
|
} catch(ex) {
|
||||||
|
res.send(makeError(ex.message));
|
||||||
|
console.error(ex);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = router;
|
||||||
Loading…
Reference in New Issue
Block a user