1- import { Injectable , Logger , OnModuleInit } from '@nestjs/common' ;
1+ import { Inject , Injectable , Logger , OnModuleInit } from '@nestjs/common' ;
22import { InjectModel } from '@nestjs/mongoose' ;
33import { Model } from 'mongoose' ;
44
@@ -12,6 +12,8 @@ export class SongWebhookService implements OnModuleInit {
1212 constructor (
1313 @InjectModel ( SongEntity . name )
1414 private songModel : Model < SongEntity > ,
15+ @Inject ( 'DISCORD_WEBHOOK_URL' )
16+ private readonly discordWebhookUrl : string | undefined ,
1517 ) { }
1618
1719 async onModuleInit ( ) {
@@ -28,7 +30,7 @@ export class SongWebhookService implements OnModuleInit {
2830 * @throws {Error } If the Discord webhook URL is not found.
2931 * @throws {Error } If there is an error sending the webhook message.
3032 */
31- const webhookUrl = process . env . DISCORD_WEBHOOK_URL ;
33+ const webhookUrl = this . discordWebhookUrl ;
3234
3335 if ( ! webhookUrl ) {
3436 this . logger . error ( 'Discord webhook URL not found' ) ;
@@ -71,7 +73,7 @@ export class SongWebhookService implements OnModuleInit {
7173 throw new Error ( 'Song does not have a webhook message' ) ;
7274 }
7375
74- const webhookUrl = process . env . DISCORD_WEBHOOK_URL ;
76+ const webhookUrl = this . discordWebhookUrl ;
7577
7678 if ( ! webhookUrl ) {
7779 this . logger . error ( 'Discord webhook URL not found' ) ;
@@ -110,7 +112,7 @@ export class SongWebhookService implements OnModuleInit {
110112 throw new Error ( 'Song does not have a webhook message' ) ;
111113 }
112114
113- const webhookUrl = process . env . DISCORD_WEBHOOK_URL ;
115+ const webhookUrl = this . discordWebhookUrl ;
114116
115117 if ( ! webhookUrl ) {
116118 this . logger . error ( 'Discord webhook URL not found' ) ;
@@ -175,7 +177,7 @@ export class SongWebhookService implements OnModuleInit {
175177 . sort ( { createdAt : 1 } )
176178 . populate ( 'uploader' , 'username profileImage -_id' ) ;
177179
178- for await ( const songDocument of songQuery ) {
180+ for ( const songDocument of await songQuery ) {
179181 const webhookMessageId = await this . syncSongWebhook (
180182 songDocument as unknown as SongWithUser ,
181183 ) ;
0 commit comments