Skip to content

Commit

Permalink
feat(subscriber): cancel auction service
Browse files Browse the repository at this point in the history
  • Loading branch information
dorucioclea committed Jul 17, 2023
1 parent 3a6b676 commit 102dbe0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { AuctionEntityRepositoryProvider } from '../auctions/providers/auction.r
import { AuctionBidEntityRepositoryProvider } from '../auctions/providers/auction.bid.repository.provider';
import { AuctionBidHistoryEntityRepositoryProvider } from './providers/auction.bid.history.repository.provider';
import { AuctionHistoryEntityRepositoryProvider } from './providers/auction.history.repository.provider';
import { CancelAuctionService } from './services/cancel.auction.service';

@Module({
imports: [
Expand All @@ -30,8 +31,9 @@ import { AuctionHistoryEntityRepositoryProvider } from './providers/auction.hist
RabbitMQHealthService,
RabbitmqService,
StartAuctionService,
CancelAuctionService,
AuctionHistoryService,

AuctionEntityRepositoryProvider,
AuctionBidEntityRepositoryProvider,
AuctionBidHistoryEntityRepositoryProvider,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Inject, Injectable } from "@nestjs/common";
import { 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 { AuctionEntity } from "src/modules/auctions/entities/auction.entity";

@Injectable()
export class CancelAuctionService {
constructor(
@Inject(AuctionEntityRepositoryToken)
private auctionRepository: AuctionEntityRepository
) {}

@Transactional()
public async startAuction(startAuctionModel: StartAuction): Promise<void> {

runOnTransactionRollback((cb) =>
console.log('Rollback error ' + cb.message),
);

runOnTransactionComplete((_) => console.log('Transaction Complete'));

const auction = await this.auctionRepository.findOneOrFail({auctionId: Number(startAuctionModel["auction-id"].value)})

auction.status = startAuctionModel["auction-status"].value;

await this.auctionRepository.save(auction);
}
}

0 comments on commit 102dbe0

Please sign in to comment.