Skip to content

Commit

Permalink
refactor: refactor and filtred discord ids
Browse files Browse the repository at this point in the history
  • Loading branch information
sahsisunny committed Apr 16, 2024
1 parent 30150ac commit b0f91cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
14 changes: 7 additions & 7 deletions src/handlers/scheduledEventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@ import { SUPER_USER_ONE, SUPER_USER_TWO } from "../constants/variables";

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

if (!Array.isArray(discordIds)) {
// If it's not an array, convert it to an array with a single element
discordIds = [discordIds];
}
const superUsers = [SUPER_USER_ONE, SUPER_USER_TWO];
const filteredDiscordIds = discordIds.filter(
(id) => !superUsers.includes(id)
);

if (discordIds.length === 0) {
if (filteredDiscordIds.length === 0) {
return;
}

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

let forFormatting = 0;
discordIds.forEach((id: string) => {
filteredDiscordIds.forEach((id: string) => {
const discordUser = `<@${id}> `;
stringToBeSent += discordUser;
forFormatting++;
Expand Down
4 changes: 1 addition & 3 deletions src/utils/taskOverDueDiscordMembers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { RDS_BASE_API_URL } from "../constants/urls";
import { UserOverdueTaskResponseType } from "../typeDefinitions/rdsUser";

export const taskOverDueDiscordMembers = async (): Promise<
string[] | string
> => {
export const taskOverDueDiscordMembers = async (): Promise<string[]> => {
try {
const overDueUrl = `${RDS_BASE_API_URL}/users?query=filterBy:overdue_tasks`;

Expand Down

0 comments on commit b0f91cd

Please sign in to comment.