@voyantjs/transactions 0.1.1 → 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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-orders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BAAsB,cAAc,CAAC,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,kBAAkB;;;;;;;;;;;;;;;;;;;;;GAoBrF;AAED,wBAAsB,gBAAgB,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;;;;;;;;;;;;;;;UAGxE;AAED,wBAAsB,eAAe,CAAC,EAAE,EAAE,kBAAkB,EAAE,IAAI,EAAE,oBAAoB;;;;;;;;;;;;;;;;UAUvF;AAED,wBAAsB,eAAe,CACnC,EAAE,EAAE,kBAAkB,EACtB,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,oBAAoB;;;;;;;;;;;;;;;;UAa3B;AAED,wBAAsB,eAAe,CAAC,EAAE,EAAE,kBAAkB,EAAE,EAAE,EAAE,MAAM;;UAMvE"}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { and, asc, desc, eq, ilike, or, sql } from "drizzle-orm";
|
|
2
|
+
import { orderItemParticipants, orderItems, orderParticipants, orders, orderTerms, } from "./schema.js";
|
|
3
|
+
import { normalizeTimestamp, paginate, toOrderParticipantResponse } from "./service-shared.js";
|
|
4
|
+
export async function listOrders(db, query) {
|
|
5
|
+
const conditions = [];
|
|
6
|
+
if (query.status)
|
|
7
|
+
conditions.push(eq(orders.status, query.status));
|
|
8
|
+
if (query.offerId)
|
|
9
|
+
conditions.push(eq(orders.offerId, query.offerId));
|
|
10
|
+
if (query.opportunityId)
|
|
11
|
+
conditions.push(eq(orders.opportunityId, query.opportunityId));
|
|
12
|
+
if (query.quoteId)
|
|
13
|
+
conditions.push(eq(orders.quoteId, query.quoteId));
|
|
14
|
+
if (query.personId)
|
|
15
|
+
conditions.push(eq(orders.personId, query.personId));
|
|
16
|
+
if (query.organizationId)
|
|
17
|
+
conditions.push(eq(orders.organizationId, query.organizationId));
|
|
18
|
+
if (query.marketId)
|
|
19
|
+
conditions.push(eq(orders.marketId, query.marketId));
|
|
20
|
+
if (query.search) {
|
|
21
|
+
const term = `%${query.search}%`;
|
|
22
|
+
conditions.push(or(ilike(orders.orderNumber, term), ilike(orders.title, term)));
|
|
23
|
+
}
|
|
24
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
25
|
+
return paginate(db
|
|
26
|
+
.select()
|
|
27
|
+
.from(orders)
|
|
28
|
+
.where(where)
|
|
29
|
+
.limit(query.limit)
|
|
30
|
+
.offset(query.offset)
|
|
31
|
+
.orderBy(desc(orders.createdAt)), db.select({ count: sql `count(*)::int` }).from(orders).where(where), query.limit, query.offset);
|
|
32
|
+
}
|
|
33
|
+
export async function getOrderById(db, id) {
|
|
34
|
+
const [row] = await db.select().from(orders).where(eq(orders.id, id)).limit(1);
|
|
35
|
+
return row ?? null;
|
|
36
|
+
}
|
|
37
|
+
export async function createOrder(db, data) {
|
|
38
|
+
const { orderedAt, confirmedAt, cancelledAt, expiresAt, ...rest } = data;
|
|
39
|
+
const [row] = await db
|
|
40
|
+
.insert(orders)
|
|
41
|
+
.values({
|
|
42
|
+
...rest,
|
|
43
|
+
orderedAt: normalizeTimestamp(orderedAt),
|
|
44
|
+
confirmedAt: normalizeTimestamp(confirmedAt),
|
|
45
|
+
cancelledAt: normalizeTimestamp(cancelledAt),
|
|
46
|
+
expiresAt: normalizeTimestamp(expiresAt),
|
|
47
|
+
})
|
|
48
|
+
.returning();
|
|
49
|
+
return row ?? null;
|
|
50
|
+
}
|
|
51
|
+
export async function updateOrder(db, id, data) {
|
|
52
|
+
const { orderedAt, confirmedAt, cancelledAt, expiresAt, ...rest } = data;
|
|
53
|
+
const [row] = await db
|
|
54
|
+
.update(orders)
|
|
55
|
+
.set({
|
|
56
|
+
...rest,
|
|
57
|
+
orderedAt: normalizeTimestamp(orderedAt),
|
|
58
|
+
confirmedAt: normalizeTimestamp(confirmedAt),
|
|
59
|
+
cancelledAt: normalizeTimestamp(cancelledAt),
|
|
60
|
+
expiresAt: normalizeTimestamp(expiresAt),
|
|
61
|
+
updatedAt: new Date(),
|
|
62
|
+
})
|
|
63
|
+
.where(eq(orders.id, id))
|
|
64
|
+
.returning();
|
|
65
|
+
return row ?? null;
|
|
66
|
+
}
|
|
67
|
+
export async function deleteOrder(db, id) {
|
|
68
|
+
const [row] = await db.delete(orders).where(eq(orders.id, id)).returning({ id: orders.id });
|
|
69
|
+
return row ?? null;
|
|
70
|
+
}
|
|
71
|
+
export async function listOrderParticipants(db, query) {
|
|
72
|
+
const conditions = [];
|
|
73
|
+
if (query.orderId)
|
|
74
|
+
conditions.push(eq(orderParticipants.orderId, query.orderId));
|
|
75
|
+
if (query.personId)
|
|
76
|
+
conditions.push(eq(orderParticipants.personId, query.personId));
|
|
77
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
78
|
+
const rows = db
|
|
79
|
+
.select()
|
|
80
|
+
.from(orderParticipants)
|
|
81
|
+
.where(where)
|
|
82
|
+
.limit(query.limit)
|
|
83
|
+
.offset(query.offset)
|
|
84
|
+
.orderBy(asc(orderParticipants.createdAt))
|
|
85
|
+
.then((items) => items.map(toOrderParticipantResponse));
|
|
86
|
+
return paginate(rows, db.select({ count: sql `count(*)::int` }).from(orderParticipants).where(where), query.limit, query.offset);
|
|
87
|
+
}
|
|
88
|
+
export async function getOrderParticipantById(db, id) {
|
|
89
|
+
const [row] = await db
|
|
90
|
+
.select()
|
|
91
|
+
.from(orderParticipants)
|
|
92
|
+
.where(eq(orderParticipants.id, id))
|
|
93
|
+
.limit(1);
|
|
94
|
+
return row ? toOrderParticipantResponse(row) : null;
|
|
95
|
+
}
|
|
96
|
+
export async function createOrderParticipant(db, data) {
|
|
97
|
+
const { dateOfBirth, nationality, ...rest } = data;
|
|
98
|
+
void dateOfBirth;
|
|
99
|
+
void nationality;
|
|
100
|
+
const [row] = await db.insert(orderParticipants).values(rest).returning();
|
|
101
|
+
return row ? toOrderParticipantResponse(row) : null;
|
|
102
|
+
}
|
|
103
|
+
export async function updateOrderParticipant(db, id, data) {
|
|
104
|
+
const { dateOfBirth, nationality, ...rest } = data;
|
|
105
|
+
void dateOfBirth;
|
|
106
|
+
void nationality;
|
|
107
|
+
const [row] = await db
|
|
108
|
+
.update(orderParticipants)
|
|
109
|
+
.set({ ...rest, updatedAt: new Date() })
|
|
110
|
+
.where(eq(orderParticipants.id, id))
|
|
111
|
+
.returning();
|
|
112
|
+
return row ? toOrderParticipantResponse(row) : null;
|
|
113
|
+
}
|
|
114
|
+
export async function deleteOrderParticipant(db, id) {
|
|
115
|
+
const [row] = await db
|
|
116
|
+
.delete(orderParticipants)
|
|
117
|
+
.where(eq(orderParticipants.id, id))
|
|
118
|
+
.returning({ id: orderParticipants.id });
|
|
119
|
+
return row ?? null;
|
|
120
|
+
}
|
|
121
|
+
export async function listOrderItems(db, query) {
|
|
122
|
+
const conditions = [];
|
|
123
|
+
if (query.orderId)
|
|
124
|
+
conditions.push(eq(orderItems.orderId, query.orderId));
|
|
125
|
+
if (query.offerItemId)
|
|
126
|
+
conditions.push(eq(orderItems.offerItemId, query.offerItemId));
|
|
127
|
+
if (query.productId)
|
|
128
|
+
conditions.push(eq(orderItems.productId, query.productId));
|
|
129
|
+
if (query.optionId)
|
|
130
|
+
conditions.push(eq(orderItems.optionId, query.optionId));
|
|
131
|
+
if (query.unitId)
|
|
132
|
+
conditions.push(eq(orderItems.unitId, query.unitId));
|
|
133
|
+
if (query.slotId)
|
|
134
|
+
conditions.push(eq(orderItems.slotId, query.slotId));
|
|
135
|
+
if (query.status)
|
|
136
|
+
conditions.push(eq(orderItems.status, query.status));
|
|
137
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
138
|
+
return paginate(db
|
|
139
|
+
.select()
|
|
140
|
+
.from(orderItems)
|
|
141
|
+
.where(where)
|
|
142
|
+
.limit(query.limit)
|
|
143
|
+
.offset(query.offset)
|
|
144
|
+
.orderBy(asc(orderItems.createdAt)), db.select({ count: sql `count(*)::int` }).from(orderItems).where(where), query.limit, query.offset);
|
|
145
|
+
}
|
|
146
|
+
export async function getOrderItemById(db, id) {
|
|
147
|
+
const [row] = await db.select().from(orderItems).where(eq(orderItems.id, id)).limit(1);
|
|
148
|
+
return row ?? null;
|
|
149
|
+
}
|
|
150
|
+
export async function createOrderItem(db, data) {
|
|
151
|
+
const { startsAt, endsAt, ...rest } = data;
|
|
152
|
+
const [row] = await db
|
|
153
|
+
.insert(orderItems)
|
|
154
|
+
.values({
|
|
155
|
+
...rest,
|
|
156
|
+
startsAt: normalizeTimestamp(startsAt),
|
|
157
|
+
endsAt: normalizeTimestamp(endsAt),
|
|
158
|
+
})
|
|
159
|
+
.returning();
|
|
160
|
+
return row ?? null;
|
|
161
|
+
}
|
|
162
|
+
export async function updateOrderItem(db, id, data) {
|
|
163
|
+
const { startsAt, endsAt, ...rest } = data;
|
|
164
|
+
const [row] = await db
|
|
165
|
+
.update(orderItems)
|
|
166
|
+
.set({
|
|
167
|
+
...rest,
|
|
168
|
+
startsAt: normalizeTimestamp(startsAt),
|
|
169
|
+
endsAt: normalizeTimestamp(endsAt),
|
|
170
|
+
updatedAt: new Date(),
|
|
171
|
+
})
|
|
172
|
+
.where(eq(orderItems.id, id))
|
|
173
|
+
.returning();
|
|
174
|
+
return row ?? null;
|
|
175
|
+
}
|
|
176
|
+
export async function deleteOrderItem(db, id) {
|
|
177
|
+
const [row] = await db
|
|
178
|
+
.delete(orderItems)
|
|
179
|
+
.where(eq(orderItems.id, id))
|
|
180
|
+
.returning({ id: orderItems.id });
|
|
181
|
+
return row ?? null;
|
|
182
|
+
}
|
|
183
|
+
export async function listOrderItemParticipants(db, query) {
|
|
184
|
+
const conditions = [];
|
|
185
|
+
if (query.orderItemId)
|
|
186
|
+
conditions.push(eq(orderItemParticipants.orderItemId, query.orderItemId));
|
|
187
|
+
if (query.participantId)
|
|
188
|
+
conditions.push(eq(orderItemParticipants.participantId, query.participantId));
|
|
189
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
190
|
+
return paginate(db
|
|
191
|
+
.select()
|
|
192
|
+
.from(orderItemParticipants)
|
|
193
|
+
.where(where)
|
|
194
|
+
.limit(query.limit)
|
|
195
|
+
.offset(query.offset)
|
|
196
|
+
.orderBy(asc(orderItemParticipants.createdAt)), db.select({ count: sql `count(*)::int` }).from(orderItemParticipants).where(where), query.limit, query.offset);
|
|
197
|
+
}
|
|
198
|
+
export async function getOrderItemParticipantById(db, id) {
|
|
199
|
+
const [row] = await db
|
|
200
|
+
.select()
|
|
201
|
+
.from(orderItemParticipants)
|
|
202
|
+
.where(eq(orderItemParticipants.id, id))
|
|
203
|
+
.limit(1);
|
|
204
|
+
return row ?? null;
|
|
205
|
+
}
|
|
206
|
+
export async function createOrderItemParticipant(db, data) {
|
|
207
|
+
const [row] = await db.insert(orderItemParticipants).values(data).returning();
|
|
208
|
+
return row ?? null;
|
|
209
|
+
}
|
|
210
|
+
export async function updateOrderItemParticipant(db, id, data) {
|
|
211
|
+
const [row] = await db
|
|
212
|
+
.update(orderItemParticipants)
|
|
213
|
+
.set(data)
|
|
214
|
+
.where(eq(orderItemParticipants.id, id))
|
|
215
|
+
.returning();
|
|
216
|
+
return row ?? null;
|
|
217
|
+
}
|
|
218
|
+
export async function deleteOrderItemParticipant(db, id) {
|
|
219
|
+
const [row] = await db
|
|
220
|
+
.delete(orderItemParticipants)
|
|
221
|
+
.where(eq(orderItemParticipants.id, id))
|
|
222
|
+
.returning({ id: orderItemParticipants.id });
|
|
223
|
+
return row ?? null;
|
|
224
|
+
}
|
|
225
|
+
export async function listOrderTerms(db, query) {
|
|
226
|
+
const conditions = [];
|
|
227
|
+
if (query.offerId)
|
|
228
|
+
conditions.push(eq(orderTerms.offerId, query.offerId));
|
|
229
|
+
if (query.orderId)
|
|
230
|
+
conditions.push(eq(orderTerms.orderId, query.orderId));
|
|
231
|
+
if (query.termType)
|
|
232
|
+
conditions.push(eq(orderTerms.termType, query.termType));
|
|
233
|
+
if (query.acceptanceStatus)
|
|
234
|
+
conditions.push(eq(orderTerms.acceptanceStatus, query.acceptanceStatus));
|
|
235
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
236
|
+
return paginate(db
|
|
237
|
+
.select()
|
|
238
|
+
.from(orderTerms)
|
|
239
|
+
.where(where)
|
|
240
|
+
.limit(query.limit)
|
|
241
|
+
.offset(query.offset)
|
|
242
|
+
.orderBy(asc(orderTerms.sortOrder), asc(orderTerms.createdAt)), db.select({ count: sql `count(*)::int` }).from(orderTerms).where(where), query.limit, query.offset);
|
|
243
|
+
}
|
|
244
|
+
export async function getOrderTermById(db, id) {
|
|
245
|
+
const [row] = await db.select().from(orderTerms).where(eq(orderTerms.id, id)).limit(1);
|
|
246
|
+
return row ?? null;
|
|
247
|
+
}
|
|
248
|
+
export async function createOrderTerm(db, data) {
|
|
249
|
+
const { acceptedAt, ...rest } = data;
|
|
250
|
+
const [row] = await db
|
|
251
|
+
.insert(orderTerms)
|
|
252
|
+
.values({
|
|
253
|
+
...rest,
|
|
254
|
+
acceptedAt: normalizeTimestamp(acceptedAt),
|
|
255
|
+
})
|
|
256
|
+
.returning();
|
|
257
|
+
return row ?? null;
|
|
258
|
+
}
|
|
259
|
+
export async function updateOrderTerm(db, id, data) {
|
|
260
|
+
const { acceptedAt, ...rest } = data;
|
|
261
|
+
const [row] = await db
|
|
262
|
+
.update(orderTerms)
|
|
263
|
+
.set({
|
|
264
|
+
...rest,
|
|
265
|
+
acceptedAt: normalizeTimestamp(acceptedAt),
|
|
266
|
+
updatedAt: new Date(),
|
|
267
|
+
})
|
|
268
|
+
.where(eq(orderTerms.id, id))
|
|
269
|
+
.returning();
|
|
270
|
+
return row ?? null;
|
|
271
|
+
}
|
|
272
|
+
export async function deleteOrderTerm(db, id) {
|
|
273
|
+
const [row] = await db
|
|
274
|
+
.delete(orderTerms)
|
|
275
|
+
.where(eq(orderTerms.id, id))
|
|
276
|
+
.returning({ id: orderTerms.id });
|
|
277
|
+
return row ?? null;
|
|
278
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { z } from "zod";
|
|
2
|
+
import type { offerParticipants, orderParticipants } from "./schema.js";
|
|
3
|
+
import type { insertOfferItemParticipantSchema, insertOfferItemSchema, insertOfferParticipantSchema, insertOfferSchema, insertOrderItemParticipantSchema, insertOrderItemSchema, insertOrderParticipantSchema, insertOrderSchema, insertOrderTermSchema, offerItemListQuerySchema, offerItemParticipantListQuerySchema, offerListQuerySchema, offerParticipantListQuerySchema, orderItemListQuerySchema, orderItemParticipantListQuerySchema, orderListQuerySchema, orderParticipantListQuerySchema, orderTermListQuerySchema, updateOfferItemParticipantSchema, updateOfferItemSchema, updateOfferParticipantSchema, updateOfferSchema, updateOrderItemParticipantSchema, updateOrderItemSchema, updateOrderParticipantSchema, updateOrderSchema, updateOrderTermSchema } from "./validation.js";
|
|
4
|
+
export type OfferListQuery = z.infer<typeof offerListQuerySchema>;
|
|
5
|
+
export type OfferParticipantListQuery = z.infer<typeof offerParticipantListQuerySchema>;
|
|
6
|
+
export type OfferItemListQuery = z.infer<typeof offerItemListQuerySchema>;
|
|
7
|
+
export type OfferItemParticipantListQuery = z.infer<typeof offerItemParticipantListQuerySchema>;
|
|
8
|
+
export type OrderListQuery = z.infer<typeof orderListQuerySchema>;
|
|
9
|
+
export type OrderParticipantListQuery = z.infer<typeof orderParticipantListQuerySchema>;
|
|
10
|
+
export type OrderItemListQuery = z.infer<typeof orderItemListQuerySchema>;
|
|
11
|
+
export type OrderItemParticipantListQuery = z.infer<typeof orderItemParticipantListQuerySchema>;
|
|
12
|
+
export type OrderTermListQuery = z.infer<typeof orderTermListQuerySchema>;
|
|
13
|
+
export type CreateOfferInput = z.infer<typeof insertOfferSchema>;
|
|
14
|
+
export type UpdateOfferInput = z.infer<typeof updateOfferSchema>;
|
|
15
|
+
export type CreateOfferParticipantInput = z.infer<typeof insertOfferParticipantSchema>;
|
|
16
|
+
export type UpdateOfferParticipantInput = z.infer<typeof updateOfferParticipantSchema>;
|
|
17
|
+
export type CreateOfferItemInput = z.infer<typeof insertOfferItemSchema>;
|
|
18
|
+
export type UpdateOfferItemInput = z.infer<typeof updateOfferItemSchema>;
|
|
19
|
+
export type CreateOfferItemParticipantInput = z.infer<typeof insertOfferItemParticipantSchema>;
|
|
20
|
+
export type UpdateOfferItemParticipantInput = z.infer<typeof updateOfferItemParticipantSchema>;
|
|
21
|
+
export type CreateOrderInput = z.infer<typeof insertOrderSchema>;
|
|
22
|
+
export type UpdateOrderInput = z.infer<typeof updateOrderSchema>;
|
|
23
|
+
export type CreateOrderParticipantInput = z.infer<typeof insertOrderParticipantSchema>;
|
|
24
|
+
export type UpdateOrderParticipantInput = z.infer<typeof updateOrderParticipantSchema>;
|
|
25
|
+
export type CreateOrderItemInput = z.infer<typeof insertOrderItemSchema>;
|
|
26
|
+
export type UpdateOrderItemInput = z.infer<typeof updateOrderItemSchema>;
|
|
27
|
+
export type CreateOrderItemParticipantInput = z.infer<typeof insertOrderItemParticipantSchema>;
|
|
28
|
+
export type UpdateOrderItemParticipantInput = z.infer<typeof updateOrderItemParticipantSchema>;
|
|
29
|
+
export type CreateOrderTermInput = z.infer<typeof insertOrderTermSchema>;
|
|
30
|
+
export type UpdateOrderTermInput = z.infer<typeof updateOrderTermSchema>;
|
|
31
|
+
export type OfferBundleParticipantInput = Omit<CreateOfferParticipantInput, "offerId">;
|
|
32
|
+
export type OfferBundleItemInput = Omit<CreateOfferItemInput, "offerId">;
|
|
33
|
+
export type OfferBundleItemParticipantInput = Omit<CreateOfferItemParticipantInput, "offerItemId" | "participantId"> & {
|
|
34
|
+
itemIndex: number;
|
|
35
|
+
participantIndex: number;
|
|
36
|
+
};
|
|
37
|
+
export type CreateOfferBundleInput = {
|
|
38
|
+
offer: CreateOfferInput;
|
|
39
|
+
participants?: OfferBundleParticipantInput[];
|
|
40
|
+
items: OfferBundleItemInput[];
|
|
41
|
+
itemParticipants?: OfferBundleItemParticipantInput[];
|
|
42
|
+
};
|
|
43
|
+
export declare function paginate<T extends object>(rowsQuery: Promise<T[]>, countQuery: Promise<Array<{
|
|
44
|
+
count: number;
|
|
45
|
+
}>>, limit: number, offset: number): Promise<{
|
|
46
|
+
data: T[];
|
|
47
|
+
total: number;
|
|
48
|
+
limit: number;
|
|
49
|
+
offset: number;
|
|
50
|
+
}>;
|
|
51
|
+
export declare function normalizeTimestamp(value: string | null | undefined): Date | null | undefined;
|
|
52
|
+
export declare function toOfferParticipantResponse(row: typeof offerParticipants.$inferSelect): {
|
|
53
|
+
id: string;
|
|
54
|
+
offerId: string;
|
|
55
|
+
personId: string | null;
|
|
56
|
+
participantType: "staff" | "other" | "traveler" | "booker" | "contact" | "occupant";
|
|
57
|
+
travelerCategory: "other" | "adult" | "child" | "infant" | "senior" | null;
|
|
58
|
+
firstName: string;
|
|
59
|
+
lastName: string;
|
|
60
|
+
email: string | null;
|
|
61
|
+
phone: string | null;
|
|
62
|
+
preferredLanguage: string | null;
|
|
63
|
+
isPrimary: boolean;
|
|
64
|
+
notes: string | null;
|
|
65
|
+
hasTravelIdentity: boolean;
|
|
66
|
+
createdAt: Date;
|
|
67
|
+
updatedAt: Date;
|
|
68
|
+
};
|
|
69
|
+
export declare function toOrderParticipantResponse(row: typeof orderParticipants.$inferSelect): {
|
|
70
|
+
id: string;
|
|
71
|
+
orderId: string;
|
|
72
|
+
personId: string | null;
|
|
73
|
+
participantType: "staff" | "other" | "traveler" | "booker" | "contact" | "occupant";
|
|
74
|
+
travelerCategory: "other" | "adult" | "child" | "infant" | "senior" | null;
|
|
75
|
+
firstName: string;
|
|
76
|
+
lastName: string;
|
|
77
|
+
email: string | null;
|
|
78
|
+
phone: string | null;
|
|
79
|
+
preferredLanguage: string | null;
|
|
80
|
+
isPrimary: boolean;
|
|
81
|
+
notes: string | null;
|
|
82
|
+
hasTravelIdentity: boolean;
|
|
83
|
+
createdAt: Date;
|
|
84
|
+
updatedAt: Date;
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=service-shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-shared.d.ts","sourceRoot":"","sources":["../src/service-shared.ts"],"names":[],"mappings":"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E,OAAO,iBAAiB,CAAC,YAAY;;;;;;;;;;;;;;;;EAkBpF;AAED,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,OAAO,iBAAiB,CAAC,YAAY;;;;;;;;;;;;;;;;EAkBpF"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
export async function paginate(rowsQuery, countQuery, limit, offset) {
|
|
2
|
+
const [data, countResult] = await Promise.all([rowsQuery, countQuery]);
|
|
3
|
+
return { data, total: countResult[0]?.count ?? 0, limit, offset };
|
|
4
|
+
}
|
|
5
|
+
export function normalizeTimestamp(value) {
|
|
6
|
+
if (value === undefined || value === "")
|
|
7
|
+
return undefined;
|
|
8
|
+
if (value === null)
|
|
9
|
+
return null;
|
|
10
|
+
return new Date(value);
|
|
11
|
+
}
|
|
12
|
+
export function toOfferParticipantResponse(row) {
|
|
13
|
+
return {
|
|
14
|
+
id: row.id,
|
|
15
|
+
offerId: row.offerId,
|
|
16
|
+
personId: row.personId,
|
|
17
|
+
participantType: row.participantType,
|
|
18
|
+
travelerCategory: row.travelerCategory,
|
|
19
|
+
firstName: row.firstName,
|
|
20
|
+
lastName: row.lastName,
|
|
21
|
+
email: row.email,
|
|
22
|
+
phone: row.phone,
|
|
23
|
+
preferredLanguage: row.preferredLanguage,
|
|
24
|
+
isPrimary: row.isPrimary,
|
|
25
|
+
notes: row.notes,
|
|
26
|
+
hasTravelIdentity: Boolean(row.identityEncrypted),
|
|
27
|
+
createdAt: row.createdAt,
|
|
28
|
+
updatedAt: row.updatedAt,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export function toOrderParticipantResponse(row) {
|
|
32
|
+
return {
|
|
33
|
+
id: row.id,
|
|
34
|
+
orderId: row.orderId,
|
|
35
|
+
personId: row.personId,
|
|
36
|
+
participantType: row.participantType,
|
|
37
|
+
travelerCategory: row.travelerCategory,
|
|
38
|
+
firstName: row.firstName,
|
|
39
|
+
lastName: row.lastName,
|
|
40
|
+
email: row.email,
|
|
41
|
+
phone: row.phone,
|
|
42
|
+
preferredLanguage: row.preferredLanguage,
|
|
43
|
+
isPrimary: row.isPrimary,
|
|
44
|
+
notes: row.notes,
|
|
45
|
+
hasTravelIdentity: Boolean(row.identityEncrypted),
|
|
46
|
+
createdAt: row.createdAt,
|
|
47
|
+
updatedAt: row.updatedAt,
|
|
48
|
+
};
|
|
49
|
+
}
|