-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
emit an event when product is created to notify users
- Loading branch information
1 parent
0d13db9
commit c364226
Showing
13 changed files
with
93 additions
and
62 deletions.
There are no files selected for viewing
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
29 changes: 18 additions & 11 deletions
29
server/ecommerce/src/discord-bot/src/commands/notifiers/item-notifier.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 |
---|---|---|
@@ -1,24 +1,31 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { Inject, Injectable, Logger } from '@nestjs/common'; | ||
import { ItemNotifier } from './item-notifier'; | ||
import { UsersService } from 'src/users/users.service'; | ||
import { DiscordNotificationsService } from 'src/discord-notifications/discord-notifications.service'; | ||
import { Product } from 'src/utils/entities/product.entity'; | ||
import { OnEvent } from '@nestjs/event-emitter'; | ||
import { GeneralEvents } from 'src/events/constants/events'; | ||
import { ProductsService } from 'src/products/products.service'; | ||
import { IProductsService } from 'src/spi/products'; | ||
|
||
@Injectable() | ||
export class ItemNotifierService { | ||
private readonly itemNotifier: ItemNotifier; | ||
private logger: Logger; | ||
|
||
constructor( | ||
private usersService: UsersService, | ||
private discordNotificationsService: DiscordNotificationsService, | ||
@Inject(ItemNotifier) private readonly itemNotifier: ItemNotifier, | ||
) { | ||
this.itemNotifier = new ItemNotifier({ | ||
bot: this.discordNotificationsService.discordNotificationsBot, | ||
usersService: this.usersService, | ||
}); | ||
this.logger = new Logger(ItemNotifierService.name); | ||
} | ||
|
||
public notifyUsers = async (userId: number, product: Product) => { | ||
return await this.itemNotifier.notifyUsers(userId, product); | ||
}; | ||
@OnEvent(GeneralEvents.ProductCreated, { async: true }) | ||
public async notifyUsers(product: Product) { | ||
this.logger.log(`${ItemNotifierService.name} recieved an event`); | ||
|
||
try { | ||
await this.itemNotifier.notifyUsers(product); | ||
} catch (error) { | ||
this.logger.error(error.message); | ||
} | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.