@voyant-travel/relationships 0.119.2

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.
Files changed (96) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +36 -0
  3. package/dist/action-ledger-capabilities.d.ts +20 -0
  4. package/dist/action-ledger-capabilities.d.ts.map +1 -0
  5. package/dist/action-ledger-capabilities.js +16 -0
  6. package/dist/events.d.ts +23 -0
  7. package/dist/events.d.ts.map +1 -0
  8. package/dist/events.js +9 -0
  9. package/dist/index.d.ts +32 -0
  10. package/dist/index.d.ts.map +1 -0
  11. package/dist/index.js +49 -0
  12. package/dist/route-runtime.d.ts +21 -0
  13. package/dist/route-runtime.d.ts.map +1 -0
  14. package/dist/route-runtime.js +28 -0
  15. package/dist/routes/accounts.d.ts +1460 -0
  16. package/dist/routes/accounts.d.ts.map +1 -0
  17. package/dist/routes/accounts.js +274 -0
  18. package/dist/routes/activities.d.ts +299 -0
  19. package/dist/routes/activities.d.ts.map +1 -0
  20. package/dist/routes/activities.js +64 -0
  21. package/dist/routes/custom-fields.d.ts +256 -0
  22. package/dist/routes/custom-fields.d.ts.map +1 -0
  23. package/dist/routes/custom-fields.js +47 -0
  24. package/dist/routes/customer-signals.d.ts +281 -0
  25. package/dist/routes/customer-signals.d.ts.map +1 -0
  26. package/dist/routes/customer-signals.js +45 -0
  27. package/dist/routes/index.d.ts +2945 -0
  28. package/dist/routes/index.d.ts.map +1 -0
  29. package/dist/routes/index.js +14 -0
  30. package/dist/routes/person-documents.d.ts +519 -0
  31. package/dist/routes/person-documents.d.ts.map +1 -0
  32. package/dist/routes/person-documents.js +240 -0
  33. package/dist/routes/person-relationships.d.ts +189 -0
  34. package/dist/routes/person-relationships.d.ts.map +1 -0
  35. package/dist/routes/person-relationships.js +36 -0
  36. package/dist/schema-accounts.d.ts +2099 -0
  37. package/dist/schema-accounts.d.ts.map +1 -0
  38. package/dist/schema-accounts.js +312 -0
  39. package/dist/schema-activities.d.ts +821 -0
  40. package/dist/schema-activities.d.ts.map +1 -0
  41. package/dist/schema-activities.js +92 -0
  42. package/dist/schema-relations.d.ts +47 -0
  43. package/dist/schema-relations.d.ts.map +1 -0
  44. package/dist/schema-relations.js +70 -0
  45. package/dist/schema-shared.d.ts +10 -0
  46. package/dist/schema-shared.d.ts.map +1 -0
  47. package/dist/schema-shared.js +36 -0
  48. package/dist/schema-signals.d.ts +324 -0
  49. package/dist/schema-signals.d.ts.map +1 -0
  50. package/dist/schema-signals.js +80 -0
  51. package/dist/schema.d.ts +6 -0
  52. package/dist/schema.d.ts.map +1 -0
  53. package/dist/schema.js +5 -0
  54. package/dist/service/accounts-merge.d.ts +63 -0
  55. package/dist/service/accounts-merge.d.ts.map +1 -0
  56. package/dist/service/accounts-merge.js +382 -0
  57. package/dist/service/accounts-organizations.d.ts +97 -0
  58. package/dist/service/accounts-organizations.d.ts.map +1 -0
  59. package/dist/service/accounts-organizations.js +70 -0
  60. package/dist/service/accounts-people.d.ts +1315 -0
  61. package/dist/service/accounts-people.d.ts.map +1 -0
  62. package/dist/service/accounts-people.js +409 -0
  63. package/dist/service/accounts-resolve.d.ts +76 -0
  64. package/dist/service/accounts-resolve.d.ts.map +1 -0
  65. package/dist/service/accounts-resolve.js +103 -0
  66. package/dist/service/accounts-shared.d.ts +68 -0
  67. package/dist/service/accounts-shared.d.ts.map +1 -0
  68. package/dist/service/accounts-shared.js +149 -0
  69. package/dist/service/accounts.d.ts +1465 -0
  70. package/dist/service/accounts.d.ts.map +1 -0
  71. package/dist/service/accounts.js +13 -0
  72. package/dist/service/activities.d.ts +486 -0
  73. package/dist/service/activities.d.ts.map +1 -0
  74. package/dist/service/activities.js +114 -0
  75. package/dist/service/custom-fields.d.ts +118 -0
  76. package/dist/service/custom-fields.d.ts.map +1 -0
  77. package/dist/service/custom-fields.js +88 -0
  78. package/dist/service/customer-signals.d.ts +733 -0
  79. package/dist/service/customer-signals.d.ts.map +1 -0
  80. package/dist/service/customer-signals.js +112 -0
  81. package/dist/service/helpers.d.ts +22 -0
  82. package/dist/service/helpers.d.ts.map +1 -0
  83. package/dist/service/helpers.js +39 -0
  84. package/dist/service/index.d.ts +4434 -0
  85. package/dist/service/index.d.ts.map +1 -0
  86. package/dist/service/index.js +17 -0
  87. package/dist/service/person-documents.d.ts +1201 -0
  88. package/dist/service/person-documents.d.ts.map +1 -0
  89. package/dist/service/person-documents.js +240 -0
  90. package/dist/service/person-relationships.d.ts +502 -0
  91. package/dist/service/person-relationships.d.ts.map +1 -0
  92. package/dist/service/person-relationships.js +121 -0
  93. package/dist/validation.d.ts +3 -0
  94. package/dist/validation.d.ts.map +1 -0
  95. package/dist/validation.js +1 -0
  96. package/package.json +80 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../../src/service/accounts.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,wBAAwB,EACxB,qBAAqB,EACrB,uBAAuB,EACxB,MAAM,uBAAuB,CAAA;AAE9B,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAqB,CAAA;AAClF,YAAY,EACV,kBAAkB,EAClB,8BAA8B,GAC/B,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,CAAA"}
