Skip to content

Commit 84ca871

Browse files
committed
create Entry
1 parent 0729e83 commit 84ca871

6 files changed

Lines changed: 36 additions & 2 deletions

File tree

duct-drone-app/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"webpack-dev-server": "^3.2.1"
3232
},
3333
"dependencies": {
34+
"body-parser": "^1.19.0",
3435
"express": "^4.16.4",
3536
"mongodb": "^3.2.2",
3637
"mongoose": "^5.4.22",

duct-drone-app/server/controllers/entryController.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
const Entry = require('../daos/entrydao');
22

3+
exports.createEntry = function (req, res, next) {
4+
console.log(req.body);
5+
const entry = {
6+
time: req.body.time,
7+
temperature: req.body.temperature,
8+
air_velocity: req.body.air_velocity,
9+
coordinates:
10+
{
11+
x: req.body.coordinates.x,
12+
y: req.body.coordinates.y,
13+
z: req.body.coordinates.z,
14+
},
15+
};
16+
Entry.create(entry, (err, entry) => {
17+
if (err) {
18+
res.json({
19+
error: err,
20+
});
21+
}
22+
res.json({
23+
message: 'Entry created successfully',
24+
});
25+
});
26+
};
27+
328
exports.getEntries = function (req, res, next) {
429
Entry.get({}, (err, entry) => {
530
if (err) {

duct-drone-app/server/daos/entrydao.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ entrySchema.statics = {
66
create(data, cb) {
77
const entry = new this(data);
88
entry.save(cb);
9+
console.log('cheese');
910
},
1011
get(query, cb) {
1112
this.find(query, cb);
13+
console.log('its');
1214
},
1315
};
1416

duct-drone-app/server/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const express = require('express');
22
const path = require('path');
33
const mongoose = require('mongoose');
4-
4+
const bodyParser = require('body-parser');
55
const entryRoute = require('./routes/entry');
66
const mapRoute = require('./routes/map');
77

@@ -10,6 +10,9 @@ const server = '127.0.0.1:27017'; // DB SERVER
1010
const database = 'test'; // DB NAME
1111
const port = process.env.PORT || 5000;
1212

13+
14+
const bodyParserJSON = bodyParser.json();
15+
const bodyParserURLEncoded = bodyParser.urlencoded({ extended: true });
1316
// respond with "hello world" when a GET request is made to the homepage
1417
app.use(express.static(path.join(__dirname, '../build')));
1518

@@ -24,6 +27,8 @@ const db = mongoose.connection;
2427
db.on('error', console.error.bind(console, 'MongoDB connection error:'));
2528

2629
const router = express.Router();
30+
app.use(bodyParserJSON);
31+
app.use(bodyParserURLEncoded);
2732
app.use('/api', router);
2833
entryRoute(router);
2934
mapRoute(router);

duct-drone-app/server/models/entrymodel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const mongoose = require('mongoose');
22

33
const { Schema } = mongoose;
44
const entrySchema = new Schema({
5-
coordinate: [{ x: Number, y: Number, z: Number }],
5+
coordinates: { x: Number, y: Number, z: Number },
66
time: Date,
77
temperature: Schema.Types.Decimal128,
88
air_velocity: Schema.Types.Decimal128,

duct-drone-app/server/routes/entry.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ const Entry = require('../controllers/entryController');
22

33
module.exports = function (router) {
44
router.get('/get/entries', Entry.getEntries);
5+
router.post('/create/entry', Entry.createEntry);
56
};

0 commit comments

Comments
 (0)