Created
October 3, 2022 03:48
-
-
Save ancyrweb/310d9da0047ed6030966fd3b440f6c2f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import { InjectQueue } from '@nestjs/bull'; | |
import { Injectable } from '@nestjs/common'; | |
import { OnEvent } from '@nestjs/event-emitter'; | |
import { Queue } from 'bull'; | |
import { CommentEvents, NewCommentEvent } from './comment.events'; | |
import { CommentEmailGenerator } from './comment.email-generator'; | |
import { createEmailJob } from './email.processor'; | |
@Injectable() | |
export class CommentNotifier { | |
constructor( | |
@InjectQueue('emails') private readonly emailQueue: Queue, | |
private readonly emailGenerator: CommentEmailGenerator, | |
) {} | |
@OnEvent(CommentEvents.NewComment) | |
onNewEvent(data: NewCommentEvent) { | |
const body = this.emailGenerator.generateCommentEmail(data.comment); | |
return this.emailQueue.add( | |
createEmailJob({ | |
subject: 'You received a new comment', | |
from: '[email protected]', | |
to: '[email protected]', | |
body, | |
}), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment