@voyantjs/transactions 0.2.0 → 0.3.0
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/routes-offers.d.ts +885 -0
- package/dist/routes-offers.d.ts.map +1 -0
- package/dist/routes-offers.js +161 -0
- package/dist/routes-orders.d.ts +1056 -0
- package/dist/routes-orders.d.ts.map +1 -0
- package/dist/routes-orders.js +180 -0
- package/dist/routes-shared.d.ts +103 -0
- package/dist/routes-shared.d.ts.map +1 -0
- package/dist/routes-shared.js +97 -0
- package/dist/routes.d.ts +3 -1979
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +5 -604
- package/dist/schema-audit.d.ts +216 -0
- package/dist/schema-audit.d.ts.map +1 -0
- package/dist/schema-audit.js +22 -0
- package/dist/schema-offers.d.ts +1301 -0
- package/dist/schema-offers.d.ts.map +1 -0
- package/dist/schema-offers.js +120 -0
- package/dist/schema-orders.d.ts +1582 -0
- package/dist/schema-orders.d.ts.map +1 -0
- package/dist/schema-orders.js +149 -0
- package/dist/schema-relations.d.ts +42 -0
- package/dist/schema-relations.d.ts.map +1 -0
- package/dist/schema-relations.js +56 -0
- package/dist/schema-shared.d.ts +12 -0
- package/dist/schema-shared.d.ts.map +1 -0
- package/dist/schema-shared.js +84 -0
- package/dist/schema.d.ts +5 -3148
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +5 -420
- package/dist/service-offers.d.ts +447 -0
- package/dist/service-offers.d.ts.map +1 -0
- package/dist/service-offers.js +262 -0
- package/dist/service-orders.d.ts +443 -0
- package/dist/service-orders.d.ts.map +1 -0
- package/dist/service-orders.js +278 -0
- package/dist/service-shared.d.ts +86 -0
- package/dist/service-shared.d.ts.map +1 -0
- package/dist/service-shared.js +49 -0
- package/dist/service.d.ts +48 -927
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +48 -595
- package/package.json +5 -5
package/dist/service.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,eAAe,EACf,0BAA0B,EAC1B,sBAAsB,EACtB,WAAW,EACX,eAAe,EACf,0BAA0B,EAC1B,sBAAsB,EACtB,YAAY,EACZ,gBAAgB,EAChB,2BAA2B,EAC3B,uBAAuB,EACvB,yBAAyB,EACzB,cAAc,EACd,qBAAqB,EACrB,UAAU,EACV,WAAW,EACX,eAAe,EACf,0BAA0B,EAC1B,sBAAsB,EACvB,MAAM,qBAAqB,CAAA;AAC5B,OAAO,EACL,WAAW,EACX,eAAe,EACf,0BAA0B,EAC1B,sBAAsB,EACtB,eAAe,EACf,WAAW,EACX,eAAe,EACf,0BAA0B,EAC1B,sBAAsB,EACtB,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,2BAA2B,EAC3B,uBAAuB,EACvB,gBAAgB,EAChB,yBAAyB,EACzB,cAAc,EACd,qBAAqB,EACrB,UAAU,EACV,cAAc,EACd,WAAW,EACX,eAAe,EACf,0BAA0B,EAC1B,sBAAsB,EACtB,eAAe,EAChB,MAAM,qBAAqB,CAAA;AAE5B,eAAO,MAAM,mBAAmB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+C/B,CAAA"}
|
package/dist/service.js
CHANGED
|
@@ -1,597 +1,50 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
async function paginate(rowsQuery, countQuery, limit, offset) {
|
|
4
|
-
const [data, countResult] = await Promise.all([rowsQuery, countQuery]);
|
|
5
|
-
return { data, total: countResult[0]?.count ?? 0, limit, offset };
|
|
6
|
-
}
|
|
7
|
-
function normalizeTimestamp(value) {
|
|
8
|
-
if (value === undefined || value === "")
|
|
9
|
-
return undefined;
|
|
10
|
-
if (value === null)
|
|
11
|
-
return null;
|
|
12
|
-
return new Date(value);
|
|
13
|
-
}
|
|
14
|
-
function toOfferParticipantResponse(row) {
|
|
15
|
-
return {
|
|
16
|
-
id: row.id,
|
|
17
|
-
offerId: row.offerId,
|
|
18
|
-
personId: row.personId,
|
|
19
|
-
participantType: row.participantType,
|
|
20
|
-
travelerCategory: row.travelerCategory,
|
|
21
|
-
firstName: row.firstName,
|
|
22
|
-
lastName: row.lastName,
|
|
23
|
-
email: row.email,
|
|
24
|
-
phone: row.phone,
|
|
25
|
-
preferredLanguage: row.preferredLanguage,
|
|
26
|
-
isPrimary: row.isPrimary,
|
|
27
|
-
notes: row.notes,
|
|
28
|
-
hasTravelIdentity: Boolean(row.identityEncrypted),
|
|
29
|
-
createdAt: row.createdAt,
|
|
30
|
-
updatedAt: row.updatedAt,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
function toOrderParticipantResponse(row) {
|
|
34
|
-
return {
|
|
35
|
-
id: row.id,
|
|
36
|
-
orderId: row.orderId,
|
|
37
|
-
personId: row.personId,
|
|
38
|
-
participantType: row.participantType,
|
|
39
|
-
travelerCategory: row.travelerCategory,
|
|
40
|
-
firstName: row.firstName,
|
|
41
|
-
lastName: row.lastName,
|
|
42
|
-
email: row.email,
|
|
43
|
-
phone: row.phone,
|
|
44
|
-
preferredLanguage: row.preferredLanguage,
|
|
45
|
-
isPrimary: row.isPrimary,
|
|
46
|
-
notes: row.notes,
|
|
47
|
-
hasTravelIdentity: Boolean(row.identityEncrypted),
|
|
48
|
-
createdAt: row.createdAt,
|
|
49
|
-
updatedAt: row.updatedAt,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
1
|
+
import { createOffer, createOfferBundle, createOfferItem, createOfferItemParticipant, createOfferParticipant, deleteOffer, deleteOfferItem, deleteOfferItemParticipant, deleteOfferParticipant, getOfferById, getOfferItemById, getOfferItemParticipantById, getOfferParticipantById, listOfferItemParticipants, listOfferItems, listOfferParticipants, listOffers, updateOffer, updateOfferItem, updateOfferItemParticipant, updateOfferParticipant, } from "./service-offers.js";
|
|
2
|
+
import { createOrder, createOrderItem, createOrderItemParticipant, createOrderParticipant, createOrderTerm, deleteOrder, deleteOrderItem, deleteOrderItemParticipant, deleteOrderParticipant, deleteOrderTerm, getOrderById, getOrderItemById, getOrderItemParticipantById, getOrderParticipantById, getOrderTermById, listOrderItemParticipants, listOrderItems, listOrderParticipants, listOrders, listOrderTerms, updateOrder, updateOrderItem, updateOrderItemParticipant, updateOrderParticipant, updateOrderTerm, } from "./service-orders.js";
|
|
52
3
|
export const transactionsService = {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
const offer = await transactionsService.createOffer(tx, input.offer);
|
|
100
|
-
if (!offer) {
|
|
101
|
-
return null;
|
|
102
|
-
}
|
|
103
|
-
const participants = [];
|
|
104
|
-
for (const participant of input.participants ?? []) {
|
|
105
|
-
const created = await transactionsService.createOfferParticipant(tx, {
|
|
106
|
-
...participant,
|
|
107
|
-
offerId: offer.id,
|
|
108
|
-
});
|
|
109
|
-
if (!created) {
|
|
110
|
-
throw new Error("Failed to create offer participant");
|
|
111
|
-
}
|
|
112
|
-
participants.push(created);
|
|
113
|
-
}
|
|
114
|
-
const items = [];
|
|
115
|
-
for (const item of input.items) {
|
|
116
|
-
const created = await transactionsService.createOfferItem(tx, {
|
|
117
|
-
...item,
|
|
118
|
-
offerId: offer.id,
|
|
119
|
-
});
|
|
120
|
-
if (!created) {
|
|
121
|
-
throw new Error("Failed to create offer item");
|
|
122
|
-
}
|
|
123
|
-
items.push(created);
|
|
124
|
-
}
|
|
125
|
-
const itemParticipants = [];
|
|
126
|
-
for (const link of input.itemParticipants ?? []) {
|
|
127
|
-
const item = items[link.itemIndex];
|
|
128
|
-
const participant = participants[link.participantIndex];
|
|
129
|
-
if (!item || !participant) {
|
|
130
|
-
throw new Error("Invalid offer item participant link");
|
|
131
|
-
}
|
|
132
|
-
const created = await transactionsService.createOfferItemParticipant(tx, {
|
|
133
|
-
offerItemId: item.id,
|
|
134
|
-
participantId: participant.id,
|
|
135
|
-
role: link.role,
|
|
136
|
-
isPrimary: link.isPrimary,
|
|
137
|
-
});
|
|
138
|
-
if (!created) {
|
|
139
|
-
throw new Error("Failed to create offer item participant");
|
|
140
|
-
}
|
|
141
|
-
itemParticipants.push(created);
|
|
142
|
-
}
|
|
143
|
-
return {
|
|
144
|
-
offer,
|
|
145
|
-
participants,
|
|
146
|
-
items,
|
|
147
|
-
itemParticipants,
|
|
148
|
-
};
|
|
149
|
-
});
|
|
150
|
-
},
|
|
151
|
-
async updateOffer(db, id, data) {
|
|
152
|
-
const { sentAt, acceptedAt, convertedAt, ...rest } = data;
|
|
153
|
-
const [row] = await db
|
|
154
|
-
.update(offers)
|
|
155
|
-
.set({
|
|
156
|
-
...rest,
|
|
157
|
-
sentAt: normalizeTimestamp(sentAt),
|
|
158
|
-
acceptedAt: normalizeTimestamp(acceptedAt),
|
|
159
|
-
convertedAt: normalizeTimestamp(convertedAt),
|
|
160
|
-
updatedAt: new Date(),
|
|
161
|
-
})
|
|
162
|
-
.where(eq(offers.id, id))
|
|
163
|
-
.returning();
|
|
164
|
-
return row ?? null;
|
|
165
|
-
},
|
|
166
|
-
async deleteOffer(db, id) {
|
|
167
|
-
const [row] = await db.delete(offers).where(eq(offers.id, id)).returning({ id: offers.id });
|
|
168
|
-
return row ?? null;
|
|
169
|
-
},
|
|
170
|
-
async listOfferParticipants(db, query) {
|
|
171
|
-
const conditions = [];
|
|
172
|
-
if (query.offerId)
|
|
173
|
-
conditions.push(eq(offerParticipants.offerId, query.offerId));
|
|
174
|
-
if (query.personId)
|
|
175
|
-
conditions.push(eq(offerParticipants.personId, query.personId));
|
|
176
|
-
const where = conditions.length ? and(...conditions) : undefined;
|
|
177
|
-
const rows = db
|
|
178
|
-
.select()
|
|
179
|
-
.from(offerParticipants)
|
|
180
|
-
.where(where)
|
|
181
|
-
.limit(query.limit)
|
|
182
|
-
.offset(query.offset)
|
|
183
|
-
.orderBy(asc(offerParticipants.createdAt))
|
|
184
|
-
.then((items) => items.map(toOfferParticipantResponse));
|
|
185
|
-
return paginate(rows, db.select({ count: sql `count(*)::int` }).from(offerParticipants).where(where), query.limit, query.offset);
|
|
186
|
-
},
|
|
187
|
-
async getOfferParticipantById(db, id) {
|
|
188
|
-
const [row] = await db
|
|
189
|
-
.select()
|
|
190
|
-
.from(offerParticipants)
|
|
191
|
-
.where(eq(offerParticipants.id, id))
|
|
192
|
-
.limit(1);
|
|
193
|
-
return row ? toOfferParticipantResponse(row) : null;
|
|
194
|
-
},
|
|
195
|
-
async createOfferParticipant(db, data) {
|
|
196
|
-
const { dateOfBirth, nationality, ...rest } = data;
|
|
197
|
-
void dateOfBirth;
|
|
198
|
-
void nationality;
|
|
199
|
-
const [row] = await db.insert(offerParticipants).values(rest).returning();
|
|
200
|
-
return row ? toOfferParticipantResponse(row) : null;
|
|
201
|
-
},
|
|
202
|
-
async updateOfferParticipant(db, id, data) {
|
|
203
|
-
const { dateOfBirth, nationality, ...rest } = data;
|
|
204
|
-
void dateOfBirth;
|
|
205
|
-
void nationality;
|
|
206
|
-
const [row] = await db
|
|
207
|
-
.update(offerParticipants)
|
|
208
|
-
.set({ ...rest, updatedAt: new Date() })
|
|
209
|
-
.where(eq(offerParticipants.id, id))
|
|
210
|
-
.returning();
|
|
211
|
-
return row ? toOfferParticipantResponse(row) : null;
|
|
212
|
-
},
|
|
213
|
-
async deleteOfferParticipant(db, id) {
|
|
214
|
-
const [row] = await db
|
|
215
|
-
.delete(offerParticipants)
|
|
216
|
-
.where(eq(offerParticipants.id, id))
|
|
217
|
-
.returning({ id: offerParticipants.id });
|
|
218
|
-
return row ?? null;
|
|
219
|
-
},
|
|
220
|
-
async listOfferItems(db, query) {
|
|
221
|
-
const conditions = [];
|
|
222
|
-
if (query.offerId)
|
|
223
|
-
conditions.push(eq(offerItems.offerId, query.offerId));
|
|
224
|
-
if (query.productId)
|
|
225
|
-
conditions.push(eq(offerItems.productId, query.productId));
|
|
226
|
-
if (query.optionId)
|
|
227
|
-
conditions.push(eq(offerItems.optionId, query.optionId));
|
|
228
|
-
if (query.unitId)
|
|
229
|
-
conditions.push(eq(offerItems.unitId, query.unitId));
|
|
230
|
-
if (query.slotId)
|
|
231
|
-
conditions.push(eq(offerItems.slotId, query.slotId));
|
|
232
|
-
if (query.status)
|
|
233
|
-
conditions.push(eq(offerItems.status, query.status));
|
|
234
|
-
const where = conditions.length ? and(...conditions) : undefined;
|
|
235
|
-
return paginate(db
|
|
236
|
-
.select()
|
|
237
|
-
.from(offerItems)
|
|
238
|
-
.where(where)
|
|
239
|
-
.limit(query.limit)
|
|
240
|
-
.offset(query.offset)
|
|
241
|
-
.orderBy(asc(offerItems.createdAt)), db.select({ count: sql `count(*)::int` }).from(offerItems).where(where), query.limit, query.offset);
|
|
242
|
-
},
|
|
243
|
-
async getOfferItemById(db, id) {
|
|
244
|
-
const [row] = await db.select().from(offerItems).where(eq(offerItems.id, id)).limit(1);
|
|
245
|
-
return row ?? null;
|
|
246
|
-
},
|
|
247
|
-
async createOfferItem(db, data) {
|
|
248
|
-
const { startsAt, endsAt, ...rest } = data;
|
|
249
|
-
const [row] = await db
|
|
250
|
-
.insert(offerItems)
|
|
251
|
-
.values({
|
|
252
|
-
...rest,
|
|
253
|
-
startsAt: normalizeTimestamp(startsAt),
|
|
254
|
-
endsAt: normalizeTimestamp(endsAt),
|
|
255
|
-
})
|
|
256
|
-
.returning();
|
|
257
|
-
return row ?? null;
|
|
258
|
-
},
|
|
259
|
-
async updateOfferItem(db, id, data) {
|
|
260
|
-
const { startsAt, endsAt, ...rest } = data;
|
|
261
|
-
const [row] = await db
|
|
262
|
-
.update(offerItems)
|
|
263
|
-
.set({
|
|
264
|
-
...rest,
|
|
265
|
-
startsAt: normalizeTimestamp(startsAt),
|
|
266
|
-
endsAt: normalizeTimestamp(endsAt),
|
|
267
|
-
updatedAt: new Date(),
|
|
268
|
-
})
|
|
269
|
-
.where(eq(offerItems.id, id))
|
|
270
|
-
.returning();
|
|
271
|
-
return row ?? null;
|
|
272
|
-
},
|
|
273
|
-
async deleteOfferItem(db, id) {
|
|
274
|
-
const [row] = await db
|
|
275
|
-
.delete(offerItems)
|
|
276
|
-
.where(eq(offerItems.id, id))
|
|
277
|
-
.returning({ id: offerItems.id });
|
|
278
|
-
return row ?? null;
|
|
279
|
-
},
|
|
280
|
-
async listOfferItemParticipants(db, query) {
|
|
281
|
-
const conditions = [];
|
|
282
|
-
if (query.offerItemId)
|
|
283
|
-
conditions.push(eq(offerItemParticipants.offerItemId, query.offerItemId));
|
|
284
|
-
if (query.participantId)
|
|
285
|
-
conditions.push(eq(offerItemParticipants.participantId, query.participantId));
|
|
286
|
-
const where = conditions.length ? and(...conditions) : undefined;
|
|
287
|
-
return paginate(db
|
|
288
|
-
.select()
|
|
289
|
-
.from(offerItemParticipants)
|
|
290
|
-
.where(where)
|
|
291
|
-
.limit(query.limit)
|
|
292
|
-
.offset(query.offset)
|
|
293
|
-
.orderBy(asc(offerItemParticipants.createdAt)), db.select({ count: sql `count(*)::int` }).from(offerItemParticipants).where(where), query.limit, query.offset);
|
|
294
|
-
},
|
|
295
|
-
async getOfferItemParticipantById(db, id) {
|
|
296
|
-
const [row] = await db
|
|
297
|
-
.select()
|
|
298
|
-
.from(offerItemParticipants)
|
|
299
|
-
.where(eq(offerItemParticipants.id, id))
|
|
300
|
-
.limit(1);
|
|
301
|
-
return row ?? null;
|
|
302
|
-
},
|
|
303
|
-
async createOfferItemParticipant(db, data) {
|
|
304
|
-
const [row] = await db.insert(offerItemParticipants).values(data).returning();
|
|
305
|
-
return row ?? null;
|
|
306
|
-
},
|
|
307
|
-
async updateOfferItemParticipant(db, id, data) {
|
|
308
|
-
const [row] = await db
|
|
309
|
-
.update(offerItemParticipants)
|
|
310
|
-
.set(data)
|
|
311
|
-
.where(eq(offerItemParticipants.id, id))
|
|
312
|
-
.returning();
|
|
313
|
-
return row ?? null;
|
|
314
|
-
},
|
|
315
|
-
async deleteOfferItemParticipant(db, id) {
|
|
316
|
-
const [row] = await db
|
|
317
|
-
.delete(offerItemParticipants)
|
|
318
|
-
.where(eq(offerItemParticipants.id, id))
|
|
319
|
-
.returning({ id: offerItemParticipants.id });
|
|
320
|
-
return row ?? null;
|
|
321
|
-
},
|
|
322
|
-
async listOrders(db, query) {
|
|
323
|
-
const conditions = [];
|
|
324
|
-
if (query.status)
|
|
325
|
-
conditions.push(eq(orders.status, query.status));
|
|
326
|
-
if (query.offerId)
|
|
327
|
-
conditions.push(eq(orders.offerId, query.offerId));
|
|
328
|
-
if (query.opportunityId)
|
|
329
|
-
conditions.push(eq(orders.opportunityId, query.opportunityId));
|
|
330
|
-
if (query.quoteId)
|
|
331
|
-
conditions.push(eq(orders.quoteId, query.quoteId));
|
|
332
|
-
if (query.personId)
|
|
333
|
-
conditions.push(eq(orders.personId, query.personId));
|
|
334
|
-
if (query.organizationId)
|
|
335
|
-
conditions.push(eq(orders.organizationId, query.organizationId));
|
|
336
|
-
if (query.marketId)
|
|
337
|
-
conditions.push(eq(orders.marketId, query.marketId));
|
|
338
|
-
if (query.search) {
|
|
339
|
-
const term = `%${query.search}%`;
|
|
340
|
-
conditions.push(or(ilike(orders.orderNumber, term), ilike(orders.title, term)));
|
|
341
|
-
}
|
|
342
|
-
const where = conditions.length ? and(...conditions) : undefined;
|
|
343
|
-
return paginate(db
|
|
344
|
-
.select()
|
|
345
|
-
.from(orders)
|
|
346
|
-
.where(where)
|
|
347
|
-
.limit(query.limit)
|
|
348
|
-
.offset(query.offset)
|
|
349
|
-
.orderBy(desc(orders.createdAt)), db.select({ count: sql `count(*)::int` }).from(orders).where(where), query.limit, query.offset);
|
|
350
|
-
},
|
|
351
|
-
async getOrderById(db, id) {
|
|
352
|
-
const [row] = await db.select().from(orders).where(eq(orders.id, id)).limit(1);
|
|
353
|
-
return row ?? null;
|
|
354
|
-
},
|
|
355
|
-
async createOrder(db, data) {
|
|
356
|
-
const { orderedAt, confirmedAt, cancelledAt, expiresAt, ...rest } = data;
|
|
357
|
-
const [row] = await db
|
|
358
|
-
.insert(orders)
|
|
359
|
-
.values({
|
|
360
|
-
...rest,
|
|
361
|
-
orderedAt: normalizeTimestamp(orderedAt),
|
|
362
|
-
confirmedAt: normalizeTimestamp(confirmedAt),
|
|
363
|
-
cancelledAt: normalizeTimestamp(cancelledAt),
|
|
364
|
-
expiresAt: normalizeTimestamp(expiresAt),
|
|
365
|
-
})
|
|
366
|
-
.returning();
|
|
367
|
-
return row ?? null;
|
|
368
|
-
},
|
|
369
|
-
async updateOrder(db, id, data) {
|
|
370
|
-
const { orderedAt, confirmedAt, cancelledAt, expiresAt, ...rest } = data;
|
|
371
|
-
const [row] = await db
|
|
372
|
-
.update(orders)
|
|
373
|
-
.set({
|
|
374
|
-
...rest,
|
|
375
|
-
orderedAt: normalizeTimestamp(orderedAt),
|
|
376
|
-
confirmedAt: normalizeTimestamp(confirmedAt),
|
|
377
|
-
cancelledAt: normalizeTimestamp(cancelledAt),
|
|
378
|
-
expiresAt: normalizeTimestamp(expiresAt),
|
|
379
|
-
updatedAt: new Date(),
|
|
380
|
-
})
|
|
381
|
-
.where(eq(orders.id, id))
|
|
382
|
-
.returning();
|
|
383
|
-
return row ?? null;
|
|
384
|
-
},
|
|
385
|
-
async deleteOrder(db, id) {
|
|
386
|
-
const [row] = await db.delete(orders).where(eq(orders.id, id)).returning({ id: orders.id });
|
|
387
|
-
return row ?? null;
|
|
388
|
-
},
|
|
389
|
-
async listOrderParticipants(db, query) {
|
|
390
|
-
const conditions = [];
|
|
391
|
-
if (query.orderId)
|
|
392
|
-
conditions.push(eq(orderParticipants.orderId, query.orderId));
|
|
393
|
-
if (query.personId)
|
|
394
|
-
conditions.push(eq(orderParticipants.personId, query.personId));
|
|
395
|
-
const where = conditions.length ? and(...conditions) : undefined;
|
|
396
|
-
const rows = db
|
|
397
|
-
.select()
|
|
398
|
-
.from(orderParticipants)
|
|
399
|
-
.where(where)
|
|
400
|
-
.limit(query.limit)
|
|
401
|
-
.offset(query.offset)
|
|
402
|
-
.orderBy(asc(orderParticipants.createdAt))
|
|
403
|
-
.then((items) => items.map(toOrderParticipantResponse));
|
|
404
|
-
return paginate(rows, db.select({ count: sql `count(*)::int` }).from(orderParticipants).where(where), query.limit, query.offset);
|
|
405
|
-
},
|
|
406
|
-
async getOrderParticipantById(db, id) {
|
|
407
|
-
const [row] = await db
|
|
408
|
-
.select()
|
|
409
|
-
.from(orderParticipants)
|
|
410
|
-
.where(eq(orderParticipants.id, id))
|
|
411
|
-
.limit(1);
|
|
412
|
-
return row ? toOrderParticipantResponse(row) : null;
|
|
413
|
-
},
|
|
414
|
-
async createOrderParticipant(db, data) {
|
|
415
|
-
const { dateOfBirth, nationality, ...rest } = data;
|
|
416
|
-
void dateOfBirth;
|
|
417
|
-
void nationality;
|
|
418
|
-
const [row] = await db.insert(orderParticipants).values(rest).returning();
|
|
419
|
-
return row ? toOrderParticipantResponse(row) : null;
|
|
420
|
-
},
|
|
421
|
-
async updateOrderParticipant(db, id, data) {
|
|
422
|
-
const { dateOfBirth, nationality, ...rest } = data;
|
|
423
|
-
void dateOfBirth;
|
|
424
|
-
void nationality;
|
|
425
|
-
const [row] = await db
|
|
426
|
-
.update(orderParticipants)
|
|
427
|
-
.set({ ...rest, updatedAt: new Date() })
|
|
428
|
-
.where(eq(orderParticipants.id, id))
|
|
429
|
-
.returning();
|
|
430
|
-
return row ? toOrderParticipantResponse(row) : null;
|
|
431
|
-
},
|
|
432
|
-
async deleteOrderParticipant(db, id) {
|
|
433
|
-
const [row] = await db
|
|
434
|
-
.delete(orderParticipants)
|
|
435
|
-
.where(eq(orderParticipants.id, id))
|
|
436
|
-
.returning({ id: orderParticipants.id });
|
|
437
|
-
return row ?? null;
|
|
438
|
-
},
|
|
439
|
-
async listOrderItems(db, query) {
|
|
440
|
-
const conditions = [];
|
|
441
|
-
if (query.orderId)
|
|
442
|
-
conditions.push(eq(orderItems.orderId, query.orderId));
|
|
443
|
-
if (query.offerItemId)
|
|
444
|
-
conditions.push(eq(orderItems.offerItemId, query.offerItemId));
|
|
445
|
-
if (query.productId)
|
|
446
|
-
conditions.push(eq(orderItems.productId, query.productId));
|
|
447
|
-
if (query.optionId)
|
|
448
|
-
conditions.push(eq(orderItems.optionId, query.optionId));
|
|
449
|
-
if (query.unitId)
|
|
450
|
-
conditions.push(eq(orderItems.unitId, query.unitId));
|
|
451
|
-
if (query.slotId)
|
|
452
|
-
conditions.push(eq(orderItems.slotId, query.slotId));
|
|
453
|
-
if (query.status)
|
|
454
|
-
conditions.push(eq(orderItems.status, query.status));
|
|
455
|
-
const where = conditions.length ? and(...conditions) : undefined;
|
|
456
|
-
return paginate(db
|
|
457
|
-
.select()
|
|
458
|
-
.from(orderItems)
|
|
459
|
-
.where(where)
|
|
460
|
-
.limit(query.limit)
|
|
461
|
-
.offset(query.offset)
|
|
462
|
-
.orderBy(asc(orderItems.createdAt)), db.select({ count: sql `count(*)::int` }).from(orderItems).where(where), query.limit, query.offset);
|
|
463
|
-
},
|
|
464
|
-
async getOrderItemById(db, id) {
|
|
465
|
-
const [row] = await db.select().from(orderItems).where(eq(orderItems.id, id)).limit(1);
|
|
466
|
-
return row ?? null;
|
|
467
|
-
},
|
|
468
|
-
async createOrderItem(db, data) {
|
|
469
|
-
const { startsAt, endsAt, ...rest } = data;
|
|
470
|
-
const [row] = await db
|
|
471
|
-
.insert(orderItems)
|
|
472
|
-
.values({
|
|
473
|
-
...rest,
|
|
474
|
-
startsAt: normalizeTimestamp(startsAt),
|
|
475
|
-
endsAt: normalizeTimestamp(endsAt),
|
|
476
|
-
})
|
|
477
|
-
.returning();
|
|
478
|
-
return row ?? null;
|
|
479
|
-
},
|
|
480
|
-
async updateOrderItem(db, id, data) {
|
|
481
|
-
const { startsAt, endsAt, ...rest } = data;
|
|
482
|
-
const [row] = await db
|
|
483
|
-
.update(orderItems)
|
|
484
|
-
.set({
|
|
485
|
-
...rest,
|
|
486
|
-
startsAt: normalizeTimestamp(startsAt),
|
|
487
|
-
endsAt: normalizeTimestamp(endsAt),
|
|
488
|
-
updatedAt: new Date(),
|
|
489
|
-
})
|
|
490
|
-
.where(eq(orderItems.id, id))
|
|
491
|
-
.returning();
|
|
492
|
-
return row ?? null;
|
|
493
|
-
},
|
|
494
|
-
async deleteOrderItem(db, id) {
|
|
495
|
-
const [row] = await db
|
|
496
|
-
.delete(orderItems)
|
|
497
|
-
.where(eq(orderItems.id, id))
|
|
498
|
-
.returning({ id: orderItems.id });
|
|
499
|
-
return row ?? null;
|
|
500
|
-
},
|
|
501
|
-
async listOrderItemParticipants(db, query) {
|
|
502
|
-
const conditions = [];
|
|
503
|
-
if (query.orderItemId)
|
|
504
|
-
conditions.push(eq(orderItemParticipants.orderItemId, query.orderItemId));
|
|
505
|
-
if (query.participantId)
|
|
506
|
-
conditions.push(eq(orderItemParticipants.participantId, query.participantId));
|
|
507
|
-
const where = conditions.length ? and(...conditions) : undefined;
|
|
508
|
-
return paginate(db
|
|
509
|
-
.select()
|
|
510
|
-
.from(orderItemParticipants)
|
|
511
|
-
.where(where)
|
|
512
|
-
.limit(query.limit)
|
|
513
|
-
.offset(query.offset)
|
|
514
|
-
.orderBy(asc(orderItemParticipants.createdAt)), db.select({ count: sql `count(*)::int` }).from(orderItemParticipants).where(where), query.limit, query.offset);
|
|
515
|
-
},
|
|
516
|
-
async getOrderItemParticipantById(db, id) {
|
|
517
|
-
const [row] = await db
|
|
518
|
-
.select()
|
|
519
|
-
.from(orderItemParticipants)
|
|
520
|
-
.where(eq(orderItemParticipants.id, id))
|
|
521
|
-
.limit(1);
|
|
522
|
-
return row ?? null;
|
|
523
|
-
},
|
|
524
|
-
async createOrderItemParticipant(db, data) {
|
|
525
|
-
const [row] = await db.insert(orderItemParticipants).values(data).returning();
|
|
526
|
-
return row ?? null;
|
|
527
|
-
},
|
|
528
|
-
async updateOrderItemParticipant(db, id, data) {
|
|
529
|
-
const [row] = await db
|
|
530
|
-
.update(orderItemParticipants)
|
|
531
|
-
.set(data)
|
|
532
|
-
.where(eq(orderItemParticipants.id, id))
|
|
533
|
-
.returning();
|
|
534
|
-
return row ?? null;
|
|
535
|
-
},
|
|
536
|
-
async deleteOrderItemParticipant(db, id) {
|
|
537
|
-
const [row] = await db
|
|
538
|
-
.delete(orderItemParticipants)
|
|
539
|
-
.where(eq(orderItemParticipants.id, id))
|
|
540
|
-
.returning({ id: orderItemParticipants.id });
|
|
541
|
-
return row ?? null;
|
|
542
|
-
},
|
|
543
|
-
async listOrderTerms(db, query) {
|
|
544
|
-
const conditions = [];
|
|
545
|
-
if (query.offerId)
|
|
546
|
-
conditions.push(eq(orderTerms.offerId, query.offerId));
|
|
547
|
-
if (query.orderId)
|
|
548
|
-
conditions.push(eq(orderTerms.orderId, query.orderId));
|
|
549
|
-
if (query.termType)
|
|
550
|
-
conditions.push(eq(orderTerms.termType, query.termType));
|
|
551
|
-
if (query.acceptanceStatus)
|
|
552
|
-
conditions.push(eq(orderTerms.acceptanceStatus, query.acceptanceStatus));
|
|
553
|
-
const where = conditions.length ? and(...conditions) : undefined;
|
|
554
|
-
return paginate(db
|
|
555
|
-
.select()
|
|
556
|
-
.from(orderTerms)
|
|
557
|
-
.where(where)
|
|
558
|
-
.limit(query.limit)
|
|
559
|
-
.offset(query.offset)
|
|
560
|
-
.orderBy(asc(orderTerms.sortOrder), asc(orderTerms.createdAt)), db.select({ count: sql `count(*)::int` }).from(orderTerms).where(where), query.limit, query.offset);
|
|
561
|
-
},
|
|
562
|
-
async getOrderTermById(db, id) {
|
|
563
|
-
const [row] = await db.select().from(orderTerms).where(eq(orderTerms.id, id)).limit(1);
|
|
564
|
-
return row ?? null;
|
|
565
|
-
},
|
|
566
|
-
async createOrderTerm(db, data) {
|
|
567
|
-
const { acceptedAt, ...rest } = data;
|
|
568
|
-
const [row] = await db
|
|
569
|
-
.insert(orderTerms)
|
|
570
|
-
.values({
|
|
571
|
-
...rest,
|
|
572
|
-
acceptedAt: normalizeTimestamp(acceptedAt),
|
|
573
|
-
})
|
|
574
|
-
.returning();
|
|
575
|
-
return row ?? null;
|
|
576
|
-
},
|
|
577
|
-
async updateOrderTerm(db, id, data) {
|
|
578
|
-
const { acceptedAt, ...rest } = data;
|
|
579
|
-
const [row] = await db
|
|
580
|
-
.update(orderTerms)
|
|
581
|
-
.set({
|
|
582
|
-
...rest,
|
|
583
|
-
acceptedAt: normalizeTimestamp(acceptedAt),
|
|
584
|
-
updatedAt: new Date(),
|
|
585
|
-
})
|
|
586
|
-
.where(eq(orderTerms.id, id))
|
|
587
|
-
.returning();
|
|
588
|
-
return row ?? null;
|
|
589
|
-
},
|
|
590
|
-
async deleteOrderTerm(db, id) {
|
|
591
|
-
const [row] = await db
|
|
592
|
-
.delete(orderTerms)
|
|
593
|
-
.where(eq(orderTerms.id, id))
|
|
594
|
-
.returning({ id: orderTerms.id });
|
|
595
|
-
return row ?? null;
|
|
596
|
-
},
|
|
4
|
+
listOffers,
|
|
5
|
+
getOfferById,
|
|
6
|
+
createOffer,
|
|
7
|
+
createOfferBundle,
|
|
8
|
+
updateOffer,
|
|
9
|
+
deleteOffer,
|
|
10
|
+
listOfferParticipants,
|
|
11
|
+
getOfferParticipantById,
|
|
12
|
+
createOfferParticipant,
|
|
13
|
+
updateOfferParticipant,
|
|
14
|
+
deleteOfferParticipant,
|
|
15
|
+
listOfferItems,
|
|
16
|
+
getOfferItemById,
|
|
17
|
+
createOfferItem,
|
|
18
|
+
updateOfferItem,
|
|
19
|
+
deleteOfferItem,
|
|
20
|
+
listOfferItemParticipants,
|
|
21
|
+
getOfferItemParticipantById,
|
|
22
|
+
createOfferItemParticipant,
|
|
23
|
+
updateOfferItemParticipant,
|
|
24
|
+
deleteOfferItemParticipant,
|
|
25
|
+
listOrders,
|
|
26
|
+
getOrderById,
|
|
27
|
+
createOrder,
|
|
28
|
+
updateOrder,
|
|
29
|
+
deleteOrder,
|
|
30
|
+
listOrderParticipants,
|
|
31
|
+
getOrderParticipantById,
|
|
32
|
+
createOrderParticipant,
|
|
33
|
+
updateOrderParticipant,
|
|
34
|
+
deleteOrderParticipant,
|
|
35
|
+
listOrderItems,
|
|
36
|
+
getOrderItemById,
|
|
37
|
+
createOrderItem,
|
|
38
|
+
updateOrderItem,
|
|
39
|
+
deleteOrderItem,
|
|
40
|
+
listOrderItemParticipants,
|
|
41
|
+
getOrderItemParticipantById,
|
|
42
|
+
createOrderItemParticipant,
|
|
43
|
+
updateOrderItemParticipant,
|
|
44
|
+
deleteOrderItemParticipant,
|
|
45
|
+
listOrderTerms,
|
|
46
|
+
getOrderTermById,
|
|
47
|
+
createOrderTerm,
|
|
48
|
+
updateOrderTerm,
|
|
49
|
+
deleteOrderTerm,
|
|
597
50
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voyantjs/transactions",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"license": "FSL-1.1-Apache-2.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"drizzle-orm": "^0.45.2",
|
|
30
30
|
"hono": "^4.12.10",
|
|
31
31
|
"zod": "^4.3.6",
|
|
32
|
-
"@voyantjs/core": "0.
|
|
33
|
-
"@voyantjs/db": "0.
|
|
34
|
-
"@voyantjs/hono": "0.
|
|
35
|
-
"@voyantjs/utils": "0.
|
|
32
|
+
"@voyantjs/core": "0.3.0",
|
|
33
|
+
"@voyantjs/db": "0.3.0",
|
|
34
|
+
"@voyantjs/hono": "0.3.0",
|
|
35
|
+
"@voyantjs/utils": "0.3.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"typescript": "^6.0.2",
|