changes
This commit is contained in:
+26
-7
@@ -14,7 +14,7 @@ const db = mongoose.connection;
|
||||
|
||||
db.on('error', console.error.bind(console, 'connection error:'));
|
||||
db.once('open', function() {
|
||||
console.log(`connected to: ${MONGO_IP_ADDRESS}`);
|
||||
console.log(`connected to mongodb: ${MONGO_IP_ADDRESS}`);
|
||||
// we're connected!
|
||||
});
|
||||
|
||||
@@ -22,20 +22,39 @@ db.once('open', function() {
|
||||
|
||||
|
||||
/*------------MODELS------------*/
|
||||
//create a schema
|
||||
//create schema
|
||||
var itemSchema = new mongoose.Schema({
|
||||
name: String,
|
||||
quantity: Number,
|
||||
description: String,
|
||||
});
|
||||
var boxSchema = new mongoose.Schema({
|
||||
name: String
|
||||
id: String,
|
||||
name: String,
|
||||
description: String,
|
||||
item: [itemSchema],
|
||||
});
|
||||
//compile schema into model
|
||||
var Box = mongoose.model('Box', boxSchema);
|
||||
var Box = mongoose.model('box', boxSchema, 'box');
|
||||
/*------------MODELS------------*/
|
||||
|
||||
/*------------CONTROLLER------------*/
|
||||
app.listen(port, () => console.log(`Listening on port ${port}`));
|
||||
|
||||
// GET route
|
||||
app.post('/box', (req, res) => {
|
||||
res.send({ express: 'YOUR EXPRESS BACKEND IS CONNECTED TO REACT' });
|
||||
// get all boxes
|
||||
app.get('/box', async (req, res) => {
|
||||
const query = Box.find({});
|
||||
const data = await query.exec();
|
||||
console.log(data);
|
||||
res.send(data);
|
||||
});
|
||||
// create new box
|
||||
app.post('/box', async (req, res) => {
|
||||
console.log(req);
|
||||
const query = Box.create();
|
||||
const data = await query.exec();
|
||||
console.log(data);
|
||||
res.send(data);
|
||||
});
|
||||
|
||||
/*------------CONTROLLER------------*/
|
||||
Reference in New Issue
Block a user