Skip to content

Commit 9c5a858

Browse files
committed
feat: implement user interface
1 parent a1f4a8a commit 9c5a858

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/items/services/UserService.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import githubDiscordMap from "../../../data/githubDiscordMap.json";
2+
import { Err, Ok, Result } from "ts-results";
3+
4+
export interface User {
5+
githubUsername: string;
6+
githubId: string;
7+
discordId: string;
8+
}
9+
10+
const users: User[] = Object.values(githubDiscordMap);
11+
12+
export class UserService {
13+
static async findUserByDiscordID(discordId: string): Promise<Result<User, Error>> {
14+
const user = users.find((u) => u.discordId === discordId);
15+
return user ? Ok(user) : Err(new Error("Could not find user with that DiscordID"));
16+
}
17+
18+
static async findUserByGithubUsername(githubUsername: string): Promise<Result<User, Error>> {
19+
const user = users.find((u) => u.githubUsername === githubUsername);
20+
return user ? Ok(user) : Err(new Error("Could not find user with that GitHub username"));
21+
}
22+
}

0 commit comments

Comments
 (0)