@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.
- package/LICENSE +201 -0
- package/README.md +36 -0
- package/dist/action-ledger-capabilities.d.ts +20 -0
- package/dist/action-ledger-capabilities.d.ts.map +1 -0
- package/dist/action-ledger-capabilities.js +16 -0
- package/dist/events.d.ts +23 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/events.js +9 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +49 -0
- package/dist/route-runtime.d.ts +21 -0
- package/dist/route-runtime.d.ts.map +1 -0
- package/dist/route-runtime.js +28 -0
- package/dist/routes/accounts.d.ts +1460 -0
- package/dist/routes/accounts.d.ts.map +1 -0
- package/dist/routes/accounts.js +274 -0
- package/dist/routes/activities.d.ts +299 -0
- package/dist/routes/activities.d.ts.map +1 -0
- package/dist/routes/activities.js +64 -0
- package/dist/routes/custom-fields.d.ts +256 -0
- package/dist/routes/custom-fields.d.ts.map +1 -0
- package/dist/routes/custom-fields.js +47 -0
- package/dist/routes/customer-signals.d.ts +281 -0
- package/dist/routes/customer-signals.d.ts.map +1 -0
- package/dist/routes/customer-signals.js +45 -0
- package/dist/routes/index.d.ts +2945 -0
- package/dist/routes/index.d.ts.map +1 -0
- package/dist/routes/index.js +14 -0
- package/dist/routes/person-documents.d.ts +519 -0
- package/dist/routes/person-documents.d.ts.map +1 -0
- package/dist/routes/person-documents.js +240 -0
- package/dist/routes/person-relationships.d.ts +189 -0
- package/dist/routes/person-relationships.d.ts.map +1 -0
- package/dist/routes/person-relationships.js +36 -0
- package/dist/schema-accounts.d.ts +2099 -0
- package/dist/schema-accounts.d.ts.map +1 -0
- package/dist/schema-accounts.js +312 -0
- package/dist/schema-activities.d.ts +821 -0
- package/dist/schema-activities.d.ts.map +1 -0
- package/dist/schema-activities.js +92 -0
- package/dist/schema-relations.d.ts +47 -0
- package/dist/schema-relations.d.ts.map +1 -0
- package/dist/schema-relations.js +70 -0
- package/dist/schema-shared.d.ts +10 -0
- package/dist/schema-shared.d.ts.map +1 -0
- package/dist/schema-shared.js +36 -0
- package/dist/schema-signals.d.ts +324 -0
- package/dist/schema-signals.d.ts.map +1 -0
- package/dist/schema-signals.js +80 -0
- package/dist/schema.d.ts +6 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +5 -0
- package/dist/service/accounts-merge.d.ts +63 -0
- package/dist/service/accounts-merge.d.ts.map +1 -0
- package/dist/service/accounts-merge.js +382 -0
- package/dist/service/accounts-organizations.d.ts +97 -0
- package/dist/service/accounts-organizations.d.ts.map +1 -0
- package/dist/service/accounts-organizations.js +70 -0
- package/dist/service/accounts-people.d.ts +1315 -0
- package/dist/service/accounts-people.d.ts.map +1 -0
- package/dist/service/accounts-people.js +409 -0
- package/dist/service/accounts-resolve.d.ts +76 -0
- package/dist/service/accounts-resolve.d.ts.map +1 -0
- package/dist/service/accounts-resolve.js +103 -0
- package/dist/service/accounts-shared.d.ts +68 -0
- package/dist/service/accounts-shared.d.ts.map +1 -0
- package/dist/service/accounts-shared.js +149 -0
- package/dist/service/accounts.d.ts +1465 -0
- package/dist/service/accounts.d.ts.map +1 -0
- package/dist/service/accounts.js +13 -0
- package/dist/service/activities.d.ts +486 -0
- package/dist/service/activities.d.ts.map +1 -0
- package/dist/service/activities.js +114 -0
- package/dist/service/custom-fields.d.ts +118 -0
- package/dist/service/custom-fields.d.ts.map +1 -0
- package/dist/service/custom-fields.js +88 -0
- package/dist/service/customer-signals.d.ts +733 -0
- package/dist/service/customer-signals.d.ts.map +1 -0
- package/dist/service/customer-signals.js +112 -0
- package/dist/service/helpers.d.ts +22 -0
- package/dist/service/helpers.d.ts.map +1 -0
- package/dist/service/helpers.js +39 -0
- package/dist/service/index.d.ts +4434 -0
- package/dist/service/index.d.ts.map +1 -0
- package/dist/service/index.js +17 -0
- package/dist/service/person-documents.d.ts +1201 -0
- package/dist/service/person-documents.d.ts.map +1 -0
- package/dist/service/person-documents.js +240 -0
- package/dist/service/person-relationships.d.ts +502 -0
- package/dist/service/person-relationships.d.ts.map +1 -0
- package/dist/service/person-relationships.js +121 -0
- package/dist/validation.d.ts +3 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +1 -0
- package/package.json +80 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"accounts.d.ts","sourceRoot":"","sources":["../../src/routes/accounts.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AA0BjE,KAAK,GAAG,GAAG;IACT,SAAS,EAAE;QACT,EAAE,EAAE,kBAAkB,CAAA;QACtB,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,CAAA;CACF,CAAA;AAYD,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBAwWtB,CAAA"}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import { idempotencyKey, parseJsonBody, parseQuery, requireUserId } from "@voyant-travel/hono";
|
|
2
|
+
import { insertAddressSchema, insertContactPointSchema, updateAddressSchema, updateContactPointSchema, } from "@voyant-travel/identity/validation";
|
|
3
|
+
import { Hono } from "hono";
|
|
4
|
+
import { RelationshipsMergeError } from "../service/accounts-merge.js";
|
|
5
|
+
import { relationshipsService } from "../service/index.js";
|
|
6
|
+
import { communicationListQuerySchema, insertCommunicationLogSchema, insertOrganizationNoteSchema, insertOrganizationSchema, insertPersonNoteSchema, insertPersonPaymentMethodSchema, insertPersonSchema, insertSegmentSchema, mergeOrganizationSchema, mergePersonSchema, organizationListQuerySchema, personListQuerySchema, updateOrganizationNoteSchema, updateOrganizationSchema, updatePersonNoteSchema, updatePersonPaymentMethodSchema, updatePersonSchema, } from "../validation.js";
|
|
7
|
+
const organizationEntity = "organization";
|
|
8
|
+
const personEntity = "person";
|
|
9
|
+
function mergeErrorResponse(c, error) {
|
|
10
|
+
if (error instanceof RelationshipsMergeError) {
|
|
11
|
+
return c.json({ error: error.message }, error.status);
|
|
12
|
+
}
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
export const accountRoutes = new Hono()
|
|
16
|
+
// Organizations
|
|
17
|
+
.get("/organizations", async (c) => {
|
|
18
|
+
const query = parseQuery(c, organizationListQuerySchema);
|
|
19
|
+
return c.json(await relationshipsService.listOrganizations(c.get("db"), query));
|
|
20
|
+
})
|
|
21
|
+
.post("/organizations", idempotencyKey({ scope: "POST /v1/admin/relationships/organizations" }), async (c) => {
|
|
22
|
+
return c.json({
|
|
23
|
+
data: await relationshipsService.createOrganization(c.get("db"), await parseJsonBody(c, insertOrganizationSchema)),
|
|
24
|
+
}, 201);
|
|
25
|
+
})
|
|
26
|
+
.get("/organizations/:id", async (c) => {
|
|
27
|
+
const row = await relationshipsService.getOrganizationById(c.get("db"), c.req.param("id"));
|
|
28
|
+
if (!row)
|
|
29
|
+
return c.json({ error: "Organization not found" }, 404);
|
|
30
|
+
return c.json({ data: row });
|
|
31
|
+
})
|
|
32
|
+
.patch("/organizations/:id", async (c) => {
|
|
33
|
+
const row = await relationshipsService.updateOrganization(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateOrganizationSchema));
|
|
34
|
+
if (!row)
|
|
35
|
+
return c.json({ error: "Organization not found" }, 404);
|
|
36
|
+
return c.json({ data: row });
|
|
37
|
+
})
|
|
38
|
+
.post("/organizations/:id/merge", async (c) => {
|
|
39
|
+
try {
|
|
40
|
+
const body = await parseJsonBody(c, mergeOrganizationSchema);
|
|
41
|
+
const row = await relationshipsService.mergeOrganization(c.get("db"), c.req.param("id"), body.mergeId);
|
|
42
|
+
return c.json({ data: row });
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
return mergeErrorResponse(c, error);
|
|
46
|
+
}
|
|
47
|
+
})
|
|
48
|
+
.delete("/organizations/:id", async (c) => {
|
|
49
|
+
const row = await relationshipsService.deleteOrganization(c.get("db"), c.req.param("id"));
|
|
50
|
+
if (!row)
|
|
51
|
+
return c.json({ error: "Organization not found" }, 404);
|
|
52
|
+
return c.json({ success: true });
|
|
53
|
+
})
|
|
54
|
+
.get("/organizations/:id/contact-methods", async (c) => {
|
|
55
|
+
return c.json({
|
|
56
|
+
data: await relationshipsService.listContactMethods(c.get("db"), organizationEntity, c.req.param("id")),
|
|
57
|
+
});
|
|
58
|
+
})
|
|
59
|
+
.post("/organizations/:id/contact-methods", async (c) => {
|
|
60
|
+
return c.json({
|
|
61
|
+
data: await relationshipsService.createContactMethod(c.get("db"), organizationEntity, c.req.param("id"), await parseJsonBody(c, insertContactPointSchema)),
|
|
62
|
+
}, 201);
|
|
63
|
+
})
|
|
64
|
+
.get("/organizations/:id/addresses", async (c) => {
|
|
65
|
+
return c.json({
|
|
66
|
+
data: await relationshipsService.listAddresses(c.get("db"), organizationEntity, c.req.param("id")),
|
|
67
|
+
});
|
|
68
|
+
})
|
|
69
|
+
.post("/organizations/:id/addresses", async (c) => {
|
|
70
|
+
return c.json({
|
|
71
|
+
data: await relationshipsService.createAddress(c.get("db"), organizationEntity, c.req.param("id"), await parseJsonBody(c, insertAddressSchema)),
|
|
72
|
+
}, 201);
|
|
73
|
+
})
|
|
74
|
+
.get("/organizations/:id/notes", async (c) => {
|
|
75
|
+
return c.json({
|
|
76
|
+
data: await relationshipsService.listOrganizationNotes(c.get("db"), c.req.param("id")),
|
|
77
|
+
});
|
|
78
|
+
})
|
|
79
|
+
.post("/organizations/:id/notes", async (c) => {
|
|
80
|
+
const userId = requireUserId(c);
|
|
81
|
+
const row = await relationshipsService.createOrganizationNote(c.get("db"), c.req.param("id"), userId, await parseJsonBody(c, insertOrganizationNoteSchema));
|
|
82
|
+
if (!row)
|
|
83
|
+
return c.json({ error: "Organization not found" }, 404);
|
|
84
|
+
return c.json({ data: row }, 201);
|
|
85
|
+
})
|
|
86
|
+
.patch("/organization-notes/:id", async (c) => {
|
|
87
|
+
const body = await parseJsonBody(c, updateOrganizationNoteSchema);
|
|
88
|
+
const row = await relationshipsService.updateOrganizationNote(c.get("db"), c.req.param("id"), body.content);
|
|
89
|
+
if (!row)
|
|
90
|
+
return c.json({ error: "Note not found" }, 404);
|
|
91
|
+
return c.json({ data: row });
|
|
92
|
+
})
|
|
93
|
+
.delete("/organization-notes/:id", async (c) => {
|
|
94
|
+
const row = await relationshipsService.deleteOrganizationNote(c.get("db"), c.req.param("id"));
|
|
95
|
+
if (!row)
|
|
96
|
+
return c.json({ error: "Note not found" }, 404);
|
|
97
|
+
return c.json({ success: true });
|
|
98
|
+
})
|
|
99
|
+
// People
|
|
100
|
+
.get("/people", async (c) => {
|
|
101
|
+
const query = parseQuery(c, personListQuerySchema);
|
|
102
|
+
return c.json(await relationshipsService.listPeople(c.get("db"), query));
|
|
103
|
+
})
|
|
104
|
+
.post("/people", idempotencyKey({ scope: "POST /v1/admin/relationships/people" }), async (c) => {
|
|
105
|
+
return c.json({
|
|
106
|
+
data: await relationshipsService.createPerson(c.get("db"), await parseJsonBody(c, insertPersonSchema)),
|
|
107
|
+
}, 201);
|
|
108
|
+
})
|
|
109
|
+
.get("/people/:id", async (c) => {
|
|
110
|
+
const row = await relationshipsService.getPersonById(c.get("db"), c.req.param("id"));
|
|
111
|
+
if (!row)
|
|
112
|
+
return c.json({ error: "Person not found" }, 404);
|
|
113
|
+
return c.json({ data: row });
|
|
114
|
+
})
|
|
115
|
+
.patch("/people/:id", async (c) => {
|
|
116
|
+
const row = await relationshipsService.updatePerson(c.get("db"), c.req.param("id"), await parseJsonBody(c, updatePersonSchema));
|
|
117
|
+
if (!row)
|
|
118
|
+
return c.json({ error: "Person not found" }, 404);
|
|
119
|
+
return c.json({ data: row });
|
|
120
|
+
})
|
|
121
|
+
.post("/people/:id/merge", async (c) => {
|
|
122
|
+
try {
|
|
123
|
+
const body = await parseJsonBody(c, mergePersonSchema);
|
|
124
|
+
const row = await relationshipsService.mergePerson(c.get("db"), c.req.param("id"), body.mergeId);
|
|
125
|
+
return c.json({ data: row });
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
return mergeErrorResponse(c, error);
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
.delete("/people/:id", async (c) => {
|
|
132
|
+
const row = await relationshipsService.deletePerson(c.get("db"), c.req.param("id"));
|
|
133
|
+
if (!row)
|
|
134
|
+
return c.json({ error: "Person not found" }, 404);
|
|
135
|
+
return c.json({ success: true });
|
|
136
|
+
})
|
|
137
|
+
.get("/people/:id/contact-methods", async (c) => {
|
|
138
|
+
return c.json({
|
|
139
|
+
data: await relationshipsService.listContactMethods(c.get("db"), personEntity, c.req.param("id")),
|
|
140
|
+
});
|
|
141
|
+
})
|
|
142
|
+
.post("/people/:id/contact-methods", async (c) => {
|
|
143
|
+
return c.json({
|
|
144
|
+
data: await relationshipsService.createContactMethod(c.get("db"), personEntity, c.req.param("id"), await parseJsonBody(c, insertContactPointSchema)),
|
|
145
|
+
}, 201);
|
|
146
|
+
})
|
|
147
|
+
.get("/people/:id/addresses", async (c) => {
|
|
148
|
+
return c.json({
|
|
149
|
+
data: await relationshipsService.listAddresses(c.get("db"), personEntity, c.req.param("id")),
|
|
150
|
+
});
|
|
151
|
+
})
|
|
152
|
+
.post("/people/:id/addresses", async (c) => {
|
|
153
|
+
return c.json({
|
|
154
|
+
data: await relationshipsService.createAddress(c.get("db"), personEntity, c.req.param("id"), await parseJsonBody(c, insertAddressSchema)),
|
|
155
|
+
}, 201);
|
|
156
|
+
})
|
|
157
|
+
.get("/people/:id/notes", async (c) => {
|
|
158
|
+
return c.json({
|
|
159
|
+
data: await relationshipsService.listPersonNotes(c.get("db"), c.req.param("id")),
|
|
160
|
+
});
|
|
161
|
+
})
|
|
162
|
+
.post("/people/:id/notes", async (c) => {
|
|
163
|
+
const userId = requireUserId(c);
|
|
164
|
+
const row = await relationshipsService.createPersonNote(c.get("db"), c.req.param("id"), userId, await parseJsonBody(c, insertPersonNoteSchema));
|
|
165
|
+
if (!row)
|
|
166
|
+
return c.json({ error: "Person not found" }, 404);
|
|
167
|
+
return c.json({ data: row }, 201);
|
|
168
|
+
})
|
|
169
|
+
.patch("/person-notes/:id", async (c) => {
|
|
170
|
+
const body = await parseJsonBody(c, updatePersonNoteSchema);
|
|
171
|
+
const row = await relationshipsService.updatePersonNote(c.get("db"), c.req.param("id"), body.content);
|
|
172
|
+
if (!row)
|
|
173
|
+
return c.json({ error: "Note not found" }, 404);
|
|
174
|
+
return c.json({ data: row });
|
|
175
|
+
})
|
|
176
|
+
.delete("/person-notes/:id", async (c) => {
|
|
177
|
+
const row = await relationshipsService.deletePersonNote(c.get("db"), c.req.param("id"));
|
|
178
|
+
if (!row)
|
|
179
|
+
return c.json({ error: "Note not found" }, 404);
|
|
180
|
+
return c.json({ success: true });
|
|
181
|
+
})
|
|
182
|
+
// Payment methods on file for a person.
|
|
183
|
+
.get("/people/:id/payment-methods", async (c) => {
|
|
184
|
+
return c.json({
|
|
185
|
+
data: await relationshipsService.listPersonPaymentMethods(c.get("db"), c.req.param("id")),
|
|
186
|
+
});
|
|
187
|
+
})
|
|
188
|
+
.post("/people/:id/payment-methods", async (c) => {
|
|
189
|
+
const row = await relationshipsService.createPersonPaymentMethod(c.get("db"), c.req.param("id"), await parseJsonBody(c, insertPersonPaymentMethodSchema));
|
|
190
|
+
if (!row)
|
|
191
|
+
return c.json({ error: "Person not found" }, 404);
|
|
192
|
+
return c.json({ data: row }, 201);
|
|
193
|
+
})
|
|
194
|
+
.patch("/person-payment-methods/:id", async (c) => {
|
|
195
|
+
const row = await relationshipsService.updatePersonPaymentMethod(c.get("db"), c.req.param("id"), await parseJsonBody(c, updatePersonPaymentMethodSchema));
|
|
196
|
+
if (!row)
|
|
197
|
+
return c.json({ error: "Payment method not found" }, 404);
|
|
198
|
+
return c.json({ data: row });
|
|
199
|
+
})
|
|
200
|
+
.delete("/person-payment-methods/:id", async (c) => {
|
|
201
|
+
const row = await relationshipsService.deletePersonPaymentMethod(c.get("db"), c.req.param("id"));
|
|
202
|
+
if (!row)
|
|
203
|
+
return c.json({ error: "Payment method not found" }, 404);
|
|
204
|
+
return c.json({ success: true });
|
|
205
|
+
})
|
|
206
|
+
.get("/people/:id/communications", async (c) => {
|
|
207
|
+
const query = parseQuery(c, communicationListQuerySchema);
|
|
208
|
+
return c.json({
|
|
209
|
+
data: await relationshipsService.listCommunications(c.get("db"), c.req.param("id"), query),
|
|
210
|
+
});
|
|
211
|
+
})
|
|
212
|
+
.post("/people/:id/communications", async (c) => {
|
|
213
|
+
const row = await relationshipsService.createCommunication(c.get("db"), c.req.param("id"), await parseJsonBody(c, insertCommunicationLogSchema));
|
|
214
|
+
if (!row)
|
|
215
|
+
return c.json({ error: "Person not found" }, 404);
|
|
216
|
+
return c.json({ data: row }, 201);
|
|
217
|
+
})
|
|
218
|
+
// Segments
|
|
219
|
+
.get("/segments", async (c) => {
|
|
220
|
+
return c.json({ data: await relationshipsService.listSegments(c.get("db")) });
|
|
221
|
+
})
|
|
222
|
+
.post("/segments", async (c) => {
|
|
223
|
+
return c.json({
|
|
224
|
+
data: await relationshipsService.createSegment(c.get("db"), await parseJsonBody(c, insertSegmentSchema)),
|
|
225
|
+
}, 201);
|
|
226
|
+
})
|
|
227
|
+
.delete("/segments/:segmentId", async (c) => {
|
|
228
|
+
const row = await relationshipsService.deleteSegment(c.get("db"), c.req.param("segmentId"));
|
|
229
|
+
if (!row)
|
|
230
|
+
return c.json({ error: "Segment not found" }, 404);
|
|
231
|
+
return c.json({ success: true });
|
|
232
|
+
})
|
|
233
|
+
// CSV export/import
|
|
234
|
+
.post("/people/export", async (c) => {
|
|
235
|
+
const csv = await relationshipsService.exportPeopleCsv(c.get("db"));
|
|
236
|
+
return new Response(csv, {
|
|
237
|
+
headers: {
|
|
238
|
+
"Content-Type": "text/csv",
|
|
239
|
+
"Content-Disposition": 'attachment; filename="people.csv"',
|
|
240
|
+
},
|
|
241
|
+
});
|
|
242
|
+
})
|
|
243
|
+
.post("/people/import", async (c) => {
|
|
244
|
+
const result = await relationshipsService.importPeopleCsv(c.get("db"), await c.req.text());
|
|
245
|
+
if ("error" in result) {
|
|
246
|
+
return c.json({ error: result.error }, 400);
|
|
247
|
+
}
|
|
248
|
+
return c.json(result, 200);
|
|
249
|
+
})
|
|
250
|
+
// Shared contact method and address resources
|
|
251
|
+
.patch("/contact-methods/:id", async (c) => {
|
|
252
|
+
const row = await relationshipsService.updateContactMethod(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateContactPointSchema));
|
|
253
|
+
if (!row)
|
|
254
|
+
return c.json({ error: "Contact method not found" }, 404);
|
|
255
|
+
return c.json({ data: row });
|
|
256
|
+
})
|
|
257
|
+
.delete("/contact-methods/:id", async (c) => {
|
|
258
|
+
const row = await relationshipsService.deleteContactMethod(c.get("db"), c.req.param("id"));
|
|
259
|
+
if (!row)
|
|
260
|
+
return c.json({ error: "Contact method not found" }, 404);
|
|
261
|
+
return c.json({ success: true });
|
|
262
|
+
})
|
|
263
|
+
.patch("/addresses/:id", async (c) => {
|
|
264
|
+
const row = await relationshipsService.updateAddress(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateAddressSchema));
|
|
265
|
+
if (!row)
|
|
266
|
+
return c.json({ error: "Address not found" }, 404);
|
|
267
|
+
return c.json({ data: row });
|
|
268
|
+
})
|
|
269
|
+
.delete("/addresses/:id", async (c) => {
|
|
270
|
+
const row = await relationshipsService.deleteAddress(c.get("db"), c.req.param("id"));
|
|
271
|
+
if (!row)
|
|
272
|
+
return c.json({ error: "Address not found" }, 404);
|
|
273
|
+
return c.json({ success: true });
|
|
274
|
+
});
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
2
|
+
type Env = {
|
|
3
|
+
Variables: {
|
|
4
|
+
db: PostgresJsDatabase;
|
|
5
|
+
userId?: string;
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
export declare const activityRoutes: import("hono/hono-base").HonoBase<Env, {
|
|
9
|
+
"/activities": {
|
|
10
|
+
$get: {
|
|
11
|
+
input: {};
|
|
12
|
+
output: {
|
|
13
|
+
data: {
|
|
14
|
+
id: string;
|
|
15
|
+
subject: string;
|
|
16
|
+
type: "email" | "meeting" | "call" | "task" | "follow_up" | "note";
|
|
17
|
+
ownerId: string | null;
|
|
18
|
+
status: "cancelled" | "planned" | "done";
|
|
19
|
+
dueAt: string | null;
|
|
20
|
+
completedAt: string | null;
|
|
21
|
+
location: string | null;
|
|
22
|
+
description: string | null;
|
|
23
|
+
createdAt: string;
|
|
24
|
+
updatedAt: string;
|
|
25
|
+
}[];
|
|
26
|
+
total: number;
|
|
27
|
+
limit: number;
|
|
28
|
+
offset: number;
|
|
29
|
+
};
|
|
30
|
+
outputFormat: "json";
|
|
31
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
} & {
|
|
35
|
+
"/activities": {
|
|
36
|
+
$post: {
|
|
37
|
+
input: {};
|
|
38
|
+
output: {
|
|
39
|
+
data: {
|
|
40
|
+
id: string;
|
|
41
|
+
status: "cancelled" | "planned" | "done";
|
|
42
|
+
createdAt: string;
|
|
43
|
+
type: "email" | "meeting" | "call" | "task" | "follow_up" | "note";
|
|
44
|
+
ownerId: string | null;
|
|
45
|
+
updatedAt: string;
|
|
46
|
+
subject: string;
|
|
47
|
+
description: string | null;
|
|
48
|
+
dueAt: string | null;
|
|
49
|
+
completedAt: string | null;
|
|
50
|
+
location: string | null;
|
|
51
|
+
} | undefined;
|
|
52
|
+
};
|
|
53
|
+
outputFormat: "json";
|
|
54
|
+
status: 201;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
} & {
|
|
58
|
+
"/activities/:id": {
|
|
59
|
+
$get: {
|
|
60
|
+
input: {
|
|
61
|
+
param: {
|
|
62
|
+
id: string;
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
output: {
|
|
66
|
+
error: string;
|
|
67
|
+
};
|
|
68
|
+
outputFormat: "json";
|
|
69
|
+
status: 404;
|
|
70
|
+
} | {
|
|
71
|
+
input: {
|
|
72
|
+
param: {
|
|
73
|
+
id: string;
|
|
74
|
+
};
|
|
75
|
+
};
|
|
76
|
+
output: {
|
|
77
|
+
data: {
|
|
78
|
+
id: string;
|
|
79
|
+
subject: string;
|
|
80
|
+
type: "email" | "meeting" | "call" | "task" | "follow_up" | "note";
|
|
81
|
+
ownerId: string | null;
|
|
82
|
+
status: "cancelled" | "planned" | "done";
|
|
83
|
+
dueAt: string | null;
|
|
84
|
+
completedAt: string | null;
|
|
85
|
+
location: string | null;
|
|
86
|
+
description: string | null;
|
|
87
|
+
createdAt: string;
|
|
88
|
+
updatedAt: string;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
outputFormat: "json";
|
|
92
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
93
|
+
};
|
|
94
|
+
};
|
|
95
|
+
} & {
|
|
96
|
+
"/activities/:id": {
|
|
97
|
+
$patch: {
|
|
98
|
+
input: {
|
|
99
|
+
param: {
|
|
100
|
+
id: string;
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
output: {
|
|
104
|
+
error: string;
|
|
105
|
+
};
|
|
106
|
+
outputFormat: "json";
|
|
107
|
+
status: 404;
|
|
108
|
+
} | {
|
|
109
|
+
input: {
|
|
110
|
+
param: {
|
|
111
|
+
id: string;
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
output: {
|
|
115
|
+
data: {
|
|
116
|
+
id: string;
|
|
117
|
+
subject: string;
|
|
118
|
+
type: "email" | "meeting" | "call" | "task" | "follow_up" | "note";
|
|
119
|
+
ownerId: string | null;
|
|
120
|
+
status: "cancelled" | "planned" | "done";
|
|
121
|
+
dueAt: string | null;
|
|
122
|
+
completedAt: string | null;
|
|
123
|
+
location: string | null;
|
|
124
|
+
description: string | null;
|
|
125
|
+
createdAt: string;
|
|
126
|
+
updatedAt: string;
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
outputFormat: "json";
|
|
130
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
} & {
|
|
134
|
+
"/activities/:id": {
|
|
135
|
+
$delete: {
|
|
136
|
+
input: {
|
|
137
|
+
param: {
|
|
138
|
+
id: string;
|
|
139
|
+
};
|
|
140
|
+
};
|
|
141
|
+
output: {
|
|
142
|
+
error: string;
|
|
143
|
+
};
|
|
144
|
+
outputFormat: "json";
|
|
145
|
+
status: 404;
|
|
146
|
+
} | {
|
|
147
|
+
input: {
|
|
148
|
+
param: {
|
|
149
|
+
id: string;
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
output: {
|
|
153
|
+
success: true;
|
|
154
|
+
};
|
|
155
|
+
outputFormat: "json";
|
|
156
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
159
|
+
} & {
|
|
160
|
+
"/activities/:id/links": {
|
|
161
|
+
$get: {
|
|
162
|
+
input: {
|
|
163
|
+
param: {
|
|
164
|
+
id: string;
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
output: {
|
|
168
|
+
data: {
|
|
169
|
+
id: string;
|
|
170
|
+
activityId: string;
|
|
171
|
+
entityType: "person" | "organization" | "quote" | "activity";
|
|
172
|
+
entityId: string;
|
|
173
|
+
role: "primary" | "related";
|
|
174
|
+
createdAt: string;
|
|
175
|
+
}[];
|
|
176
|
+
};
|
|
177
|
+
outputFormat: "json";
|
|
178
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
} & {
|
|
182
|
+
"/activities/:id/links": {
|
|
183
|
+
$post: {
|
|
184
|
+
input: {
|
|
185
|
+
param: {
|
|
186
|
+
id: string;
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
output: {
|
|
190
|
+
data: {
|
|
191
|
+
id: string;
|
|
192
|
+
createdAt: string;
|
|
193
|
+
entityType: "person" | "organization" | "quote" | "activity";
|
|
194
|
+
entityId: string;
|
|
195
|
+
role: "primary" | "related";
|
|
196
|
+
activityId: string;
|
|
197
|
+
} | undefined;
|
|
198
|
+
};
|
|
199
|
+
outputFormat: "json";
|
|
200
|
+
status: 201;
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
} & {
|
|
204
|
+
"/activity-links/:id": {
|
|
205
|
+
$delete: {
|
|
206
|
+
input: {
|
|
207
|
+
param: {
|
|
208
|
+
id: string;
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
output: {
|
|
212
|
+
error: string;
|
|
213
|
+
};
|
|
214
|
+
outputFormat: "json";
|
|
215
|
+
status: 404;
|
|
216
|
+
} | {
|
|
217
|
+
input: {
|
|
218
|
+
param: {
|
|
219
|
+
id: string;
|
|
220
|
+
};
|
|
221
|
+
};
|
|
222
|
+
output: {
|
|
223
|
+
success: true;
|
|
224
|
+
};
|
|
225
|
+
outputFormat: "json";
|
|
226
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
} & {
|
|
230
|
+
"/activities/:id/participants": {
|
|
231
|
+
$get: {
|
|
232
|
+
input: {
|
|
233
|
+
param: {
|
|
234
|
+
id: string;
|
|
235
|
+
};
|
|
236
|
+
};
|
|
237
|
+
output: {
|
|
238
|
+
data: {
|
|
239
|
+
id: string;
|
|
240
|
+
activityId: string;
|
|
241
|
+
personId: string;
|
|
242
|
+
isPrimary: boolean;
|
|
243
|
+
createdAt: string;
|
|
244
|
+
}[];
|
|
245
|
+
};
|
|
246
|
+
outputFormat: "json";
|
|
247
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
248
|
+
};
|
|
249
|
+
};
|
|
250
|
+
} & {
|
|
251
|
+
"/activities/:id/participants": {
|
|
252
|
+
$post: {
|
|
253
|
+
input: {
|
|
254
|
+
param: {
|
|
255
|
+
id: string;
|
|
256
|
+
};
|
|
257
|
+
};
|
|
258
|
+
output: {
|
|
259
|
+
data: {
|
|
260
|
+
id: string;
|
|
261
|
+
createdAt: string;
|
|
262
|
+
isPrimary: boolean;
|
|
263
|
+
personId: string;
|
|
264
|
+
activityId: string;
|
|
265
|
+
} | undefined;
|
|
266
|
+
};
|
|
267
|
+
outputFormat: "json";
|
|
268
|
+
status: 201;
|
|
269
|
+
};
|
|
270
|
+
};
|
|
271
|
+
} & {
|
|
272
|
+
"/activity-participants/:id": {
|
|
273
|
+
$delete: {
|
|
274
|
+
input: {
|
|
275
|
+
param: {
|
|
276
|
+
id: string;
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
output: {
|
|
280
|
+
error: string;
|
|
281
|
+
};
|
|
282
|
+
outputFormat: "json";
|
|
283
|
+
status: 404;
|
|
284
|
+
} | {
|
|
285
|
+
input: {
|
|
286
|
+
param: {
|
|
287
|
+
id: string;
|
|
288
|
+
};
|
|
289
|
+
};
|
|
290
|
+
output: {
|
|
291
|
+
success: true;
|
|
292
|
+
};
|
|
293
|
+
outputFormat: "json";
|
|
294
|
+
status: import("hono/utils/http-status").ContentfulStatusCode;
|
|
295
|
+
};
|
|
296
|
+
};
|
|
297
|
+
}, "/", "/activity-participants/:id">;
|
|
298
|
+
export {};
|
|
299
|
+
//# sourceMappingURL=activities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"activities.d.ts","sourceRoot":"","sources":["../../src/routes/activities.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAYjE,KAAK,GAAG,GAAG;IACT,SAAS,EAAE;QACT,EAAE,EAAE,kBAAkB,CAAA;QACtB,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,CAAA;CACF,CAAA;AAED,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qCA8EvB,CAAA"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { parseJsonBody, parseQuery } from "@voyant-travel/hono";
|
|
2
|
+
import { Hono } from "hono";
|
|
3
|
+
import { relationshipsService } from "../service/index.js";
|
|
4
|
+
import { activityListQuerySchema, insertActivityLinkSchema, insertActivityParticipantSchema, insertActivitySchema, updateActivitySchema, } from "../validation.js";
|
|
5
|
+
export const activityRoutes = new Hono()
|
|
6
|
+
.get("/activities", async (c) => {
|
|
7
|
+
const query = await parseQuery(c, activityListQuerySchema);
|
|
8
|
+
return c.json(await relationshipsService.listActivities(c.get("db"), query));
|
|
9
|
+
})
|
|
10
|
+
.post("/activities", async (c) => {
|
|
11
|
+
return c.json({
|
|
12
|
+
data: await relationshipsService.createActivity(c.get("db"), await parseJsonBody(c, insertActivitySchema)),
|
|
13
|
+
}, 201);
|
|
14
|
+
})
|
|
15
|
+
.get("/activities/:id", async (c) => {
|
|
16
|
+
const row = await relationshipsService.getActivityById(c.get("db"), c.req.param("id"));
|
|
17
|
+
if (!row)
|
|
18
|
+
return c.json({ error: "Activity not found" }, 404);
|
|
19
|
+
return c.json({ data: row });
|
|
20
|
+
})
|
|
21
|
+
.patch("/activities/:id", async (c) => {
|
|
22
|
+
const row = await relationshipsService.updateActivity(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateActivitySchema));
|
|
23
|
+
if (!row)
|
|
24
|
+
return c.json({ error: "Activity not found" }, 404);
|
|
25
|
+
return c.json({ data: row });
|
|
26
|
+
})
|
|
27
|
+
.delete("/activities/:id", async (c) => {
|
|
28
|
+
const row = await relationshipsService.deleteActivity(c.get("db"), c.req.param("id"));
|
|
29
|
+
if (!row)
|
|
30
|
+
return c.json({ error: "Activity not found" }, 404);
|
|
31
|
+
return c.json({ success: true });
|
|
32
|
+
})
|
|
33
|
+
.get("/activities/:id/links", async (c) => {
|
|
34
|
+
return c.json({
|
|
35
|
+
data: await relationshipsService.listActivityLinks(c.get("db"), c.req.param("id")),
|
|
36
|
+
});
|
|
37
|
+
})
|
|
38
|
+
.post("/activities/:id/links", async (c) => {
|
|
39
|
+
return c.json({
|
|
40
|
+
data: await relationshipsService.createActivityLink(c.get("db"), c.req.param("id"), await parseJsonBody(c, insertActivityLinkSchema)),
|
|
41
|
+
}, 201);
|
|
42
|
+
})
|
|
43
|
+
.delete("/activity-links/:id", async (c) => {
|
|
44
|
+
const row = await relationshipsService.deleteActivityLink(c.get("db"), c.req.param("id"));
|
|
45
|
+
if (!row)
|
|
46
|
+
return c.json({ error: "Activity link not found" }, 404);
|
|
47
|
+
return c.json({ success: true });
|
|
48
|
+
})
|
|
49
|
+
.get("/activities/:id/participants", async (c) => {
|
|
50
|
+
return c.json({
|
|
51
|
+
data: await relationshipsService.listActivityParticipants(c.get("db"), c.req.param("id")),
|
|
52
|
+
});
|
|
53
|
+
})
|
|
54
|
+
.post("/activities/:id/participants", async (c) => {
|
|
55
|
+
return c.json({
|
|
56
|
+
data: await relationshipsService.createActivityParticipant(c.get("db"), c.req.param("id"), await parseJsonBody(c, insertActivityParticipantSchema)),
|
|
57
|
+
}, 201);
|
|
58
|
+
})
|
|
59
|
+
.delete("/activity-participants/:id", async (c) => {
|
|
60
|
+
const row = await relationshipsService.deleteActivityParticipant(c.get("db"), c.req.param("id"));
|
|
61
|
+
if (!row)
|
|
62
|
+
return c.json({ error: "Activity participant not found" }, 404);
|
|
63
|
+
return c.json({ success: true });
|
|
64
|
+
});
|