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) => {
|
app.post('/api/order', (req, res, next) => {
|
||||||
console.log('Post /api/order', req.body);
|
console.log('Post /api/order', req.body);
|
||||||
const order = new ordermodel(req.body.order);
|
if(req.body.order._id == null) {
|
||||||
order.save();
|
const order = new ordermodel(req.body.order);
|
||||||
res.status(200).json({
|
order.save();
|
||||||
message: 'Order added',
|
res.status(200).json({
|
||||||
order: order
|
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) => {
|
app.post('/api/lineitem', (req, res, next) => {
|
||||||
|
|
|
@ -79,6 +79,7 @@ export class OrderComponent implements OnInit{
|
||||||
dialogRef.afterClosed().subscribe((val) => {
|
dialogRef.afterClosed().subscribe((val) => {
|
||||||
if (val) {
|
if (val) {
|
||||||
console.log('Payment confirmed!');
|
console.log('Payment confirmed!');
|
||||||
|
this.orderService.closeOrder();
|
||||||
} else {
|
} else {
|
||||||
console.log('Returning to order');
|
console.log('Returning to order');
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,4 +124,28 @@ export class OrderService {
|
||||||
return obs;
|
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