Skip to content

Commit b0f91cd

Browse files
committed
refactor: refactor and filtred discord ids
1 parent 30150ac commit b0f91cd

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/handlers/scheduledEventHandler.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ import { SUPER_USER_ONE, SUPER_USER_TWO } from "../constants/variables";
55

66
export async function send(env: env): Promise<void> {
77
try {
8-
let discordIds: string[] | string = await taskOverDueDiscordMembers();
8+
const discordIds: string[] = await taskOverDueDiscordMembers();
99

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-
}
10+
const superUsers = [SUPER_USER_ONE, SUPER_USER_TWO];
11+
const filteredDiscordIds = discordIds.filter(
12+
(id) => !superUsers.includes(id)
13+
);
1414

15-
if (discordIds.length === 0) {
15+
if (filteredDiscordIds.length === 0) {
1616
return;
1717
}
1818

1919
//notifying the two users with the authority.
2020
let stringToBeSent = `<@${SUPER_USER_ONE}> <@${SUPER_USER_TWO}>\nThese people have their task running red:\n`;
2121

2222
let forFormatting = 0;
23-
discordIds.forEach((id: string) => {
23+
filteredDiscordIds.forEach((id: string) => {
2424
const discordUser = `<@${id}> `;
2525
stringToBeSent += discordUser;
2626
forFormatting++;

src/utils/taskOverDueDiscordMembers.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { RDS_BASE_API_URL } from "../constants/urls";
22
import { UserOverdueTaskResponseType } from "../typeDefinitions/rdsUser";
33

4-
export const taskOverDueDiscordMembers = async (): Promise<
5-
string[] | string
6-
> => {
4+
export const taskOverDueDiscordMembers = async (): Promise<string[]> => {
75
try {
86
const overDueUrl = `${RDS_BASE_API_URL}/users?query=filterBy:overdue_tasks`;
97

0 commit comments

Comments
 (0)