@remit/drizzle-service 0.0.93 → 0.0.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
PutCalendarObjectInput,
|
|
5
5
|
} from "@remit/data-ports";
|
|
6
6
|
import { deriveCalendarObjectId } from "@remit/data-ports/id";
|
|
7
|
-
import { and, asc, eq, gt, lt, ne } from "drizzle-orm";
|
|
7
|
+
import { and, asc, eq, gt, gte, lt, ne } from "drizzle-orm";
|
|
8
8
|
import type { Db } from "../db.js";
|
|
9
9
|
import { NotFoundError } from "../error.js";
|
|
10
10
|
import { calendarObjectTable } from "../schema.js";
|
|
@@ -146,6 +146,23 @@ export class CalendarObjectRepo implements ICalendarObjectRepository {
|
|
|
146
146
|
return row ? rowToCalendarObject(row) : null;
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
async listByUidPrefix(
|
|
150
|
+
calendarId: string,
|
|
151
|
+
prefix: string,
|
|
152
|
+
): Promise<CalendarObjectItem[]> {
|
|
153
|
+
const rows = await this.db
|
|
154
|
+
.select()
|
|
155
|
+
.from(calendarObjectTable)
|
|
156
|
+
.where(
|
|
157
|
+
and(
|
|
158
|
+
eq(calendarObjectTable.calendarId, calendarId),
|
|
159
|
+
gte(calendarObjectTable.icalUid, prefix),
|
|
160
|
+
lt(calendarObjectTable.icalUid, `${prefix}\uffff`),
|
|
161
|
+
),
|
|
162
|
+
);
|
|
163
|
+
return rows.map(rowToCalendarObject);
|
|
164
|
+
}
|
|
165
|
+
|
|
149
166
|
async listByCalendar(calendarId: string): Promise<CalendarObjectItem[]> {
|
|
150
167
|
const rows = await this.db
|
|
151
168
|
.select()
|
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
} from "@remit/data-ports";
|
|
8
8
|
import { deriveCalendarSuggestionId } from "@remit/data-ports/id";
|
|
9
9
|
import { CalendarSuggestionState } from "@remit/domain-enums";
|
|
10
|
-
import { and, asc, desc, eq, lt, or } from "drizzle-orm";
|
|
10
|
+
import { and, asc, desc, eq, inArray, lt, or } from "drizzle-orm";
|
|
11
11
|
import type { Db } from "../db.js";
|
|
12
12
|
import { NotFoundError } from "../error.js";
|
|
13
13
|
import { decodeToken, resultList } from "../pagination.js";
|
|
@@ -37,6 +37,7 @@ function rowToCalendarSuggestion(
|
|
|
37
37
|
zoneCertainty: row.zoneCertainty,
|
|
38
38
|
icalData: row.icalData,
|
|
39
39
|
acceptedCalendarObjectId: row.acceptedCalendarObjectId,
|
|
40
|
+
supersededByMessageId: row.supersededByMessageId,
|
|
40
41
|
createdAt: row.createdAt,
|
|
41
42
|
updatedAt: row.updatedAt,
|
|
42
43
|
};
|
|
@@ -61,6 +62,7 @@ export class CalendarSuggestionRepo implements ICalendarSuggestionRepository {
|
|
|
61
62
|
suggestionId,
|
|
62
63
|
state: CalendarSuggestionState.Pending,
|
|
63
64
|
acceptedCalendarObjectId: "",
|
|
65
|
+
supersededByMessageId: "",
|
|
64
66
|
createdAt: now,
|
|
65
67
|
updatedAt: now,
|
|
66
68
|
})
|
|
@@ -97,6 +99,26 @@ export class CalendarSuggestionRepo implements ICalendarSuggestionRepository {
|
|
|
97
99
|
return rowToCalendarSuggestion(row);
|
|
98
100
|
}
|
|
99
101
|
|
|
102
|
+
async listByAcceptedCalendarObjects(
|
|
103
|
+
accountConfigId: string,
|
|
104
|
+
calendarObjectIds: string[],
|
|
105
|
+
): Promise<CalendarSuggestionItem[]> {
|
|
106
|
+
if (calendarObjectIds.length === 0) return [];
|
|
107
|
+
const rows = await this.db
|
|
108
|
+
.select()
|
|
109
|
+
.from(calendarSuggestionTable)
|
|
110
|
+
.where(
|
|
111
|
+
and(
|
|
112
|
+
eq(calendarSuggestionTable.accountConfigId, accountConfigId),
|
|
113
|
+
inArray(
|
|
114
|
+
calendarSuggestionTable.acceptedCalendarObjectId,
|
|
115
|
+
calendarObjectIds,
|
|
116
|
+
),
|
|
117
|
+
),
|
|
118
|
+
);
|
|
119
|
+
return rows.map(rowToCalendarSuggestion);
|
|
120
|
+
}
|
|
121
|
+
|
|
100
122
|
async listByMessage(
|
|
101
123
|
accountConfigId: string,
|
|
102
124
|
messageId: string,
|
|
@@ -200,12 +222,14 @@ export class CalendarSuggestionRepo implements ICalendarSuggestionRepository {
|
|
|
200
222
|
async supersedeIfPending(
|
|
201
223
|
accountConfigId: string,
|
|
202
224
|
suggestionId: string,
|
|
225
|
+
supersededByMessageId: string,
|
|
203
226
|
): Promise<CalendarSuggestionItem | null> {
|
|
204
227
|
const [row] = await this.db
|
|
205
228
|
.update(calendarSuggestionTable)
|
|
206
229
|
.set({
|
|
207
230
|
state: CalendarSuggestionState.Superseded,
|
|
208
231
|
acceptedCalendarObjectId: "",
|
|
232
|
+
supersededByMessageId,
|
|
209
233
|
updatedAt: Date.now(),
|
|
210
234
|
})
|
|
211
235
|
.where(
|
|
@@ -220,4 +244,23 @@ export class CalendarSuggestionRepo implements ICalendarSuggestionRepository {
|
|
|
220
244
|
.returning();
|
|
221
245
|
return row ? rowToCalendarSuggestion(row) : null;
|
|
222
246
|
}
|
|
247
|
+
|
|
248
|
+
async repointSuperseded(
|
|
249
|
+
accountConfigId: string,
|
|
250
|
+
suggestionId: string,
|
|
251
|
+
supersededByMessageId: string,
|
|
252
|
+
): Promise<CalendarSuggestionItem | null> {
|
|
253
|
+
const [row] = await this.db
|
|
254
|
+
.update(calendarSuggestionTable)
|
|
255
|
+
.set({ supersededByMessageId, updatedAt: Date.now() })
|
|
256
|
+
.where(
|
|
257
|
+
and(
|
|
258
|
+
eq(calendarSuggestionTable.accountConfigId, accountConfigId),
|
|
259
|
+
eq(calendarSuggestionTable.suggestionId, suggestionId),
|
|
260
|
+
eq(calendarSuggestionTable.state, CalendarSuggestionState.Superseded),
|
|
261
|
+
),
|
|
262
|
+
)
|
|
263
|
+
.returning();
|
|
264
|
+
return row ? rowToCalendarSuggestion(row) : null;
|
|
265
|
+
}
|
|
223
266
|
}
|