-
Notifications
You must be signed in to change notification settings - Fork 1
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
[NO-ISSUE] feat: allow to query multiple users (freebusy) #26
Changes from 42 commits
805f4e2
941e65f
d2234a7
446f130
0a4f16c
1f0bd04
b1df0f7
cee3d0f
a08ea16
8bac479
10439cb
6800201
e556c34
a08d635
4626cf1
6d1bf21
47d560a
1e9d5af
0e37677
a56b001
515f73e
8d0f7bd
dc66f27
dc6757e
f420558
11749f3
57a181b
bd43e72
8f1bd7f
ee5164a
c14dfc5
804da1c
0f55a28
3861c55
72147a9
9bdd463
5ff58a4
ba6229a
7f0b094
af390af
821a881
1b8e859
9693b49
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { UUID } from "./utilities" | ||
import { UUID } from './utilities' | ||
|
||
/** | ||
* Account domain model | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
|
||
|
||
/** | ||
* UUID type | ||
* @format uuid (v4) - `xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx` | ||
* @example "d3b3b3b3-3b3b-4b3b-b3b3-b3b3b3b3b3b3" | ||
*/ | ||
export type UUID = string | ||
export type UUID = string |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import type { CalendarEventInstance } from './domain/calendarEvent' | ||
import { NettuBaseClient } from './baseClient' | ||
import { APIResponse, NettuBaseClient } from './baseClient' | ||
import type { Metadata } from './domain/metadata' | ||
import type { User } from './domain/user' | ||
import type { IntegrationProvider, UUID } from '.' | ||
import { convertInstanceDates } from './helpers/datesConverters' | ||
|
||
/** | ||
* Request to get a user's freebusy | ||
|
@@ -27,14 +28,34 @@ type GetUserFeebusyReq = { | |
calendarIds?: string[] | ||
} | ||
|
||
/** | ||
* Request to get multiple users' freebusy status | ||
*/ | ||
type GetMultipleUsersFeebusyReq = { | ||
/** | ||
* List of user ids to check for freebusy | ||
*/ | ||
userIds: UUID[] | ||
/** | ||
* Start time of the period to check for freebusy | ||
* @format Date in UTC | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume you've thought of this so maybe just catch me up, but: my expectation as a user of the client would be that I'd be able to query with timezone information, this seems like the main place someone would make a mistake there. Is there a reason why this expects UTC? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have started looking into a bit more in #28, following the article that Derek shared, but it's a bit more complex than expected (I need to invest more time). Ideally, I would like (at least) the JS SDK, the Rust SDK and the API to accept any timezone. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good for me, we might need to revisit the API design later though. The reason I ask is you're going to immediately have this problem I think since we're operating in Tokyo timezone. |
||
*/ | ||
startTime: Date | ||
/** | ||
* End time of the period to check for freebusy | ||
* @format Date in UTC | ||
*/ | ||
endTime: Date | ||
} | ||
|
||
/** | ||
* Response when getting a user's freebusy | ||
*/ | ||
type GetUserFeebusyResponse = { | ||
/** | ||
* List of busy instances | ||
* List of busy instances per user_id | ||
*/ | ||
busy: CalendarEventInstance[] | ||
[key: string]: CalendarEventInstance[] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [nit] Shouldn't this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @GuillaumeDecMeetsMore minor nit, otherwise LGTM. |
||
} | ||
|
||
/** | ||
|
@@ -117,12 +138,59 @@ export class NettuUserClient extends NettuBaseClient { | |
return this.delete<UserResponse>(`/user/${userId}`) | ||
} | ||
|
||
public freebusy(userId: UUID, req: GetUserFeebusyReq) { | ||
return this.get<GetUserFeebusyResponse>(`/user/${userId}/freebusy`, { | ||
startTime: req.startTime.toISOString(), | ||
endTime: req.endTime.toISOString(), | ||
calendarIds: req.calendarIds, | ||
}) | ||
public async freebusy( | ||
userId: UUID, | ||
req: GetUserFeebusyReq | ||
): Promise<APIResponse<GetUserFeebusyResponse>> { | ||
const res = await this.get<GetUserFeebusyResponse>( | ||
`/user/${userId}/freebusy`, | ||
{ | ||
startTime: req.startTime.toISOString(), | ||
endTime: req.endTime.toISOString(), | ||
calendarIds: req.calendarIds?.join(','), | ||
} | ||
) | ||
|
||
if (!res.data) { | ||
return res | ||
} | ||
|
||
return { | ||
res: res.res, | ||
status: res.status, | ||
data: { | ||
busy: res.data.busy.map(convertInstanceDates), | ||
}, | ||
} | ||
Comment on lines
+158
to
+164
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix, it should retun |
||
} | ||
|
||
public async freebusyMultipleUsers( | ||
req: GetMultipleUsersFeebusyReq | ||
): Promise<APIResponse<GetUserFeebusyResponse>> { | ||
const res = await this.post<GetUserFeebusyResponse>( | ||
'/user/multipleFreebusy', | ||
GuillaumeDecMeetsMore marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
userIds: req.userIds, | ||
startTime: req.startTime.toISOString(), | ||
endTime: req.endTime.toISOString(), | ||
} | ||
) | ||
|
||
if (!res.data) { | ||
return res | ||
} | ||
|
||
return { | ||
res: res.res, | ||
status: res.status, | ||
data: Object.keys(res.data).reduce((acc, key) => { | ||
if (!res?.data?.[key]) { | ||
return acc | ||
} | ||
acc[key] = res.data[key].map(convertInstanceDates) | ||
return acc | ||
}, {} as GetUserFeebusyResponse), | ||
} | ||
} | ||
|
||
public oauth(userId: UUID, code: string, provider: IntegrationProvider) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Print backtrace in case of error