Skip to content

Commit

Permalink
fix(teams&users): XXX-0 fix timely api path in teams and return values
Browse files Browse the repository at this point in the history
  • Loading branch information
noticeeverything committed Sep 28, 2021
1 parent b7a339e commit b801386
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/lib/teams/teams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ export class Teams {
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
return response.find((u) => u.name === name) as TimelyTeam
}

async update(teamId: number, team: Partial<TimelyTeam>): Promise<TimelyTeam> {
const { data } = await this.http.put(`/${this.config.accountId}/teams${teamId}`, { team })
const { data } = await this.http.put(`/${this.config.accountId}/teams/${teamId}`, { team })
return data
}
}
3 changes: 2 additions & 1 deletion src/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export interface TimelyUser {
id: number
name: string
}
projects?: { project_id: number; hour_rate?: number }[]
}

export interface TimelyLabel {
Expand Down Expand Up @@ -377,7 +378,7 @@ export type TimelyEventBulkUpdate = OptionalExceptFor<TimelyEvent, 'id'>

export type AddTimelyClient = OptionalExceptFor<TimelyClient, 'name'>

export type AddTimelyUser = OptionalExceptFor<TimelyUser, 'name' | 'email' | 'role_id'>
export type AddTimelyUser = OptionalExceptFor<TimelyUser, 'name' | 'email' | 'role_id' | 'projects'>

export type AddTimelyLabel = OptionalExceptFor<TimelyLabel, 'name'>

Expand Down
6 changes: 2 additions & 4 deletions src/lib/users/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ export class Users {
const { data: response }: { data: TimelyUser[] } = await this.http.get(
`/${this.config.accountId}/users?limit=999`,
)
const user = response.find((u) => u.email === userEmail)
if (!user) throw new Error(`Can't find user with email of ${userEmail}`)
return user
return response.find((u) => u.email === userEmail) as TimelyUser
}

async add(user: TimelyUser): Promise<AddTimelyUser> {
async add(user: AddTimelyUser): Promise<TimelyUser> {
const { data } = await this.http.post(`/${this.config.accountId}/users`, { user })
return data
}
Expand Down

0 comments on commit b801386

Please sign in to comment.