@voyantjs/transactions 0.6.8 → 0.6.9
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/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -3
- package/dist/pii.d.ts +16 -9
- package/dist/pii.d.ts.map +1 -1
- package/dist/pii.js +76 -70
- package/dist/routes-offers.d.ts +462 -28
- package/dist/routes-offers.d.ts.map +1 -1
- package/dist/routes-offers.js +199 -84
- package/dist/routes-orders.d.ts +461 -27
- package/dist/routes-orders.d.ts.map +1 -1
- package/dist/routes-orders.js +199 -84
- package/dist/routes-shared.d.ts +20 -13
- package/dist/routes-shared.d.ts.map +1 -1
- package/dist/routes-shared.js +7 -6
- package/dist/schema/participant-identity.d.ts +43 -6
- package/dist/schema/participant-identity.d.ts.map +1 -1
- package/dist/schema/participant-identity.js +12 -5
- package/dist/schema-audit.d.ts +4 -4
- package/dist/schema-audit.js +3 -3
- package/dist/schema-contacts.d.ts +529 -0
- package/dist/schema-contacts.d.ts.map +1 -0
- package/dist/schema-contacts.js +57 -0
- package/dist/schema-offers.d.ts +177 -3
- package/dist/schema-offers.d.ts.map +1 -1
- package/dist/schema-offers.js +13 -3
- package/dist/schema-orders.d.ts +177 -3
- package/dist/schema-orders.d.ts.map +1 -1
- package/dist/schema-orders.js +13 -3
- package/dist/schema-relations.d.ts +24 -0
- package/dist/schema-relations.d.ts.map +1 -1
- package/dist/schema-relations.js +40 -2
- package/dist/schema-shared.d.ts +3 -1
- package/dist/schema-shared.d.ts.map +1 -1
- package/dist/schema-shared.js +8 -2
- package/dist/schema-staff.d.ts +529 -0
- package/dist/schema-staff.d.ts.map +1 -0
- package/dist/schema-staff.js +57 -0
- package/dist/schema.d.ts +2 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +2 -0
- package/dist/service-offers.d.ts +275 -29
- package/dist/service-offers.d.ts.map +1 -1
- package/dist/service-offers.js +306 -43
- package/dist/service-orders.d.ts +227 -25
- package/dist/service-orders.d.ts.map +1 -1
- package/dist/service-orders.js +127 -22
- package/dist/service-shared.d.ts +144 -22
- package/dist/service-shared.d.ts.map +1 -1
- package/dist/service-shared.js +30 -2
- package/dist/service.d.ts +62 -22
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +42 -2
- package/dist/storefront-offers.d.ts +39 -5
- package/dist/storefront-offers.d.ts.map +1 -1
- package/dist/storefront-offers.js +3 -3
- package/dist/validation.d.ts +674 -36
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +186 -29
- package/package.json +5 -5
package/dist/service-offers.js
CHANGED
|
@@ -1,6 +1,54 @@
|
|
|
1
1
|
import { and, asc, desc, eq, ilike, or, sql } from "drizzle-orm";
|
|
2
|
-
import { offerItemParticipants, offerItems, offerParticipants, offers } from "./schema.js";
|
|
3
|
-
import { normalizeTimestamp, paginate,
|
|
2
|
+
import { offerContactAssignments, offerItemParticipants, offerItems, offerParticipants, offerStaffAssignments, offers, } from "./schema.js";
|
|
3
|
+
import { normalizeTimestamp, paginate, toOfferContactAssignmentResponse, toOfferItemTravelerResponse, toOfferStaffAssignmentResponse, toOfferTravelerResponse, } from "./service-shared.js";
|
|
4
|
+
function isStaffParticipantType(participantType) {
|
|
5
|
+
return participantType === "staff";
|
|
6
|
+
}
|
|
7
|
+
function toStaffAssignmentRole(role) {
|
|
8
|
+
return role === "service_assignee" ? "service_assignee" : "other";
|
|
9
|
+
}
|
|
10
|
+
function pickPrimaryContactSnapshot(offer, contactAssignments) {
|
|
11
|
+
if (offer.contactFirstName ??
|
|
12
|
+
offer.contactLastName ??
|
|
13
|
+
offer.contactEmail ??
|
|
14
|
+
offer.contactPhone ??
|
|
15
|
+
offer.contactPreferredLanguage ??
|
|
16
|
+
offer.contactCountry ??
|
|
17
|
+
offer.contactRegion ??
|
|
18
|
+
offer.contactCity ??
|
|
19
|
+
offer.contactAddressLine1 ??
|
|
20
|
+
offer.contactPostalCode) {
|
|
21
|
+
return {
|
|
22
|
+
contactFirstName: offer.contactFirstName ?? null,
|
|
23
|
+
contactLastName: offer.contactLastName ?? null,
|
|
24
|
+
contactEmail: offer.contactEmail ?? null,
|
|
25
|
+
contactPhone: offer.contactPhone ?? null,
|
|
26
|
+
contactPreferredLanguage: offer.contactPreferredLanguage ?? null,
|
|
27
|
+
contactCountry: offer.contactCountry ?? null,
|
|
28
|
+
contactRegion: offer.contactRegion ?? null,
|
|
29
|
+
contactCity: offer.contactCity ?? null,
|
|
30
|
+
contactAddressLine1: offer.contactAddressLine1 ?? null,
|
|
31
|
+
contactPostalCode: offer.contactPostalCode ?? null,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const contactAssignment = contactAssignments.find((assignment) => assignment.role === "primary_contact" && assignment.isPrimary) ??
|
|
35
|
+
contactAssignments.find((assignment) => assignment.role === "primary_contact") ??
|
|
36
|
+
contactAssignments.find((assignment) => assignment.isPrimary) ??
|
|
37
|
+
contactAssignments[0] ??
|
|
38
|
+
null;
|
|
39
|
+
return {
|
|
40
|
+
contactFirstName: contactAssignment?.firstName ?? null,
|
|
41
|
+
contactLastName: contactAssignment?.lastName ?? null,
|
|
42
|
+
contactEmail: contactAssignment?.email ?? null,
|
|
43
|
+
contactPhone: contactAssignment?.phone ?? null,
|
|
44
|
+
contactPreferredLanguage: contactAssignment?.preferredLanguage ?? null,
|
|
45
|
+
contactCountry: null,
|
|
46
|
+
contactRegion: null,
|
|
47
|
+
contactCity: null,
|
|
48
|
+
contactAddressLine1: null,
|
|
49
|
+
contactPostalCode: null,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
4
52
|
export async function listOffers(db, query) {
|
|
5
53
|
const conditions = [];
|
|
6
54
|
if (query.status)
|
|
@@ -47,18 +95,34 @@ export async function createOffer(db, data) {
|
|
|
47
95
|
}
|
|
48
96
|
export async function createOfferBundle(db, input) {
|
|
49
97
|
return db.transaction(async (tx) => {
|
|
50
|
-
const
|
|
98
|
+
const derivedContact = pickPrimaryContactSnapshot(input.offer, input.contactAssignments ?? []);
|
|
99
|
+
const offer = await createOffer(tx, {
|
|
100
|
+
...derivedContact,
|
|
101
|
+
...input.offer,
|
|
102
|
+
});
|
|
51
103
|
if (!offer)
|
|
52
104
|
return null;
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
105
|
+
const travelers = [];
|
|
106
|
+
const travelerIndexByInputIndex = new Map();
|
|
107
|
+
const staffInputByIndex = new Map();
|
|
108
|
+
(input.travelers ?? []).forEach((traveler, index) => {
|
|
109
|
+
if (isStaffParticipantType(traveler.participantType)) {
|
|
110
|
+
staffInputByIndex.set(index, traveler);
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
travelerIndexByInputIndex.set(index, travelers.length);
|
|
114
|
+
});
|
|
115
|
+
for (const [index, traveler] of (input.travelers ?? []).entries()) {
|
|
116
|
+
if (staffInputByIndex.has(index)) {
|
|
117
|
+
continue;
|
|
118
|
+
}
|
|
119
|
+
const created = await createOfferTraveler(tx, {
|
|
120
|
+
...traveler,
|
|
57
121
|
offerId: offer.id,
|
|
58
122
|
});
|
|
59
123
|
if (!created)
|
|
60
|
-
throw new Error("Failed to create offer
|
|
61
|
-
|
|
124
|
+
throw new Error("Failed to create offer traveler");
|
|
125
|
+
travelers.push(created);
|
|
62
126
|
}
|
|
63
127
|
const items = [];
|
|
64
128
|
for (const item of input.items) {
|
|
@@ -70,23 +134,117 @@ export async function createOfferBundle(db, input) {
|
|
|
70
134
|
throw new Error("Failed to create offer item");
|
|
71
135
|
items.push(created);
|
|
72
136
|
}
|
|
73
|
-
const
|
|
74
|
-
|
|
137
|
+
const itemTravelers = [];
|
|
138
|
+
const contactAssignments = [];
|
|
139
|
+
const staffAssignments = [];
|
|
140
|
+
const linkedStaffInputIndexes = new Set();
|
|
141
|
+
for (const link of input.itemTravelers ?? []) {
|
|
75
142
|
const item = items[link.itemIndex];
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
143
|
+
if (!item)
|
|
144
|
+
throw new Error("Invalid offer item traveler link");
|
|
145
|
+
const travelerIndex = travelerIndexByInputIndex.get(link.participantIndex);
|
|
146
|
+
if (travelerIndex !== undefined) {
|
|
147
|
+
const traveler = travelers[travelerIndex];
|
|
148
|
+
if (!traveler)
|
|
149
|
+
throw new Error("Invalid offer item traveler link");
|
|
150
|
+
const created = await createOfferItemTraveler(tx, {
|
|
151
|
+
offerItemId: item.id,
|
|
152
|
+
travelerId: traveler.id,
|
|
153
|
+
role: link.role,
|
|
154
|
+
isPrimary: link.isPrimary,
|
|
155
|
+
});
|
|
156
|
+
if (!created)
|
|
157
|
+
throw new Error("Failed to create offer item traveler");
|
|
158
|
+
itemTravelers.push(created);
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
const staffInput = staffInputByIndex.get(link.participantIndex);
|
|
162
|
+
if (!staffInput) {
|
|
163
|
+
throw new Error("Invalid offer item traveler link");
|
|
164
|
+
}
|
|
165
|
+
linkedStaffInputIndexes.add(link.participantIndex);
|
|
166
|
+
const [createdAssignment] = await tx
|
|
167
|
+
.insert(offerStaffAssignments)
|
|
168
|
+
.values({
|
|
169
|
+
offerId: offer.id,
|
|
80
170
|
offerItemId: item.id,
|
|
81
|
-
|
|
82
|
-
role: link.role,
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
171
|
+
personId: staffInput.personId ?? null,
|
|
172
|
+
role: toStaffAssignmentRole(link.role),
|
|
173
|
+
firstName: staffInput.firstName,
|
|
174
|
+
lastName: staffInput.lastName,
|
|
175
|
+
email: staffInput.email ?? null,
|
|
176
|
+
phone: staffInput.phone ?? null,
|
|
177
|
+
preferredLanguage: staffInput.preferredLanguage ?? null,
|
|
178
|
+
isPrimary: Boolean(link.isPrimary || staffInput.isPrimary),
|
|
179
|
+
notes: staffInput.notes ?? null,
|
|
180
|
+
metadata: {
|
|
181
|
+
sourceParticipantType: staffInput.participantType,
|
|
182
|
+
},
|
|
183
|
+
})
|
|
184
|
+
.returning();
|
|
185
|
+
if (!createdAssignment) {
|
|
186
|
+
throw new Error("Failed to create offer staff assignment");
|
|
187
|
+
}
|
|
188
|
+
staffAssignments.push(createdAssignment);
|
|
88
189
|
}
|
|
89
|
-
|
|
190
|
+
for (const contactInput of input.contactAssignments ?? []) {
|
|
191
|
+
const offerItemId = contactInput.itemIndex !== undefined && contactInput.itemIndex !== null
|
|
192
|
+
? (items[contactInput.itemIndex]?.id ?? null)
|
|
193
|
+
: null;
|
|
194
|
+
if (contactInput.itemIndex !== undefined && contactInput.itemIndex !== null && !offerItemId) {
|
|
195
|
+
throw new Error("Invalid offer contact assignment link");
|
|
196
|
+
}
|
|
197
|
+
const [createdAssignment] = await tx
|
|
198
|
+
.insert(offerContactAssignments)
|
|
199
|
+
.values({
|
|
200
|
+
offerId: offer.id,
|
|
201
|
+
offerItemId,
|
|
202
|
+
personId: contactInput.personId ?? null,
|
|
203
|
+
role: contactInput.role,
|
|
204
|
+
firstName: contactInput.firstName,
|
|
205
|
+
lastName: contactInput.lastName,
|
|
206
|
+
email: contactInput.email ?? null,
|
|
207
|
+
phone: contactInput.phone ?? null,
|
|
208
|
+
preferredLanguage: contactInput.preferredLanguage ?? null,
|
|
209
|
+
isPrimary: Boolean(contactInput.isPrimary),
|
|
210
|
+
notes: contactInput.notes ?? null,
|
|
211
|
+
metadata: contactInput.metadata ?? null,
|
|
212
|
+
})
|
|
213
|
+
.returning();
|
|
214
|
+
if (!createdAssignment) {
|
|
215
|
+
throw new Error("Failed to create offer contact assignment");
|
|
216
|
+
}
|
|
217
|
+
contactAssignments.push(createdAssignment);
|
|
218
|
+
}
|
|
219
|
+
for (const [inputIndex, staffInput] of staffInputByIndex.entries()) {
|
|
220
|
+
if (linkedStaffInputIndexes.has(inputIndex)) {
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
const [createdAssignment] = await tx
|
|
224
|
+
.insert(offerStaffAssignments)
|
|
225
|
+
.values({
|
|
226
|
+
offerId: offer.id,
|
|
227
|
+
offerItemId: null,
|
|
228
|
+
personId: staffInput.personId ?? null,
|
|
229
|
+
role: "service_assignee",
|
|
230
|
+
firstName: staffInput.firstName,
|
|
231
|
+
lastName: staffInput.lastName,
|
|
232
|
+
email: staffInput.email ?? null,
|
|
233
|
+
phone: staffInput.phone ?? null,
|
|
234
|
+
preferredLanguage: staffInput.preferredLanguage ?? null,
|
|
235
|
+
isPrimary: Boolean(staffInput.isPrimary),
|
|
236
|
+
notes: staffInput.notes ?? null,
|
|
237
|
+
metadata: {
|
|
238
|
+
sourceParticipantType: staffInput.participantType,
|
|
239
|
+
},
|
|
240
|
+
})
|
|
241
|
+
.returning();
|
|
242
|
+
if (!createdAssignment) {
|
|
243
|
+
throw new Error("Failed to create offer staff assignment");
|
|
244
|
+
}
|
|
245
|
+
staffAssignments.push(createdAssignment);
|
|
246
|
+
}
|
|
247
|
+
return { offer, travelers, contactAssignments, staffAssignments, items, itemTravelers };
|
|
90
248
|
});
|
|
91
249
|
}
|
|
92
250
|
export async function updateOffer(db, id, data) {
|
|
@@ -108,7 +266,7 @@ export async function deleteOffer(db, id) {
|
|
|
108
266
|
const [row] = await db.delete(offers).where(eq(offers.id, id)).returning({ id: offers.id });
|
|
109
267
|
return row ?? null;
|
|
110
268
|
}
|
|
111
|
-
export async function
|
|
269
|
+
export async function listOfferTravelers(db, query) {
|
|
112
270
|
const conditions = [];
|
|
113
271
|
if (query.offerId)
|
|
114
272
|
conditions.push(eq(offerParticipants.offerId, query.offerId));
|
|
@@ -122,25 +280,28 @@ export async function listOfferParticipants(db, query) {
|
|
|
122
280
|
.limit(query.limit)
|
|
123
281
|
.offset(query.offset)
|
|
124
282
|
.orderBy(asc(offerParticipants.createdAt))
|
|
125
|
-
.then((items) => items.map(
|
|
283
|
+
.then((items) => items.map(toOfferTravelerResponse));
|
|
126
284
|
return paginate(rows, db.select({ count: sql `count(*)::int` }).from(offerParticipants).where(where), query.limit, query.offset);
|
|
127
285
|
}
|
|
128
|
-
export
|
|
286
|
+
export const listOfferParticipants = listOfferTravelers;
|
|
287
|
+
export async function getOfferTravelerById(db, id) {
|
|
129
288
|
const [row] = await db
|
|
130
289
|
.select()
|
|
131
290
|
.from(offerParticipants)
|
|
132
291
|
.where(eq(offerParticipants.id, id))
|
|
133
292
|
.limit(1);
|
|
134
|
-
return row ?
|
|
293
|
+
return row ? toOfferTravelerResponse(row) : null;
|
|
135
294
|
}
|
|
136
|
-
export
|
|
295
|
+
export const getOfferParticipantById = getOfferTravelerById;
|
|
296
|
+
export async function createOfferTraveler(db, data) {
|
|
137
297
|
const { dateOfBirth, nationality, ...rest } = data;
|
|
138
298
|
void dateOfBirth;
|
|
139
299
|
void nationality;
|
|
140
300
|
const [row] = await db.insert(offerParticipants).values(rest).returning();
|
|
141
|
-
return row ?
|
|
301
|
+
return row ? toOfferTravelerResponse(row) : null;
|
|
142
302
|
}
|
|
143
|
-
export
|
|
303
|
+
export const createOfferParticipant = createOfferTraveler;
|
|
304
|
+
export async function updateOfferTraveler(db, id, data) {
|
|
144
305
|
const { dateOfBirth, nationality, ...rest } = data;
|
|
145
306
|
void dateOfBirth;
|
|
146
307
|
void nationality;
|
|
@@ -149,15 +310,111 @@ export async function updateOfferParticipant(db, id, data) {
|
|
|
149
310
|
.set({ ...rest, updatedAt: new Date() })
|
|
150
311
|
.where(eq(offerParticipants.id, id))
|
|
151
312
|
.returning();
|
|
152
|
-
return row ?
|
|
313
|
+
return row ? toOfferTravelerResponse(row) : null;
|
|
153
314
|
}
|
|
154
|
-
export
|
|
315
|
+
export const updateOfferParticipant = updateOfferTraveler;
|
|
316
|
+
export async function deleteOfferTraveler(db, id) {
|
|
155
317
|
const [row] = await db
|
|
156
318
|
.delete(offerParticipants)
|
|
157
319
|
.where(eq(offerParticipants.id, id))
|
|
158
320
|
.returning({ id: offerParticipants.id });
|
|
159
321
|
return row ?? null;
|
|
160
322
|
}
|
|
323
|
+
export const deleteOfferParticipant = deleteOfferTraveler;
|
|
324
|
+
export async function listOfferContactAssignments(db, query) {
|
|
325
|
+
const conditions = [];
|
|
326
|
+
if (query.offerId)
|
|
327
|
+
conditions.push(eq(offerContactAssignments.offerId, query.offerId));
|
|
328
|
+
if (query.offerItemId)
|
|
329
|
+
conditions.push(eq(offerContactAssignments.offerItemId, query.offerItemId));
|
|
330
|
+
if (query.personId)
|
|
331
|
+
conditions.push(eq(offerContactAssignments.personId, query.personId));
|
|
332
|
+
if (query.role)
|
|
333
|
+
conditions.push(eq(offerContactAssignments.role, query.role));
|
|
334
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
335
|
+
return paginate(db
|
|
336
|
+
.select()
|
|
337
|
+
.from(offerContactAssignments)
|
|
338
|
+
.where(where)
|
|
339
|
+
.limit(query.limit)
|
|
340
|
+
.offset(query.offset)
|
|
341
|
+
.orderBy(asc(offerContactAssignments.createdAt))
|
|
342
|
+
.then((items) => items.map(toOfferContactAssignmentResponse)), db.select({ count: sql `count(*)::int` }).from(offerContactAssignments).where(where), query.limit, query.offset);
|
|
343
|
+
}
|
|
344
|
+
export async function getOfferContactAssignmentById(db, id) {
|
|
345
|
+
const [row] = await db
|
|
346
|
+
.select()
|
|
347
|
+
.from(offerContactAssignments)
|
|
348
|
+
.where(eq(offerContactAssignments.id, id))
|
|
349
|
+
.limit(1);
|
|
350
|
+
return row ? toOfferContactAssignmentResponse(row) : null;
|
|
351
|
+
}
|
|
352
|
+
export async function createOfferContactAssignment(db, data) {
|
|
353
|
+
const [row] = await db.insert(offerContactAssignments).values(data).returning();
|
|
354
|
+
return row ? toOfferContactAssignmentResponse(row) : null;
|
|
355
|
+
}
|
|
356
|
+
export async function updateOfferContactAssignment(db, id, data) {
|
|
357
|
+
const [row] = await db
|
|
358
|
+
.update(offerContactAssignments)
|
|
359
|
+
.set({ ...data, updatedAt: new Date() })
|
|
360
|
+
.where(eq(offerContactAssignments.id, id))
|
|
361
|
+
.returning();
|
|
362
|
+
return row ? toOfferContactAssignmentResponse(row) : null;
|
|
363
|
+
}
|
|
364
|
+
export async function deleteOfferContactAssignment(db, id) {
|
|
365
|
+
const [row] = await db
|
|
366
|
+
.delete(offerContactAssignments)
|
|
367
|
+
.where(eq(offerContactAssignments.id, id))
|
|
368
|
+
.returning({ id: offerContactAssignments.id });
|
|
369
|
+
return row ?? null;
|
|
370
|
+
}
|
|
371
|
+
export async function listOfferStaffAssignments(db, query) {
|
|
372
|
+
const conditions = [];
|
|
373
|
+
if (query.offerId)
|
|
374
|
+
conditions.push(eq(offerStaffAssignments.offerId, query.offerId));
|
|
375
|
+
if (query.offerItemId)
|
|
376
|
+
conditions.push(eq(offerStaffAssignments.offerItemId, query.offerItemId));
|
|
377
|
+
if (query.personId)
|
|
378
|
+
conditions.push(eq(offerStaffAssignments.personId, query.personId));
|
|
379
|
+
if (query.role)
|
|
380
|
+
conditions.push(eq(offerStaffAssignments.role, query.role));
|
|
381
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
382
|
+
return paginate(db
|
|
383
|
+
.select()
|
|
384
|
+
.from(offerStaffAssignments)
|
|
385
|
+
.where(where)
|
|
386
|
+
.limit(query.limit)
|
|
387
|
+
.offset(query.offset)
|
|
388
|
+
.orderBy(asc(offerStaffAssignments.createdAt))
|
|
389
|
+
.then((items) => items.map(toOfferStaffAssignmentResponse)), db.select({ count: sql `count(*)::int` }).from(offerStaffAssignments).where(where), query.limit, query.offset);
|
|
390
|
+
}
|
|
391
|
+
export async function getOfferStaffAssignmentById(db, id) {
|
|
392
|
+
const [row] = await db
|
|
393
|
+
.select()
|
|
394
|
+
.from(offerStaffAssignments)
|
|
395
|
+
.where(eq(offerStaffAssignments.id, id))
|
|
396
|
+
.limit(1);
|
|
397
|
+
return row ? toOfferStaffAssignmentResponse(row) : null;
|
|
398
|
+
}
|
|
399
|
+
export async function createOfferStaffAssignment(db, data) {
|
|
400
|
+
const [row] = await db.insert(offerStaffAssignments).values(data).returning();
|
|
401
|
+
return row ? toOfferStaffAssignmentResponse(row) : null;
|
|
402
|
+
}
|
|
403
|
+
export async function updateOfferStaffAssignment(db, id, data) {
|
|
404
|
+
const [row] = await db
|
|
405
|
+
.update(offerStaffAssignments)
|
|
406
|
+
.set({ ...data, updatedAt: new Date() })
|
|
407
|
+
.where(eq(offerStaffAssignments.id, id))
|
|
408
|
+
.returning();
|
|
409
|
+
return row ? toOfferStaffAssignmentResponse(row) : null;
|
|
410
|
+
}
|
|
411
|
+
export async function deleteOfferStaffAssignment(db, id) {
|
|
412
|
+
const [row] = await db
|
|
413
|
+
.delete(offerStaffAssignments)
|
|
414
|
+
.where(eq(offerStaffAssignments.id, id))
|
|
415
|
+
.returning({ id: offerStaffAssignments.id });
|
|
416
|
+
return row ?? null;
|
|
417
|
+
}
|
|
161
418
|
export async function listOfferItems(db, query) {
|
|
162
419
|
const conditions = [];
|
|
163
420
|
if (query.offerId)
|
|
@@ -218,12 +475,12 @@ export async function deleteOfferItem(db, id) {
|
|
|
218
475
|
.returning({ id: offerItems.id });
|
|
219
476
|
return row ?? null;
|
|
220
477
|
}
|
|
221
|
-
export async function
|
|
478
|
+
export async function listOfferItemTravelers(db, query) {
|
|
222
479
|
const conditions = [];
|
|
223
480
|
if (query.offerItemId)
|
|
224
481
|
conditions.push(eq(offerItemParticipants.offerItemId, query.offerItemId));
|
|
225
|
-
if (query.
|
|
226
|
-
conditions.push(eq(offerItemParticipants.
|
|
482
|
+
if (query.travelerId)
|
|
483
|
+
conditions.push(eq(offerItemParticipants.travelerId, query.travelerId));
|
|
227
484
|
const where = conditions.length ? and(...conditions) : undefined;
|
|
228
485
|
return paginate(db
|
|
229
486
|
.select()
|
|
@@ -231,32 +488,38 @@ export async function listOfferItemParticipants(db, query) {
|
|
|
231
488
|
.where(where)
|
|
232
489
|
.limit(query.limit)
|
|
233
490
|
.offset(query.offset)
|
|
234
|
-
.orderBy(asc(offerItemParticipants.createdAt))
|
|
491
|
+
.orderBy(asc(offerItemParticipants.createdAt))
|
|
492
|
+
.then((items) => items.map(toOfferItemTravelerResponse)), db.select({ count: sql `count(*)::int` }).from(offerItemParticipants).where(where), query.limit, query.offset);
|
|
235
493
|
}
|
|
236
|
-
export
|
|
494
|
+
export const listOfferItemParticipants = listOfferItemTravelers;
|
|
495
|
+
export async function getOfferItemTravelerById(db, id) {
|
|
237
496
|
const [row] = await db
|
|
238
497
|
.select()
|
|
239
498
|
.from(offerItemParticipants)
|
|
240
499
|
.where(eq(offerItemParticipants.id, id))
|
|
241
500
|
.limit(1);
|
|
242
|
-
return row
|
|
501
|
+
return row ? toOfferItemTravelerResponse(row) : null;
|
|
243
502
|
}
|
|
244
|
-
export
|
|
503
|
+
export const getOfferItemParticipantById = getOfferItemTravelerById;
|
|
504
|
+
export async function createOfferItemTraveler(db, data) {
|
|
245
505
|
const [row] = await db.insert(offerItemParticipants).values(data).returning();
|
|
246
|
-
return row
|
|
506
|
+
return row ? toOfferItemTravelerResponse(row) : null;
|
|
247
507
|
}
|
|
248
|
-
export
|
|
508
|
+
export const createOfferItemParticipant = createOfferItemTraveler;
|
|
509
|
+
export async function updateOfferItemTraveler(db, id, data) {
|
|
249
510
|
const [row] = await db
|
|
250
511
|
.update(offerItemParticipants)
|
|
251
512
|
.set(data)
|
|
252
513
|
.where(eq(offerItemParticipants.id, id))
|
|
253
514
|
.returning();
|
|
254
|
-
return row
|
|
515
|
+
return row ? toOfferItemTravelerResponse(row) : null;
|
|
255
516
|
}
|
|
256
|
-
export
|
|
517
|
+
export const updateOfferItemParticipant = updateOfferItemTraveler;
|
|
518
|
+
export async function deleteOfferItemTraveler(db, id) {
|
|
257
519
|
const [row] = await db
|
|
258
520
|
.delete(offerItemParticipants)
|
|
259
521
|
.where(eq(offerItemParticipants.id, id))
|
|
260
522
|
.returning({ id: offerItemParticipants.id });
|
|
261
523
|
return row ?? null;
|
|
262
524
|
}
|
|
525
|
+
export const deleteOfferItemParticipant = deleteOfferItemTraveler;
|