File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments