Skip to content

Commit

Permalink
add teams module (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
noticeeverything authored Sep 27, 2021
1 parent 2562002 commit 4b0ae69
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/lib/teams/teams.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Teams } from './teams'

describe('Teams', () => {
it('creates', () => {
expect(new Teams({} as never, {} as never)).toBeTruthy()
})
})
25 changes: 25 additions & 0 deletions src/lib/teams/teams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { AxiosInstance } from 'axios'
import { TimelyAppConfig, TimelyTeam, TimelyUser } from '../types'

export class Teams {
constructor(private readonly http: AxiosInstance, private readonly config: TimelyAppConfig) {}

async getAll(): Promise<TimelyUser[]> {
const { data } = await this.http.get(`/${this.config.accountId}/teams`)
return data
}

async getByName(name: string): Promise<TimelyTeam> {
const { data: response }: { data: TimelyTeam[] } = await this.http.get(
`/${this.config.accountId}/teams`,
)
const team = response.find((u) => u.name === name)
if (!team) throw new Error(`Can't find team with name ${name}`)
return team
}

async update(teamId: number, team: Partial<TimelyTeam>): Promise<TimelyTeam> {
const { data } = await this.http.put(`/${this.config.accountId}/teams${teamId}`, { team })
return data
}
}
4 changes: 4 additions & 0 deletions src/lib/timely-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Labels } from './labels/labels'
import { Projects } from './projects/projects'
import { Users } from './users/users'
import { createHttpClient } from './http/http'
import { Teams } from './teams/teams'

export class TimelyApp {
readonly accounts: Accounts
Expand All @@ -21,6 +22,8 @@ export class TimelyApp {

readonly projects: Projects

readonly teams: Teams

readonly users: Users

constructor(private readonly config: TimelyAppConfig) {
Expand All @@ -39,6 +42,7 @@ export class TimelyApp {
this.events = new Events(this.http, this.config)
this.labels = new Labels(this.http, this.config)
this.projects = new Projects(this.http, this.config)
this.teams = new Teams(this.http, this.config)
this.users = new Users(this.http, this.config)
}

Expand Down
9 changes: 9 additions & 0 deletions src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ export interface TimelyClient {
updated_at: string
}

export interface TimelyTeam {
id: number
name: string
users: {
user_id: number
lead?: boolean
}[]
}

export interface TimelyUser {
id: number
email: string
Expand Down

0 comments on commit 4b0ae69

Please sign in to comment.