generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import config from "../../config/config"; | ||
import { env } from "../typeDefinitions/default.types"; | ||
import { discordTextResponse } from "../utils/discordResponse"; | ||
import { fetchDiscordGroups } from "../utils/fetchDiscordGroups"; | ||
|
||
export async function groupInvite(userId: string, roleId: string, env: env) { | ||
const response = await fetchDiscordGroups(env); | ||
const group = response.groups.find((group) => group.roleid === roleId); | ||
|
||
if (!group) { | ||
return discordTextResponse(`<@&${roleId}> is not a valid group.`); | ||
} | ||
|
||
const groupName = group.rolename.replace(/^group-/, ""); | ||
|
||
return discordTextResponse( | ||
`<@${userId}> join the group <@&${roleId}> via the link below:\n ${ | ||
config(env).DASHBOARD_SITE_URL | ||
}/groups/?dev=true&name=${groupName}` | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
export type GroupType = { | ||
id: string; | ||
date: { | ||
_seconds: number; | ||
_nanoseconds: number; | ||
}; | ||
createdBy: string; | ||
rolename: string; | ||
roleid: string; | ||
description: string; | ||
memberCount: number; | ||
isMember: boolean; | ||
}; | ||
|
||
export type GroupResponseType = { | ||
message?: string; | ||
groups: GroupType[]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import config from "../../config/config"; | ||
import { FAILED_TO_FETCH_DISCORD_GROUPS } from "../constants/responses"; | ||
import { env } from "../typeDefinitions/default.types"; | ||
import { GroupResponseType } from "../typeDefinitions/group.types"; | ||
|
||
async function fetchDiscordGroups(env: env): Promise<GroupResponseType> { | ||
try { | ||
const url = `${config(env).RDS_BASE_API_URL}/discord-actions/groups`; | ||
const response = await fetch(url); | ||
|
||
if (!response.ok) { | ||
throw new Error(FAILED_TO_FETCH_DISCORD_GROUPS); | ||
} | ||
|
||
const responseData: GroupResponseType = await response.json(); | ||
return responseData; | ||
} catch (error) { | ||
console.error("An error occurred while fetching discord groups:", error); | ||
throw error; | ||
} | ||
} | ||
|
||
export { fetchDiscordGroups }; |