Skip to content

Commit 6fac2a0

Browse files
committed
refactor: change API endpoint and related logic to get overdue task users who are in server
1 parent 2ca525c commit 6fac2a0

File tree

2 files changed

+17
-19
lines changed

2 files changed

+17
-19
lines changed

src/handlers/scheduledEventHandler.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
import { env } from "../typeDefinitions/default.types";
22
import { taskOverDueDiscordMembers } from "../utils/taskOverDueDiscordMembers";
3-
import * as error from "../constants/responses";
4-
import { getDiscordIds } from "../utils/getDiscordIds";
53
import config from "../../config/config";
64
import { SUPER_USER_ONE, SUPER_USER_TWO } from "../constants/variables";
75

86
export async function send(env: env): Promise<void> {
97
try {
10-
const assigneeIds: string[] | string = await taskOverDueDiscordMembers();
8+
let discordIds: string[] | string = await taskOverDueDiscordMembers();
119

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+
}
1618

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

2022
let forFormatting = 0;
21-
uniqueDiscordIds.forEach((id) => {
23+
discordIds.forEach((id: string) => {
2224
const discordUser = `<@${id}> `;
2325
stringToBeSent += discordUser;
2426
forFormatting++;
@@ -35,7 +37,7 @@ export async function send(env: env): Promise<void> {
3537

3638
const url = config(env).TRACKING_CHANNEL_URL;
3739

38-
const res = await fetch(url, {
40+
await fetch(url, {
3941
method: "POST",
4042
body: JSON.stringify(bodyObj),
4143
headers: {

src/utils/taskOverDueDiscordMembers.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
import { RDS_BASE_API_URL } from "../constants/urls";
2-
import {
3-
TaskOverdue,
4-
TaskOverdueResponse,
5-
} from "../typeDefinitions/taskOverdue.types";
6-
import * as errors from "../constants/responses";
2+
import { UserOverdueTaskResponseType } from "../typeDefinitions/rdsUser";
73

84
export const taskOverDueDiscordMembers = async (): Promise<
95
string[] | string
106
> => {
117
try {
12-
const overDueUrl = `${RDS_BASE_API_URL}/tasks?dev=true&status=overdue&size=100`;
8+
const overDueUrl = `${RDS_BASE_API_URL}/users?query=filterBy:overdue_tasks`;
139

1410
const response: Response = await fetch(overDueUrl);
15-
const responseObj: TaskOverdueResponse = await response.json();
11+
const responseObj: UserOverdueTaskResponseType = await response.json();
1612

17-
const assigneeIds: string[] = responseObj.tasks.map(
18-
(task: TaskOverdue) => task.assigneeId
13+
const discordIds: string[] = responseObj.users.map(
14+
(user) => user.discordId
1915
);
2016

21-
return assigneeIds;
17+
return discordIds;
2218
} catch (e) {
2319
console.log(e);
2420
throw e;

0 commit comments

Comments
 (0)