1
- import { Injectable , Logger , OnModuleInit } from '@nestjs/common' ;
1
+ import { Inject , Injectable , Logger , OnModuleInit } from '@nestjs/common' ;
2
2
import { InjectModel } from '@nestjs/mongoose' ;
3
3
import { Model } from 'mongoose' ;
4
4
@@ -12,6 +12,8 @@ export class SongWebhookService implements OnModuleInit {
12
12
constructor (
13
13
@InjectModel ( SongEntity . name )
14
14
private songModel : Model < SongEntity > ,
15
+ @Inject ( 'DISCORD_WEBHOOK_URL' )
16
+ private readonly discordWebhookUrl : string | undefined ,
15
17
) { }
16
18
17
19
async onModuleInit ( ) {
@@ -28,7 +30,7 @@ export class SongWebhookService implements OnModuleInit {
28
30
* @throws {Error } If the Discord webhook URL is not found.
29
31
* @throws {Error } If there is an error sending the webhook message.
30
32
*/
31
- const webhookUrl = process . env . DISCORD_WEBHOOK_URL ;
33
+ const webhookUrl = this . discordWebhookUrl ;
32
34
33
35
if ( ! webhookUrl ) {
34
36
this . logger . error ( 'Discord webhook URL not found' ) ;
@@ -71,7 +73,7 @@ export class SongWebhookService implements OnModuleInit {
71
73
throw new Error ( 'Song does not have a webhook message' ) ;
72
74
}
73
75
74
- const webhookUrl = process . env . DISCORD_WEBHOOK_URL ;
76
+ const webhookUrl = this . discordWebhookUrl ;
75
77
76
78
if ( ! webhookUrl ) {
77
79
this . logger . error ( 'Discord webhook URL not found' ) ;
@@ -110,7 +112,7 @@ export class SongWebhookService implements OnModuleInit {
110
112
throw new Error ( 'Song does not have a webhook message' ) ;
111
113
}
112
114
113
- const webhookUrl = process . env . DISCORD_WEBHOOK_URL ;
115
+ const webhookUrl = this . discordWebhookUrl ;
114
116
115
117
if ( ! webhookUrl ) {
116
118
this . logger . error ( 'Discord webhook URL not found' ) ;
@@ -175,7 +177,7 @@ export class SongWebhookService implements OnModuleInit {
175
177
. sort ( { createdAt : 1 } )
176
178
. populate ( 'uploader' , 'username profileImage -_id' ) ;
177
179
178
- for await ( const songDocument of songQuery ) {
180
+ for ( const songDocument of await songQuery ) {
179
181
const webhookMessageId = await this . syncSongWebhook (
180
182
songDocument as unknown as SongWithUser ,
181
183
) ;
0 commit comments