Skip to content

Instantly share code, notes, and snippets.

@ancyrweb
Created October 3, 2022 03:48
Show Gist options
  • Save ancyrweb/310d9da0047ed6030966fd3b440f6c2f to your computer and use it in GitHub Desktop.
Save ancyrweb/310d9da0047ed6030966fd3b440f6c2f to your computer and use it in GitHub Desktop.
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: 'author@website.com',
to: 'receiver@website.com',
body,
}),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment