-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
102dbe0
commit b832c35
Showing
4 changed files
with
56 additions
and
7 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...subscriber/src/models/cancel-bid.model.ts → ...criber/src/models/cancel-auction.model.ts
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
44 changes: 44 additions & 0 deletions
44
chainhook-subscriber/src/modules/auctionhistory/services/place.bid.service.ts
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,44 @@ | ||
import { Inject, Injectable } from "@nestjs/common"; | ||
import { PlaceBid, StartAuction } from "src/models"; | ||
import { AuctionEntityRepository } from "src/modules/auctions/repositories/auction.repository"; | ||
import { AuctionEntityRepositoryToken } from "src/modules/auctions/providers/auction.repository.provider"; | ||
import { Transactional } from "src/common/transaction/transaction"; | ||
import { runOnTransactionComplete, runOnTransactionRollback } from "src/common/transaction/hook"; | ||
import { AuctionBidEntity } from "src/modules/auctions/entities/auction.bid.entity"; | ||
import { AuctionBidEntityRepositoryToken } from "src/modules/auctions/providers/auction.bid.repository.provider"; | ||
import { AuctionBidEntityRepository } from "src/modules/auctions/repositories/auction.bid.entity.repository"; | ||
|
||
@Injectable() | ||
export class PlaceBidService { | ||
constructor( | ||
@Inject(AuctionEntityRepositoryToken) | ||
private auctionRepository: AuctionEntityRepository, | ||
@Inject(AuctionBidEntityRepositoryToken) | ||
private auctionBidRepository: AuctionBidEntityRepository | ||
) {} | ||
|
||
@Transactional() | ||
public async placeBid(placeBidModel: PlaceBid): Promise<void> { | ||
|
||
runOnTransactionRollback((cb) => | ||
console.log('Rollback error ' + cb.message), | ||
); | ||
|
||
runOnTransactionComplete((_) => console.log('Transaction Complete')); | ||
|
||
const auction = await this.auctionRepository.findOneOrFail({ | ||
where: { auctionId: Number(placeBidModel["auction-id"].value)}, | ||
relations: ['bids'], | ||
}); | ||
|
||
const bid = new AuctionBidEntity(); | ||
bid.amount = Number(placeBidModel.bid.value); | ||
bid.bidder = placeBidModel.bidder.value; | ||
|
||
await this.auctionBidRepository.save(bid); | ||
|
||
(auction.bids || []).push(bid); | ||
|
||
await this.auctionRepository.save(auction); | ||
} | ||
} |
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