@@ -0,0 +1,13 @@
1
+ import { accountMergeService } from "./accounts-merge.js";
2
+ import { organizationAccountsService } from "./accounts-organizations.js";
3
+ import { peopleAccountsService } from "./accounts-people.js";
4
+ import { findPersonByContactPoint, personNameFromContact, upsertPersonFromContact, } from "./accounts-resolve.js";
5
+ export const accountsService = {
6
+ ...organizationAccountsService,
7
+ ...peopleAccountsService,
8
+ ...accountMergeService,
9
+ findPersonByContactPoint,
10
+ upsertPersonFromContact,
11
+ };
12
+ export { accountMergeService, RelationshipsMergeError } from "./accounts-merge.js";
13
+ export { findPersonByContactPoint, personNameFromContact, upsertPersonFromContact };
@@ -0,0 +1,486 @@
1
+ import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
2
+ import type { z } from "zod";
3
+ import type { activityListQuerySchema, insertActivityLinkSchema, insertActivityParticipantSchema, insertActivitySchema, updateActivitySchema } from "../validation.js";
4
+ type ActivityListQuery = z.infer<typeof activityListQuerySchema>;
5
+ type CreateActivityInput = z.infer<typeof insertActivitySchema>;
6
+ type UpdateActivityInput = z.infer<typeof updateActivitySchema>;
7
+ type CreateActivityLinkInput = z.infer<typeof insertActivityLinkSchema>;
8
+ type CreateActivityParticipantInput = z.infer<typeof insertActivityParticipantSchema>;
9
+ export declare const activitiesService: {
10
+ listActivities(db: PostgresJsDatabase, query: ActivityListQuery): Promise<{
11
+ data: {
12
+ id: string;
13
+ subject: string;
14
+ type: "email" | "meeting" | "call" | "task" | "follow_up" | "note";
15
+ ownerId: string | null;
16
+ status: "cancelled" | "done" | "planned";
17
+ dueAt: Date | null;
18
+ completedAt: Date | null;
19
+ location: string | null;
20
+ description: string | null;
21
+ createdAt: Date;
22
+ updatedAt: Date;
23
+ }[];
24
+ total: number;
25
+ limit: number;
26
+ offset: number;
27
+ }>;
28
+ getActivityById(db: PostgresJsDatabase, id: string): Promise<{
29
+ id: string;
30
+ subject: string;
31
+ type: "email" | "meeting" | "call" | "task" | "follow_up" | "note";
32
+ ownerId: string | null;
33
+ status: "cancelled" | "done" | "planned";
34
+ dueAt: Date | null;
35
+ completedAt: Date | null;
36
+ location: string | null;
37
+ description: string | null;
38
+ createdAt: Date;
39
+ updatedAt: Date;
40
+ } | null>;
41
+ createActivity(db: PostgresJsDatabase, data: CreateActivityInput): Promise<{
42
+ type: "email" | "meeting" | "call" | "task" | "follow_up" | "note";
43
+ description: string | null;
44
+ id: string;
45
+ status: "cancelled" | "done" | "planned";
46
+ createdAt: Date;
47
+ updatedAt: Date;
48
+ ownerId: string | null;
49
+ subject: string;
50
+ dueAt: Date | null;
51
+ completedAt: Date | null;
52
+ location: string | null;
53
+ } | undefined>;
54
+ updateActivity(db: PostgresJsDatabase, id: string, data: UpdateActivityInput): Promise<{
55
+ id: string;
56
+ subject: string;
57
+ type: "email" | "meeting" | "call" | "task" | "follow_up" | "note";
58
+ ownerId: string | null;
59
+ status: "cancelled" | "done" | "planned";
60
+ dueAt: Date | null;
61
+ completedAt: Date | null;
62
+ location: string | null;
63
+ description: string | null;
64
+ createdAt: Date;
65
+ updatedAt: Date;
66
+ } | null>;
67
+ deleteActivity(db: PostgresJsDatabase, id: string): Promise<{
68
+ id: string;
69
+ } | null>;
70
+ listActivityLinks(db: PostgresJsDatabase, activityId: string): Omit<import("drizzle-orm/pg-core").PgSelectBase<"activity_links", {
71
+ id: import("drizzle-orm/pg-core").PgColumn<{
72
+ name: string;
73
+ tableName: "activity_links";
74
+ dataType: "string";
75
+ columnType: "PgText";
76
+ data: string;
77
+ driverParam: string;
78
+ notNull: true;
79
+ hasDefault: true;
80
+ isPrimaryKey: true;
81
+ isAutoincrement: false;
82
+ hasRuntimeDefault: true;
83
+ enumValues: [string, ...string[]];
84
+ baseColumn: never;
85
+ identity: undefined;
86
+ generated: undefined;
87
+ }, {}, {}>;
88
+ activityId: import("drizzle-orm/pg-core").PgColumn<{
89
+ name: string;
90
+ tableName: "activity_links";
91
+ dataType: "string";
92
+ columnType: "PgText";
93
+ data: string;
94
+ driverParam: string;
95
+ notNull: true;
96
+ hasDefault: false;
97
+ isPrimaryKey: false;
98
+ isAutoincrement: false;
99
+ hasRuntimeDefault: false;
100
+ enumValues: [string, ...string[]];
101
+ baseColumn: never;
102
+ identity: undefined;
103
+ generated: undefined;
104
+ }, {}, {}>;
105
+ entityType: import("drizzle-orm/pg-core").PgColumn<{
106
+ name: "entity_type";
107
+ tableName: "activity_links";
108
+ dataType: "string";
109
+ columnType: "PgEnumColumn";
110
+ data: "organization" | "person" | "quote" | "activity";
111
+ driverParam: string;
112
+ notNull: true;
113
+ hasDefault: false;
114
+ isPrimaryKey: false;
115
+ isAutoincrement: false;
116
+ hasRuntimeDefault: false;
117
+ enumValues: ["organization", "person", "quote", "activity"];
118
+ baseColumn: never;
119
+ identity: undefined;
120
+ generated: undefined;
121
+ }, {}, {}>;
122
+ entityId: import("drizzle-orm/pg-core").PgColumn<{
123
+ name: "entity_id";
124
+ tableName: "activity_links";
125
+ dataType: "string";
126
+ columnType: "PgText";
127
+ data: string;
128
+ driverParam: string;
129
+ notNull: true;
130
+ hasDefault: false;
131
+ isPrimaryKey: false;
132
+ isAutoincrement: false;
133
+ hasRuntimeDefault: false;
134
+ enumValues: [string, ...string[]];
135
+ baseColumn: never;
136
+ identity: undefined;
137
+ generated: undefined;
138
+ }, {}, {}>;
139
+ role: import("drizzle-orm/pg-core").PgColumn<{
140
+ name: "role";
141
+ tableName: "activity_links";
142
+ dataType: "string";
143
+ columnType: "PgEnumColumn";
144
+ data: "primary" | "related";
145
+ driverParam: string;
146
+ notNull: true;
147
+ hasDefault: true;
148
+ isPrimaryKey: false;
149
+ isAutoincrement: false;
150
+ hasRuntimeDefault: false;
151
+ enumValues: ["primary", "related"];
152
+ baseColumn: never;
153
+ identity: undefined;
154
+ generated: undefined;
155
+ }, {}, {}>;
156
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
157
+ name: "created_at";
158
+ tableName: "activity_links";
159
+ dataType: "date";
160
+ columnType: "PgTimestamp";
161
+ data: Date;
162
+ driverParam: string;
163
+ notNull: true;
164
+ hasDefault: true;
165
+ isPrimaryKey: false;
166
+ isAutoincrement: false;
167
+ hasRuntimeDefault: false;
168
+ enumValues: undefined;
169
+ baseColumn: never;
170
+ identity: undefined;
171
+ generated: undefined;
172
+ }, {}, {}>;
173
+ }, "single", Record<"activity_links", "not-null">, false, "where" | "orderBy", {
174
+ id: string;
175
+ activityId: string;
176
+ entityType: "organization" | "person" | "quote" | "activity";
177
+ entityId: string;
178
+ role: "primary" | "related";
179
+ createdAt: Date;
180
+ }[], {
181
+ id: import("drizzle-orm/pg-core").PgColumn<{
182
+ name: string;
183
+ tableName: "activity_links";
184
+ dataType: "string";
185
+ columnType: "PgText";
186
+ data: string;
187
+ driverParam: string;
188
+ notNull: true;
189
+ hasDefault: true;
190
+ isPrimaryKey: true;
191
+ isAutoincrement: false;
192
+ hasRuntimeDefault: true;
193
+ enumValues: [string, ...string[]];
194
+ baseColumn: never;
195
+ identity: undefined;
196
+ generated: undefined;
197
+ }, {}, {}>;
198
+ activityId: import("drizzle-orm/pg-core").PgColumn<{
199
+ name: string;
200
+ tableName: "activity_links";
201
+ dataType: "string";
202
+ columnType: "PgText";
203
+ data: string;
204
+ driverParam: string;
205
+ notNull: true;
206
+ hasDefault: false;
207
+ isPrimaryKey: false;
208
+ isAutoincrement: false;
209
+ hasRuntimeDefault: false;
210
+ enumValues: [string, ...string[]];
211
+ baseColumn: never;
212
+ identity: undefined;
213
+ generated: undefined;
214
+ }, {}, {}>;
215
+ entityType: import("drizzle-orm/pg-core").PgColumn<{
216
+ name: "entity_type";
217
+ tableName: "activity_links";
218
+ dataType: "string";
219
+ columnType: "PgEnumColumn";
220
+ data: "organization" | "person" | "quote" | "activity";
221
+ driverParam: string;
222
+ notNull: true;
223
+ hasDefault: false;
224
+ isPrimaryKey: false;
225
+ isAutoincrement: false;
226
+ hasRuntimeDefault: false;
227
+ enumValues: ["organization", "person", "quote", "activity"];
228
+ baseColumn: never;
229
+ identity: undefined;
230
+ generated: undefined;
231
+ }, {}, {}>;
232
+ entityId: import("drizzle-orm/pg-core").PgColumn<{
233
+ name: "entity_id";
234
+ tableName: "activity_links";
235
+ dataType: "string";
236
+ columnType: "PgText";
237
+ data: string;
238
+ driverParam: string;
239
+ notNull: true;
240
+ hasDefault: false;
241
+ isPrimaryKey: false;
242
+ isAutoincrement: false;
243
+ hasRuntimeDefault: false;
244
+ enumValues: [string, ...string[]];
245
+ baseColumn: never;
246
+ identity: undefined;
247
+ generated: undefined;
248
+ }, {}, {}>;
249
+ role: import("drizzle-orm/pg-core").PgColumn<{
250
+ name: "role";
251
+ tableName: "activity_links";
252
+ dataType: "string";
253
+ columnType: "PgEnumColumn";
254
+ data: "primary" | "related";
255
+ driverParam: string;
256
+ notNull: true;
257
+ hasDefault: true;
258
+ isPrimaryKey: false;
259
+ isAutoincrement: false;
260
+ hasRuntimeDefault: false;
261
+ enumValues: ["primary", "related"];
262
+ baseColumn: never;
263
+ identity: undefined;
264
+ generated: undefined;
265
+ }, {}, {}>;
266
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
267
+ name: "created_at";
268
+ tableName: "activity_links";
269
+ dataType: "date";
270
+ columnType: "PgTimestamp";
271
+ data: Date;
272
+ driverParam: string;
273
+ notNull: true;
274
+ hasDefault: true;
275
+ isPrimaryKey: false;
276
+ isAutoincrement: false;
277
+ hasRuntimeDefault: false;
278
+ enumValues: undefined;
279
+ baseColumn: never;
280
+ identity: undefined;
281
+ generated: undefined;
282
+ }, {}, {}>;
283
+ }>, "where" | "orderBy">;
284
+ createActivityLink(db: PostgresJsDatabase, activityId: string, data: CreateActivityLinkInput): Promise<{
285
+ id: string;
286
+ createdAt: Date;
287
+ entityType: "organization" | "person" | "quote" | "activity";
288
+ entityId: string;
289
+ role: "primary" | "related";
290
+ activityId: string;
291
+ } | undefined>;
292
+ deleteActivityLink(db: PostgresJsDatabase, id: string): Promise<{
293
+ id: string;
294
+ } | null>;
295
+ listActivityParticipants(db: PostgresJsDatabase, activityId: string): Omit<import("drizzle-orm/pg-core").PgSelectBase<"activity_participants", {
296
+ id: import("drizzle-orm/pg-core").PgColumn<{
297
+ name: string;
298
+ tableName: "activity_participants";
299
+ dataType: "string";
300
+ columnType: "PgText";
301
+ data: string;
302
+ driverParam: string;
303
+ notNull: true;
304
+ hasDefault: true;
305
+ isPrimaryKey: true;
306
+ isAutoincrement: false;
307
+ hasRuntimeDefault: true;
308
+ enumValues: [string, ...string[]];
309
+ baseColumn: never;
310
+ identity: undefined;
311
+ generated: undefined;
312
+ }, {}, {}>;
313
+ activityId: import("drizzle-orm/pg-core").PgColumn<{
314
+ name: string;
315
+ tableName: "activity_participants";
316
+ dataType: "string";
317
+ columnType: "PgText";
318
+ data: string;
319
+ driverParam: string;
320
+ notNull: true;
321
+ hasDefault: false;
322
+ isPrimaryKey: false;
323
+ isAutoincrement: false;
324
+ hasRuntimeDefault: false;
325
+ enumValues: [string, ...string[]];
326
+ baseColumn: never;
327
+ identity: undefined;
328
+ generated: undefined;
329
+ }, {}, {}>;
330
+ personId: import("drizzle-orm/pg-core").PgColumn<{
331
+ name: string;
332
+ tableName: "activity_participants";
333
+ dataType: "string";
334
+ columnType: "PgText";
335
+ data: string;
336
+ driverParam: string;
337
+ notNull: true;
338
+ hasDefault: false;
339
+ isPrimaryKey: false;
340
+ isAutoincrement: false;
341
+ hasRuntimeDefault: false;
342
+ enumValues: [string, ...string[]];
343
+ baseColumn: never;
344
+ identity: undefined;
345
+ generated: undefined;
346
+ }, {}, {}>;
347
+ isPrimary: import("drizzle-orm/pg-core").PgColumn<{
348
+ name: "is_primary";
349
+ tableName: "activity_participants";
350
+ dataType: "boolean";
351
+ columnType: "PgBoolean";
352
+ data: boolean;
353
+ driverParam: boolean;
354
+ notNull: true;
355
+ hasDefault: true;
356
+ isPrimaryKey: false;
357
+ isAutoincrement: false;
358
+ hasRuntimeDefault: false;
359
+ enumValues: undefined;
360
+ baseColumn: never;
361
+ identity: undefined;
362
+ generated: undefined;
363
+ }, {}, {}>;
364
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
365
+ name: "created_at";
366
+ tableName: "activity_participants";
367
+ dataType: "date";
368
+ columnType: "PgTimestamp";
369
+ data: Date;
370
+ driverParam: string;
371
+ notNull: true;
372
+ hasDefault: true;
373
+ isPrimaryKey: false;
374
+ isAutoincrement: false;
375
+ hasRuntimeDefault: false;
376
+ enumValues: undefined;
377
+ baseColumn: never;
378
+ identity: undefined;
379
+ generated: undefined;
380
+ }, {}, {}>;
381
+ }, "single", Record<"activity_participants", "not-null">, false, "where" | "orderBy", {
382
+ id: string;
383
+ activityId: string;
384
+ personId: string;
385
+ isPrimary: boolean;
386
+ createdAt: Date;
387
+ }[], {
388
+ id: import("drizzle-orm/pg-core").PgColumn<{
389
+ name: string;
390
+ tableName: "activity_participants";
391
+ dataType: "string";
392
+ columnType: "PgText";
393
+ data: string;
394
+ driverParam: string;
395
+ notNull: true;
396
+ hasDefault: true;
397
+ isPrimaryKey: true;
398
+ isAutoincrement: false;
399
+ hasRuntimeDefault: true;
400
+ enumValues: [string, ...string[]];
401
+ baseColumn: never;
402
+ identity: undefined;
403
+ generated: undefined;
404
+ }, {}, {}>;
405
+ activityId: import("drizzle-orm/pg-core").PgColumn<{
406
+ name: string;
407
+ tableName: "activity_participants";
408
+ dataType: "string";
409
+ columnType: "PgText";
410
+ data: string;
411
+ driverParam: string;
412
+ notNull: true;
413
+ hasDefault: false;
414
+ isPrimaryKey: false;
415
+ isAutoincrement: false;
416
+ hasRuntimeDefault: false;
417
+ enumValues: [string, ...string[]];
418
+ baseColumn: never;
419
+ identity: undefined;
420
+ generated: undefined;
421
+ }, {}, {}>;
422
+ personId: import("drizzle-orm/pg-core").PgColumn<{
423
+ name: string;
424
+ tableName: "activity_participants";
425
+ dataType: "string";
426
+ columnType: "PgText";
427
+ data: string;
428
+ driverParam: string;
429
+ notNull: true;
430
+ hasDefault: false;
431
+ isPrimaryKey: false;
432
+ isAutoincrement: false;
433
+ hasRuntimeDefault: false;
434
+ enumValues: [string, ...string[]];
435
+ baseColumn: never;
436
+ identity: undefined;
437
+ generated: undefined;
438
+ }, {}, {}>;
439
+ isPrimary: import("drizzle-orm/pg-core").PgColumn<{
440
+ name: "is_primary";
441
+ tableName: "activity_participants";
442
+ dataType: "boolean";
443
+ columnType: "PgBoolean";
444
+ data: boolean;
445
+ driverParam: boolean;
446
+ notNull: true;
447
+ hasDefault: true;
448
+ isPrimaryKey: false;
449
+ isAutoincrement: false;
450
+ hasRuntimeDefault: false;
451
+ enumValues: undefined;
452
+ baseColumn: never;
453
+ identity: undefined;
454
+ generated: undefined;
455
+ }, {}, {}>;
456
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
457
+ name: "created_at";
458
+ tableName: "activity_participants";
459
+ dataType: "date";
460
+ columnType: "PgTimestamp";
461
+ data: Date;
462
+ driverParam: string;
463
+ notNull: true;
464
+ hasDefault: true;
465
+ isPrimaryKey: false;
466
+ isAutoincrement: false;
467
+ hasRuntimeDefault: false;
468
+ enumValues: undefined;
469
+ baseColumn: never;
470
+ identity: undefined;
471
+ generated: undefined;
472
+ }, {}, {}>;
473
+ }>, "where" | "orderBy">;
474
+ createActivityParticipant(db: PostgresJsDatabase, activityId: string, data: CreateActivityParticipantInput): Promise<{
475
+ id: string;
476
+ createdAt: Date;
477
+ isPrimary: boolean;
478
+ personId: string;
479
+ activityId: string;
480
+ } | undefined>;
481
+ deleteActivityParticipant(db: PostgresJsDatabase, id: string): Promise<{
482
+ id: string;
483
+ } | null>;
484
+ };
485
+ export {};
486
+ //# sourceMappingURL=activities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"activities.d.ts","sourceRoot":"","sources":["../../src/service/activities.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,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kB,cAAc,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kCAS7D,kBAAkB,cACV,MAAM,QACZ,8BAA8B;;;;;;;kCASF,kBAAkB,MAAM,MAAM;;;CAOnE,CAAA"}
@@ -0,0 +1,114 @@
1
+ import { and, desc, eq, ilike, inArray, or, sql } from "drizzle-orm";
2
+ import { activities, activityLinks, activityParticipants } from "../schema.js";
3
+ import { paginate, toDateOrNull } from "./helpers.js";
4
+ export const activitiesService = {
5
+ async listActivities(db, query) {
6
+ const conditions = [];
7
+ if (query.ownerId)
8
+ conditions.push(eq(activities.ownerId, query.ownerId));
9
+ if (query.status)
10
+ conditions.push(eq(activities.status, query.status));
11
+ if (query.type)
12
+ conditions.push(eq(activities.type, query.type));
13
+ if (query.search) {
14
+ const term = `%${query.search}%`;
15
+ conditions.push(or(ilike(activities.subject, term), ilike(activities.description, term)));
16
+ }
17
+ if (query.entityType && query.entityId) {
18
+ const linkRows = await db
19
+ .select({ activityId: activityLinks.activityId })
20
+ .from(activityLinks)
21
+ .where(and(eq(activityLinks.entityType, query.entityType), eq(activityLinks.entityId, query.entityId)));
22
+ const activityIds = linkRows.map((row) => row.activityId);
23
+ if (activityIds.length === 0) {
24
+ return { data: [], total: 0, limit: query.limit, offset: query.offset };
25
+ }
26
+ conditions.push(inArray(activities.id, activityIds));
27
+ }
28
+ const where = conditions.length ? and(...conditions) : undefined;
29
+ return paginate(db
30
+ .select()
31
+ .from(activities)
32
+ .where(where)
33
+ .limit(query.limit)
34
+ .offset(query.offset)
35
+ .orderBy(desc(activities.updatedAt)), db.select({ count: sql `count(*)::int` }).from(activities).where(where), query.limit, query.offset);
36
+ },
37
+ async getActivityById(db, id) {
38
+ const [row] = await db.select().from(activities).where(eq(activities.id, id)).limit(1);
39
+ return row ?? null;
40
+ },
41
+ async createActivity(db, data) {
42
+ const [row] = await db
43
+ .insert(activities)
44
+ .values({
45
+ ...data,
46
+ dueAt: toDateOrNull(data.dueAt),
47
+ completedAt: toDateOrNull(data.completedAt),
48
+ })
49
+ .returning();
50
+ return row;
51
+ },
52
+ async updateActivity(db, id, data) {
53
+ const patch = {
54
+ ...data,
55
+ dueAt: data.dueAt === undefined ? undefined : toDateOrNull(data.dueAt),
56
+ completedAt: data.completedAt === undefined ? undefined : toDateOrNull(data.completedAt),
57
+ updatedAt: new Date(),
58
+ };
59
+ if (data.status === "done" && !data.completedAt) {
60
+ patch.completedAt = new Date();
61
+ }
62
+ const [row] = await db.update(activities).set(patch).where(eq(activities.id, id)).returning();
63
+ return row ?? null;
64
+ },
65
+ async deleteActivity(db, id) {
66
+ const [row] = await db
67
+ .delete(activities)
68
+ .where(eq(activities.id, id))
69
+ .returning({ id: activities.id });
70
+ return row ?? null;
71
+ },
72
+ listActivityLinks(db, activityId) {
73
+ return db
74
+ .select()
75
+ .from(activityLinks)
76
+ .where(eq(activityLinks.activityId, activityId))
77
+ .orderBy(desc(activityLinks.role), activityLinks.createdAt);
78
+ },
79
+ async createActivityLink(db, activityId, data) {
80
+ const [row] = await db
81
+ .insert(activityLinks)
82
+ .values({ ...data, activityId })
83
+ .returning();
84
+ return row;
85
+ },
86
+ async deleteActivityLink(db, id) {
87
+ const [row] = await db
88
+ .delete(activityLinks)
89
+ .where(eq(activityLinks.id, id))
90
+ .returning({ id: activityLinks.id });
91
+ return row ?? null;
92
+ },
93
+ listActivityParticipants(db, activityId) {
94
+ return db
95
+ .select()
96
+ .from(activityParticipants)
97
+ .where(eq(activityParticipants.activityId, activityId))
98
+ .orderBy(desc(activityParticipants.isPrimary), activityParticipants.createdAt);
99
+ },
100
+ async createActivityParticipant(db, activityId, data) {
101
+ const [row] = await db
102
+ .insert(activityParticipants)
103
+ .values({ ...data, activityId })
104
+ .returning();
105
+ return row;
106
+ },
107
+ async deleteActivityParticipant(db, id) {
108
+ const [row] = await db
109
+ .delete(activityParticipants)
110
+ .where(eq(activityParticipants.id, id))
111
+ .returning({ id: activityParticipants.id });
112
+ return row ?? null;
113
+ },
114
+ };