-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
orders an inventory added with get and post method
- Loading branch information
1 parent
db294ed
commit 7fde1ac
Showing
5 changed files
with
118 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const Inventory = require('../../models/admin/inventory'); | ||
|
||
router.get('/', (req, res, next)=>{ | ||
Inventory.getInventorys((err, inventory)=>{ | ||
if (err) { | ||
res.json({"error":"error"}); | ||
console.log(err) | ||
} else { | ||
res.json(inventory); | ||
} | ||
}) | ||
}); | ||
|
||
router.get('/:id', (req, res, next)=>{ | ||
let id = req.params.id; | ||
Inventory.getInventoryById(id, (err, inventory)=>{ | ||
if (err) { | ||
res.json({"error":"error"}); | ||
console.log(err) | ||
} else { | ||
res.json(inventory); | ||
} | ||
}) | ||
}); | ||
|
||
|
||
router.post('/', (req, res, next)=>{ | ||
|
||
let date = (new Date()).toString().split(' ').splice(1,3).join(' '); | ||
let newInventory =new Inventory({ | ||
products: req.body.products, | ||
inventory_total: req.body.inventory_total, | ||
ship_date: req.body.ship_date, | ||
ship_address: req.body.ship_address, | ||
ship_pin:req.body.ship_pin, | ||
user_id: req.body.user_id, | ||
payment_id: req.body.payment_id, | ||
status: req.body.status, | ||
inventory_date: date | ||
}); | ||
Inventory.addInventory(newInventory, (err, inventory)=>{ | ||
if (err) { | ||
res.json({success:false, msg:"Failed to add the inventory"}); | ||
console.log(err); | ||
} else { | ||
res.json({success:true, msg:"Inventory added succefully"}); | ||
} | ||
}) | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const Order = require('../../models/admin/order'); | ||
|
||
router.get('/', (req, res, next)=>{ | ||
Order.getOrders((err, order)=>{ | ||
if (err) { | ||
res.json({"error":"error"}); | ||
console.log(err) | ||
} else { | ||
res.json(order); | ||
} | ||
}) | ||
}); | ||
|
||
router.get('/:id', (req, res, next)=>{ | ||
let id = req.params.id; | ||
Order.getOrderByID(id, (err, order)=>{ | ||
if (err) { | ||
res.json({"error":"error"}); | ||
console.log(err) | ||
} else { | ||
res.json(order); | ||
} | ||
}) | ||
}); | ||
|
||
|
||
router.post('/', (req, res, next)=>{ | ||
|
||
let date = (new Date()).toString().split(' ').splice(1,3).join(' '); | ||
let newOrder =new Order({ | ||
products: req.body.products, | ||
order_total: req.body.order_total, | ||
ship_date: req.body.ship_date, | ||
ship_address: req.body.ship_address, | ||
ship_pin:req.body.ship_pin, | ||
user_id: req.body.user_id, | ||
payment_id: req.body.payment_id, | ||
order_date: date | ||
}); | ||
Order.addOrder(newOrder, (err, order)=>{ | ||
if (err) { | ||
res.json({success:false, msg:"Failed to add the order"}); | ||
console.log(err); | ||
} else { | ||
res.json({success:true, msg:"Order added succefully"}); | ||
} | ||
}) | ||
}); | ||
|
||
module.exports = router; |