Skip to content

Commit 431cd7a

Browse files
refactor(calendarEvents): rework search events + add search for account level (#183)
* feat(calendarEvent): add event_type field * refactor(calendarEvents): rework search events + add account level for searching events * fix: adapt JS + fix some issues in RS * fix: StringQuery should be exported with that name * test: add unit tests * refactor: convert query's structs to enums for search * fix: still allow multiple fields for dateTime
1 parent 0ba71d8 commit 431cd7a

File tree

24 files changed

+962
-153
lines changed

24 files changed

+962
-153
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2+
import type { DateTimeQuery } from './DateTimeQuery'
3+
import type { IDQuery } from './IDQuery'
4+
import type { StringQuery } from './StringQuery'
5+
import type { JsonValue } from './serde_json/JsonValue'
6+
7+
/**
8+
* Request body for searching events for a whole account (across all users)
9+
*/
10+
export type AccountSearchEventsRequestBody = {
11+
/**
12+
* Optional query on user ID, or list of user IDs
13+
*/
14+
userId?: IDQuery
15+
/**
16+
* Optional query on parent ID (which is a string as it's an ID from an external system)
17+
*/
18+
parentId?: StringQuery
19+
/**
20+
* Optional query on the group ID
21+
*/
22+
groupId?: IDQuery
23+
/**
24+
* Optional query on start time - e.g. "lower than or equal", or "great than or equal" (UTC)
25+
*/
26+
startTime?: DateTimeQuery
27+
/**
28+
* Optional query on end time - e.g. "lower than or equal", or "great than or equal" (UTC)
29+
*/
30+
endTime?: DateTimeQuery
31+
/**
32+
* Optional query on event type
33+
*/
34+
eventType?: StringQuery
35+
/**
36+
* Optional query on event status
37+
*/
38+
status?: StringQuery
39+
/**
40+
* Optional query on updated at - e.g. "lower than or equal", or "great than or equal" (UTC)
41+
*/
42+
updatedAt?: DateTimeQuery
43+
/**
44+
* Optional query on metadata
45+
*/
46+
metadata?: JsonValue
47+
}
Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2+
import type { DateTimeQueryRange } from './DateTimeQueryRange'
23

34
/**
45
* Query parameters for searching on a date time
56
*/
6-
export type DateTimeQuery = {
7-
/**
8-
* Optional "greater than or equal" query (UTC)
9-
*/
10-
gte?: Date
11-
/**
12-
* Optional "less than or equal" query (UTC)
13-
*/
14-
lte?: Date
15-
}
7+
export type DateTimeQuery = { eq: Date } | { range: DateTimeQueryRange }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2+
3+
export type DateTimeQueryRange = {
4+
/**
5+
* "greater than or equal" query (UTC)
6+
*/
7+
gte?: Date
8+
/**
9+
* "less than or equal" query (UTC)
10+
*/
11+
lte?: Date
12+
/**
13+
* "greater than" query (UTC)
14+
* This is exclusive of the value
15+
*/
16+
gt?: Date
17+
/**
18+
* "less than" query (UTC)
19+
* This is exclusive of the value
20+
*/
21+
lt?: Date
22+
}
Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2+
import type { ID } from './ID'
23

34
/**
4-
* Query parameters for searching on an ID
5+
* Query parameters for searching on an ID (or list of IDs)
56
*/
6-
export type IDQuery = {
7-
/**
8-
* Optional String (equality test)
9-
* This is not a UUID, but a string as we allow any type of ID in this field
10-
*/
11-
eq?: string
12-
/**
13-
* Optional bool (existence test)
14-
* If "eq" is provided, this field is ignored
15-
*/
16-
exists?: boolean
17-
}
7+
export type IDQuery =
8+
| { eq: ID }
9+
| { ne: ID }
10+
| { exists: boolean }
11+
| { in: Array<ID> }

clients/javascript/lib/gen_types/SearchEventsRequestBody.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import type { DateTimeQuery } from './DateTimeQuery'
33
import type { ID } from './ID'
44
import type { IDQuery } from './IDQuery'
5+
import type { StringQuery } from './StringQuery'
56
import type { JsonValue } from './serde_json/JsonValue'
67

78
/**
@@ -18,13 +19,13 @@ export type SearchEventsRequestBody = {
1819
*/
1920
calendarIds?: Array<ID>
2021
/**
21-
* Optional query on parent ID
22+
* Optional query on parent ID (which is a string as it's an ID from an external system)
2223
*/
23-
parentId?: IDQuery
24+
parentId?: StringQuery
2425
/**
2526
* Optional query on group ID
2627
*/
27-
groupId?: ID
28+
groupId?: IDQuery
2829
/**
2930
* Optional query on start time - "lower than or equal", or "great than or equal" (UTC)
3031
*/
@@ -34,9 +35,13 @@ export type SearchEventsRequestBody = {
3435
*/
3536
endTime?: DateTimeQuery
3637
/**
37-
* Optional list of event status
38+
* Optional query on event type
3839
*/
39-
status?: Array<string>
40+
eventType?: StringQuery
41+
/**
42+
* Optional query on status
43+
*/
44+
status?: StringQuery
4045
/**
4146
* Optioanl query on updated at - "lower than or equal", or "great than or equal" (UTC)
4247
*/
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
2+
3+
/**
4+
* Query parameters for searching on a string
5+
*/
6+
export type StringQuery =
7+
| { eq: string }
8+
| { ne: string }
9+
| { exists: boolean }
10+
| { in: Array<string> }

clients/javascript/lib/gen_types/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export * from './AccountDTO'
22
export * from './AccountEventRemindersDTO'
33
export * from './AccountRemindersDTO'
44
export * from './AccountResponse'
5+
export * from './AccountSearchEventsRequestBody'
56
export * from './AccountSettingsDTO'
67
export * from './AccountWebhookSettingsDTO'
78
export * from './AddAccountIntegrationRequestBody'
@@ -28,6 +29,7 @@ export * from './CreateServiceEventIntendRequestBody'
2829
export * from './CreateServiceRequestBody'
2930
export * from './CreateUserRequestBody'
3031
export * from './DateTimeQuery'
32+
export * from './DateTimeQueryRange'
3133
export * from './EventGroup'
3234
export * from './EventGroupDTO'
3335
export * from './EventGroupResponse'
@@ -88,6 +90,7 @@ export * from './ServiceWithUsersDTO'
8890
export * from './ServiceWithUsersResponse'
8991
export * from './SetAccountPubKeyRequestBody'
9092
export * from './SetAccountWebhookRequestBody'
93+
export * from './StringQuery'
9194
export * from './Time'
9295
export * from './TimePlan'
9396
export * from './TimeSpan'

clients/javascript/tests/calendarEvent.spec.ts

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,10 @@ describe('CalendarEvent API', () => {
522522
const res = await adminClient.events.searchEvents({
523523
userId: userId,
524524
startTime: {
525-
gte: new Date(500),
525+
range: {
526+
lte: new Date(2000),
527+
gte: new Date(500),
528+
},
526529
},
527530
})
528531
expect(res.events.length).toBe(3)
@@ -532,7 +535,9 @@ describe('CalendarEvent API', () => {
532535
const res = await adminClient.events.searchEvents({
533536
userId: userId,
534537
startTime: {
535-
gte: new Date(2000),
538+
range: {
539+
gte: new Date(2000),
540+
},
536541
},
537542
})
538543
expect(res.events.length).toBe(0)
@@ -542,7 +547,9 @@ describe('CalendarEvent API', () => {
542547
const res = await adminClient.events.searchEvents({
543548
userId: userId,
544549
endTime: {
545-
lte: new Date(2000),
550+
range: {
551+
lte: new Date(2000),
552+
},
546553
},
547554
})
548555
expect(res.events.length).toBe(3)
@@ -552,7 +559,9 @@ describe('CalendarEvent API', () => {
552559
const res = await adminClient.events.searchEvents({
553560
userId: userId,
554561
endTime: {
555-
lte: new Date(500),
562+
range: {
563+
lte: new Date(500),
564+
},
556565
},
557566
})
558567
expect(res.events.length).toBe(0)
@@ -561,15 +570,19 @@ describe('CalendarEvent API', () => {
561570
it('should be able to search for events (status)', async () => {
562571
const res = await adminClient.events.searchEvents({
563572
userId: userId,
564-
status: ['tentative'],
573+
status: {
574+
in: ['tentative'],
575+
},
565576
})
566577
expect(res.events.length).toBe(2)
567578
})
568579

569580
it('should be able to search for events (multiple status)', async () => {
570581
const res = await adminClient.events.searchEvents({
571582
userId: userId,
572-
status: ['confirmed', 'tentative'],
583+
status: {
584+
in: ['confirmed', 'tentative'],
585+
},
573586
})
574587
expect(res.events.length).toBe(3)
575588
})
@@ -603,7 +616,9 @@ describe('CalendarEvent API', () => {
603616
eq: 'parentId',
604617
},
605618
startTime: {
606-
gte: new Date(500),
619+
range: {
620+
gte: new Date(500),
621+
},
607622
},
608623
})
609624
expect(res.events.length).toBe(1)
@@ -617,7 +632,9 @@ describe('CalendarEvent API', () => {
617632
eq: 'parentId',
618633
},
619634
startTime: {
620-
gte: new Date(2000),
635+
range: {
636+
gte: new Date(2000),
637+
},
621638
},
622639
})
623640
expect(res.events.length).toBe(0)
@@ -627,7 +644,9 @@ describe('CalendarEvent API', () => {
627644
const res = await adminClient.events.searchEvents({
628645
userId: userId,
629646
updatedAt: {
630-
gte: new Date(0),
647+
range: {
648+
gte: new Date(0),
649+
},
631650
},
632651
})
633652
expect(res.events.length).toBe(3)
@@ -637,7 +656,9 @@ describe('CalendarEvent API', () => {
637656
const res = await adminClient.events.searchEvents({
638657
userId: userId,
639658
updatedAt: {
640-
gte: new Date(new Date().getTime() + 10000),
659+
range: {
660+
gte: new Date(new Date().getTime() + 10000),
661+
},
641662
},
642663
})
643664
expect(res.events.length).toBe(0)
@@ -683,7 +704,9 @@ describe('CalendarEvent API', () => {
683704

684705
const resSearch = await adminClient.events.searchEvents({
685706
userId,
686-
groupId: group.eventGroup.id,
707+
groupId: {
708+
eq: group.eventGroup.id,
709+
},
687710
})
688711

689712
expect(resSearch.events.length).toBe(1)

0 commit comments

Comments
 (0)