import NI from '../util/NetworkInterface' ; import * as Common from '../util/Common' ; import * as queries from '../scripts/userQueries' ; import Log from '../util/Logger' ; import { IUser , IUserData , IUserDataFull , IUserDataSets , IUserDataRankings } from '../interfaces/IUser' ; import { IPlayerRank } from '../interfaces/IPlayerRank' ; import { IGGSet } from '../interfaces/IGGSet' ; import { GGSet } from './GGSet' ; export class User implements IUser { public static parse ( data ) { return new User ( data . id , data . gamerTag , data . prefix , data . color , data . twitchStream , data . twitterHandle , data . youtube , data . region , data . state , data . country , data . gamerTagChangedAt ) ; } public static parseFull ( data ) { return User . parse ( data . player ) ; } public static async getById ( theId ) { Log . info ( 'Getting User (smash.gg Player) with id %s' , theId ) ; const data = await NI . query ( queries . user , { id : theId } ) ; return User . parseFull ( data ) ; } private id : number ; private gamerTag : string ; private prefix : string | null ; private color : string | null ; private twitchStream : string | null ; private twitterHandle : string | null ; private youtube : string | null ; private region : string | null ; private state : string | null ; private country : string | null ; private gamerTagChangedAt : number | null ; constructor ( id , gamerTag , prefix , color , twitchStream , twitterHandle , youtube , region , state , country , gamerTagChangedAt ) { this . id = id ; this . gamerTag = gamerTag ; this . prefix = prefix ; this . color = color ; this . twitchStream = twitchStream ; this . twitterHandle = twitterHandle ; this . youtube = youtube ; this . region = region ; this . state = state ; this . country = country ; this . gamerTagChangedAt = gamerTagChangedAt ; } public getId ( ) { return this . id ; } public getGamerTag ( ) { return this . gamerTag ; } public getSponsor ( ) { return this . prefix ; } public getColor ( ) { return this . color ; } public getTwitchStream ( ) { return this . twitchStream ; } public getTwitterHandle ( ) { return this . twitterHandle ; } public getYoutube ( ) { return this . youtube ; } public getRegion ( ) { return this . region ; } public getState ( ) { return this . state ; } public getCountry ( ) { return this . country ; } public getGamerTagChangedAt ( ) { return this . gamerTagChangedAt ? Common . convertEpochToDate ( this . gamerTagChangedAt ) : null ; } public async getRecentSets ( ) { Log . info ( 'Getting Sets for %s (User: %s)' , this . gamerTag , this . id ) ; const data = await NI . query ( queries . userRecentGGSets , { id : this . id } ) ; const sets = data . player . recentSets . map ( setData => GGSet . parse ( setData ) ) ; return sets ; } public async getRankings ( ) { Log . info ( 'Getting Rankings for %s (User: %s)' , this . gamerTag , this . id ) ; const data = await NI . query ( queries . userRankings , { id : this . id } ) ; const rankings = data . player . rankings ; return rankings ; } }