Implement order closing
This commit is contained in:
parent
33326febaf
commit
0f5a731d08
3 changed files with 47 additions and 6 deletions
|
@ -288,12 +288,28 @@ app.get('/api/order', (req, res, next) => {
|
|||
|
||||
app.post('/api/order', (req, res, next) => {
|
||||
console.log('Post /api/order', req.body);
|
||||
if(req.body.order._id == null) {
|
||||
const order = new ordermodel(req.body.order);
|
||||
order.save();
|
||||
res.status(200).json({
|
||||
message: 'Order added',
|
||||
order: order
|
||||
});
|
||||
} else {
|
||||
ordermodel.findByIdAndUpdate(req.body.order._id, {
|
||||
address: req.body.order.address,
|
||||
session: req.body.order.session,
|
||||
closed: req.body.order.closed
|
||||
}, function(err, docs) {
|
||||
if(err) {
|
||||
console.log(err);
|
||||
} else {
|
||||
res.status(200).json({
|
||||
message: 'Order updated'
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/lineitem', (req, res, next) => {
|
||||
|
|
|
@ -79,6 +79,7 @@ export class OrderComponent implements OnInit{
|
|||
dialogRef.afterClosed().subscribe((val) => {
|
||||
if (val) {
|
||||
console.log('Payment confirmed!');
|
||||
this.orderService.closeOrder();
|
||||
} else {
|
||||
console.log('Returning to order');
|
||||
}
|
||||
|
|
|
@ -124,4 +124,28 @@ export class OrderService {
|
|||
return obs;
|
||||
}
|
||||
|
||||
closeOrder(){
|
||||
this.dataStore.order.closed = true;
|
||||
let obs = this.http.post<{message: string, order: Order}>('http://localhost:3000/api/order', {order: this.dataStore.order});
|
||||
obs.subscribe((orderData) => {
|
||||
console.log('Closed order', orderData);
|
||||
this.dataStore.order = {
|
||||
address: '',
|
||||
session: '',
|
||||
timestamp: '',
|
||||
closed: false,
|
||||
lines: [
|
||||
{
|
||||
qty: 1,
|
||||
name: '',
|
||||
cost:0
|
||||
}
|
||||
]
|
||||
};
|
||||
this._orderUpdated.next(Object.assign({}, this.dataStore).order);
|
||||
});
|
||||
|
||||
return obs;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue