Skip to content

Commit

Permalink
updated order service
Browse files Browse the repository at this point in the history
  • Loading branch information
egerj committed Apr 1, 2021
1 parent f2c2fc4 commit 0cec684
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
1 change: 1 addition & 0 deletions nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"assets": ["views/**/*", "public/**/*"],
"plugins": [
{
"name": "@nestjs/swagger/plugin",
Expand Down
32 changes: 17 additions & 15 deletions src/order/order.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class OrderService {
const orderDeleted = new OrderDeletedDto(order);
await order.delete();
this.msSocket.server.to('stockmarket').emit('update-orderbook');
this.httpService.post(order.onDelete, orderDeleted);
await this.httpService.post(order.onDelete, orderDeleted).toPromise();
}
}

Expand All @@ -113,11 +113,13 @@ export class OrderService {
timestamp: new Date().getTime(),
});

const res = await this.httpService.post(order.onPlace, {
jobId: jobId.toString(),
...order.toJSON(),
}).toPromise();
console.log(res);
await this.httpService
.post(order.onPlace, {
jobId: jobId.toString(),
...order.toJSON(),
})
.toPromise();

await this.orderPlaced(order);
}

Expand Down Expand Up @@ -149,7 +151,9 @@ export class OrderService {
const readyForDelete = await this.orderModel.find({ amount: { $lte: 0 } });
await Promise.all(
readyForDelete.map(async (d) => {
this.httpService.post(d.onComplete, new OrderCompletedDto(d));
await this.httpService
.post(d.onComplete, new OrderCompletedDto(d))
.toPromise();
await d.delete();
}),
);
Expand Down Expand Up @@ -318,14 +322,12 @@ export class OrderService {
await this.updateOrderAmount(iOrder, amount, price);
await this.updateOrderAmount(mOrder, amount, price);

this.httpService.post(
iOrder.onMatch,
new OrderMatchedDto(iOrder, remaining),
);
this.httpService.post(
mOrder.onMatch,
new OrderMatchedDto(mOrder, remaining),
);
await this.httpService
.post(iOrder.onMatch, new OrderMatchedDto(iOrder, remaining))
.toPromise();
await this.httpService
.post(mOrder.onMatch, new OrderMatchedDto(mOrder, remaining))
.toPromise();

remaining -= amount;

Expand Down

0 comments on commit 0cec684

Please sign in to comment.