harmony/src/managers/users.ts

24 lines
696 B
TypeScript
Raw Permalink Normal View History

2021-04-04 09:29:56 +00:00
import type { Client } from '../client/mod.ts'
import { User } from '../structures/user.ts'
import { USER } from '../types/endpoint.ts'
2021-04-04 09:29:56 +00:00
import type { UserPayload } from '../types/user.ts'
2020-11-04 12:38:00 +00:00
import { BaseManager } from './base.ts'
2020-12-03 04:06:41 +00:00
export class UsersManager extends BaseManager<UserPayload, User> {
2020-12-02 12:29:52 +00:00
constructor(client: Client) {
super(client, 'users', User)
}
2020-12-02 12:29:52 +00:00
async fetch(id: string): Promise<User> {
return await new Promise((resolve, reject) => {
this.client.rest
.get(USER(id))
2020-12-02 12:29:52 +00:00
.then((data) => {
this.set(id, data as UserPayload)
resolve(new User(this.client, data as UserPayload))
})
2020-12-02 12:29:52 +00:00
.catch((e) => reject(e))
})
}
}