Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add teams module #78

Merged
merged 1 commit into from
Sep 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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