Skip to content

Commit

Permalink
feat: implement start, cancel auction and place bid
Browse files Browse the repository at this point in the history
  • Loading branch information
dorucioclea committed Jul 17, 2023
1 parent a974116 commit 594fa60
Showing 1 changed file with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { Injectable, OnModuleInit, OnApplicationShutdown } from '@nestjs/common'
import * as amqp from 'amqplib';
import * as winston from 'winston';
import { Counter, Registry } from 'prom-client';
import { StartAuctionService } from './start.auction.service';
import { CancelAuctionService } from './cancel.auction.service';
import { PlaceBidService } from './place.bid.service';
import { CancelAuction, PlaceBid, StartAuction } from 'src/models';

@Injectable()
export class RabbitmqService implements OnModuleInit, OnApplicationShutdown {
Expand Down Expand Up @@ -31,6 +35,14 @@ export class RabbitmqService implements OnModuleInit, OnApplicationShutdown {
],
});

public constructor(
private readonly startAuctionService: StartAuctionService,
private readonly cancelAuctionService: CancelAuctionService,
private readonly placeBidService: PlaceBidService,
) {

}

async onModuleInit() {
await this.retryConnect();
await this.startListening();
Expand Down Expand Up @@ -113,7 +125,7 @@ export class RabbitmqService implements OnModuleInit, OnApplicationShutdown {
if (this.channel) {
await this.channel.assertQueue(this.queueName, { durable: false });

this.channel.consume(this.queueName, (msg) => {
this.channel.consume(this.queueName, async (msg) => {
if (msg) {

const content = msg.content.toString();
Expand All @@ -126,18 +138,25 @@ export class RabbitmqService implements OnModuleInit, OnApplicationShutdown {
switch (type) {
case 'place-bid':
this.logger.info('Place bid event received');
const placeBidModel = dataJson as PlaceBid;
await this.placeBidService.placeBid(placeBidModel);
break;
case 'place-bid-return-previous-bid':
this.logger.info('Place bid return previous bid event received');
break;
case 'start-auction':
this.logger.info('Start Auction event received');

const startAuctionModel = dataJson as StartAuction;
await this.startAuctionService.startAuction(startAuctionModel);
break;
case 'set-whitelisted':
this.logger.info('Whitelist event received');
break;
case 'cancel-auction':
this.logger.info('Cancel Auction event received');
const cancelAuctionModel = dataJson as CancelAuction;
await this.cancelAuctionService.cancelAuction(cancelAuctionModel);
break;
default:
this.logger.info('Unknown event received');
Expand Down

0 comments on commit 594fa60

Please sign in to comment.