1
1
import { env } from "../typeDefinitions/default.types" ;
2
2
import { taskOverDueDiscordMembers } from "../utils/taskOverDueDiscordMembers" ;
3
- import * as error from "../constants/responses" ;
4
- import { getDiscordIds } from "../utils/getDiscordIds" ;
5
3
import config from "../../config/config" ;
6
4
import { SUPER_USER_ONE , SUPER_USER_TWO } from "../constants/variables" ;
7
5
8
6
export async function send ( env : env ) : Promise < void > {
9
7
try {
10
- const assigneeIds : string [ ] | string = await taskOverDueDiscordMembers ( ) ;
8
+ let discordIds : string [ ] | string = await taskOverDueDiscordMembers ( ) ;
11
9
12
- //A user might have more than one task which are running red
13
- //so to mention them just once, we are using Set to filter out
14
- const discordIds : string [ ] | string = await getDiscordIds ( assigneeIds ) ;
15
- const uniqueDiscordIds = [ ...new Set ( discordIds ) ] ;
10
+ if ( ! Array . isArray ( discordIds ) ) {
11
+ // If it's not an array, convert it to an array with a single element
12
+ discordIds = [ discordIds ] ;
13
+ }
14
+
15
+ if ( discordIds . length === 0 ) {
16
+ return ;
17
+ }
16
18
17
19
//notifying the two users with the authority.
18
20
let stringToBeSent = `<@${ SUPER_USER_ONE } > <@${ SUPER_USER_TWO } >\nThese people have their task running red:\n` ;
19
21
20
22
let forFormatting = 0 ;
21
- uniqueDiscordIds . forEach ( ( id ) => {
23
+ discordIds . forEach ( ( id : string ) => {
22
24
const discordUser = `<@${ id } > ` ;
23
25
stringToBeSent += discordUser ;
24
26
forFormatting ++ ;
@@ -35,7 +37,7 @@ export async function send(env: env): Promise<void> {
35
37
36
38
const url = config ( env ) . TRACKING_CHANNEL_URL ;
37
39
38
- const res = await fetch ( url , {
40
+ await fetch ( url , {
39
41
method : "POST" ,
40
42
body : JSON . stringify ( bodyObj ) ,
41
43
headers : {
0 commit comments