This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added findUserById, notification on task completion
- Loading branch information
Showing
5 changed files
with
50 additions
and
13 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { NotificationService } from './notification.service'; | ||
import { ConfigModule } from '@nestjs/config'; | ||
import { UserRepository } from 'src/db/repositories/user.repository'; | ||
|
||
@Module({ | ||
imports: [ConfigModule.forRoot()], | ||
imports: [ConfigModule.forRoot(), UserRepository], | ||
providers: [NotificationService], | ||
}) | ||
export class NotificationModule {} |
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,21 +1,29 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { User } from '@prisma/client'; | ||
import { EmailNotifier } from './emailNotifier'; | ||
import { UserRepository } from 'src/db/repositories/user.repository'; | ||
|
||
@Injectable() | ||
export class NotificationService { | ||
constructor(private userRepository: UserRepository) {} | ||
|
||
private readonly notifiers = { | ||
EMAIL: new EmailNotifier(), | ||
}; | ||
|
||
/** | ||
* Sends a notification to a user via the method specified in the users settings. | ||
* @param user User receiving the notification | ||
* @param user User id receiving the notification | ||
* @param title Title of the notification | ||
* @param content Message content of the notification | ||
*/ | ||
notify(user: User, title: string, content: string): void { | ||
async notify(userId: string, title: string, content: string) { | ||
const user = await this.userRepository.findById(userId); | ||
|
||
// only supports email notifications for now | ||
this.notifiers[user.notificationMethod]?.notify(user, title, content); | ||
this.notifiers?.[user?.notificationMethod ?? '']?.notify( | ||
userId, | ||
title, | ||
content, | ||
); | ||
} | ||
} |