@voyant-travel/distribution 0.109.8
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 +42 -0
- package/dist/booking-extension.d.ts +168 -0
- package/dist/booking-extension.d.ts.map +1 -0
- package/dist/booking-extension.js +102 -0
- package/dist/channel-push/admin-routes.d.ts +31 -0
- package/dist/channel-push/admin-routes.d.ts.map +1 -0
- package/dist/channel-push/admin-routes.js +165 -0
- package/dist/channel-push/availability-push.d.ts +76 -0
- package/dist/channel-push/availability-push.d.ts.map +1 -0
- package/dist/channel-push/availability-push.js +236 -0
- package/dist/channel-push/booking-push-helpers.d.ts +36 -0
- package/dist/channel-push/booking-push-helpers.d.ts.map +1 -0
- package/dist/channel-push/booking-push-helpers.js +169 -0
- package/dist/channel-push/booking-push.d.ts +108 -0
- package/dist/channel-push/booking-push.d.ts.map +1 -0
- package/dist/channel-push/booking-push.js +335 -0
- package/dist/channel-push/boundary-sql.d.ts +23 -0
- package/dist/channel-push/boundary-sql.d.ts.map +1 -0
- package/dist/channel-push/boundary-sql.js +75 -0
- package/dist/channel-push/content-push.d.ts +60 -0
- package/dist/channel-push/content-push.d.ts.map +1 -0
- package/dist/channel-push/content-push.js +252 -0
- package/dist/channel-push/index.d.ts +15 -0
- package/dist/channel-push/index.d.ts.map +1 -0
- package/dist/channel-push/index.js +18 -0
- package/dist/channel-push/plugin.d.ts +18 -0
- package/dist/channel-push/plugin.d.ts.map +1 -0
- package/dist/channel-push/plugin.js +21 -0
- package/dist/channel-push/reconciler.d.ts +85 -0
- package/dist/channel-push/reconciler.d.ts.map +1 -0
- package/dist/channel-push/reconciler.js +179 -0
- package/dist/channel-push/subscriber.d.ts +40 -0
- package/dist/channel-push/subscriber.d.ts.map +1 -0
- package/dist/channel-push/subscriber.js +199 -0
- package/dist/channel-push/types.d.ts +43 -0
- package/dist/channel-push/types.d.ts.map +1 -0
- package/dist/channel-push/types.js +32 -0
- package/dist/channel-push/workflows.d.ts +56 -0
- package/dist/channel-push/workflows.d.ts.map +1 -0
- package/dist/channel-push/workflows.js +100 -0
- package/dist/external-refs/index.d.ts +11 -0
- package/dist/external-refs/index.d.ts.map +1 -0
- package/dist/external-refs/index.js +12 -0
- package/dist/external-refs/routes.d.ts +253 -0
- package/dist/external-refs/routes.d.ts.map +1 -0
- package/dist/external-refs/routes.js +52 -0
- package/dist/external-refs/schema.d.ts +251 -0
- package/dist/external-refs/schema.d.ts.map +1 -0
- package/dist/external-refs/schema.js +32 -0
- package/dist/external-refs/service.d.ts +82 -0
- package/dist/external-refs/service.d.ts.map +1 -0
- package/dist/external-refs/service.js +112 -0
- package/dist/external-refs/validation.d.ts +91 -0
- package/dist/external-refs/validation.d.ts.map +1 -0
- package/dist/external-refs/validation.js +40 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/interface-types.d.ts +128 -0
- package/dist/interface-types.d.ts.map +1 -0
- package/dist/interface-types.js +1 -0
- package/dist/interface.d.ts +10 -0
- package/dist/interface.d.ts.map +1 -0
- package/dist/interface.js +286 -0
- package/dist/rate-limit.d.ts +69 -0
- package/dist/rate-limit.d.ts.map +1 -0
- package/dist/rate-limit.js +135 -0
- package/dist/routes/batch.d.ts +200 -0
- package/dist/routes/batch.d.ts.map +1 -0
- package/dist/routes/batch.js +52 -0
- package/dist/routes/env.d.ts +8 -0
- package/dist/routes/env.d.ts.map +1 -0
- package/dist/routes/env.js +1 -0
- package/dist/routes/inventory.d.ts +604 -0
- package/dist/routes/inventory.d.ts.map +1 -0
- package/dist/routes/inventory.js +138 -0
- package/dist/routes/settlements.d.ts +1649 -0
- package/dist/routes/settlements.d.ts.map +1 -0
- package/dist/routes/settlements.js +265 -0
- package/dist/routes.d.ts +3909 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +323 -0
- package/dist/schema-automation.d.ts +680 -0
- package/dist/schema-automation.d.ts.map +1 -0
- package/dist/schema-automation.js +76 -0
- package/dist/schema-core.d.ts +1674 -0
- package/dist/schema-core.d.ts.map +1 -0
- package/dist/schema-core.js +227 -0
- package/dist/schema-finance.d.ts +1372 -0
- package/dist/schema-finance.d.ts.map +1 -0
- package/dist/schema-finance.js +153 -0
- package/dist/schema-inventory.d.ts +855 -0
- package/dist/schema-inventory.d.ts.map +1 -0
- package/dist/schema-inventory.js +102 -0
- package/dist/schema-push-intents.d.ts +387 -0
- package/dist/schema-push-intents.d.ts.map +1 -0
- package/dist/schema-push-intents.js +77 -0
- package/dist/schema-relations.d.ts +95 -0
- package/dist/schema-relations.d.ts.map +1 -0
- package/dist/schema-relations.js +196 -0
- package/dist/schema-shared.d.ts +24 -0
- package/dist/schema-shared.d.ts.map +1 -0
- package/dist/schema-shared.js +123 -0
- package/dist/schema.d.ts +9 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +8 -0
- package/dist/service/channels.d.ts +167 -0
- package/dist/service/channels.d.ts.map +1 -0
- package/dist/service/channels.js +305 -0
- package/dist/service/commercial.d.ts +385 -0
- package/dist/service/commercial.d.ts.map +1 -0
- package/dist/service/commercial.js +248 -0
- package/dist/service/helpers.d.ts +10 -0
- package/dist/service/helpers.d.ts.map +1 -0
- package/dist/service/helpers.js +7 -0
- package/dist/service/inventory.d.ts +193 -0
- package/dist/service/inventory.d.ts.map +1 -0
- package/dist/service/inventory.js +154 -0
- package/dist/service/settlement-policies.d.ts +325 -0
- package/dist/service/settlement-policies.d.ts.map +1 -0
- package/dist/service/settlement-policies.js +272 -0
- package/dist/service/settlements.d.ts +357 -0
- package/dist/service/settlements.d.ts.map +1 -0
- package/dist/service/settlements.js +319 -0
- package/dist/service/types.d.ts +60 -0
- package/dist/service/types.d.ts.map +1 -0
- package/dist/service/types.js +1 -0
- package/dist/service.d.ts +1418 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +17 -0
- package/dist/suppliers/index.d.ts +15 -0
- package/dist/suppliers/index.d.ts.map +1 -0
- package/dist/suppliers/index.js +23 -0
- package/dist/suppliers/routes.d.ts +1202 -0
- package/dist/suppliers/routes.d.ts.map +1 -0
- package/dist/suppliers/routes.js +290 -0
- package/dist/suppliers/schema.d.ts +1272 -0
- package/dist/suppliers/schema.d.ts.map +1 -0
- package/dist/suppliers/schema.js +219 -0
- package/dist/suppliers/service-aggregates.d.ts +23 -0
- package/dist/suppliers/service-aggregates.d.ts.map +1 -0
- package/dist/suppliers/service-aggregates.js +51 -0
- package/dist/suppliers/service-core.d.ts +89 -0
- package/dist/suppliers/service-core.d.ts.map +1 -0
- package/dist/suppliers/service-core.js +164 -0
- package/dist/suppliers/service-identity.d.ts +162 -0
- package/dist/suppliers/service-identity.d.ts.map +1 -0
- package/dist/suppliers/service-identity.js +101 -0
- package/dist/suppliers/service-operations.d.ts +1500 -0
- package/dist/suppliers/service-operations.d.ts.map +1 -0
- package/dist/suppliers/service-operations.js +157 -0
- package/dist/suppliers/service-shared.d.ts +45 -0
- package/dist/suppliers/service-shared.d.ts.map +1 -0
- package/dist/suppliers/service-shared.js +294 -0
- package/dist/suppliers/service.d.ts +41 -0
- package/dist/suppliers/service.d.ts.map +1 -0
- package/dist/suppliers/service.js +40 -0
- package/dist/suppliers/validation.d.ts +2 -0
- package/dist/suppliers/validation.d.ts.map +1 -0
- package/dist/suppliers/validation.js +1 -0
- package/dist/validation.d.ts +1371 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +445 -0
- package/dist/webhook-deliveries.d.ts +86 -0
- package/dist/webhook-deliveries.d.ts.map +1 -0
- package/dist/webhook-deliveries.js +296 -0
- package/package.json +71 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import { and, desc, eq, sql } from "drizzle-orm";
|
|
2
|
+
import { channelBookingLinks, channelCommissionRules, channelContracts, channelProductMappings, channelWebhookEvents, } from "../schema.js";
|
|
3
|
+
import { paginate, toDateOrNull } from "./helpers.js";
|
|
4
|
+
export const commercialServiceOperations = {
|
|
5
|
+
async listContracts(db, query) {
|
|
6
|
+
const conditions = [];
|
|
7
|
+
if (query.channelId)
|
|
8
|
+
conditions.push(eq(channelContracts.channelId, query.channelId));
|
|
9
|
+
if (query.supplierId)
|
|
10
|
+
conditions.push(eq(channelContracts.supplierId, query.supplierId));
|
|
11
|
+
if (query.status)
|
|
12
|
+
conditions.push(eq(channelContracts.status, query.status));
|
|
13
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
14
|
+
return paginate(db
|
|
15
|
+
.select()
|
|
16
|
+
.from(channelContracts)
|
|
17
|
+
.where(where)
|
|
18
|
+
.limit(query.limit)
|
|
19
|
+
.offset(query.offset)
|
|
20
|
+
.orderBy(desc(channelContracts.createdAt)), db.select({ count: sql `count(*)::int` }).from(channelContracts).where(where), query.limit, query.offset);
|
|
21
|
+
},
|
|
22
|
+
async getContractById(db, id) {
|
|
23
|
+
const [row] = await db
|
|
24
|
+
.select()
|
|
25
|
+
.from(channelContracts)
|
|
26
|
+
.where(eq(channelContracts.id, id))
|
|
27
|
+
.limit(1);
|
|
28
|
+
return row ?? null;
|
|
29
|
+
},
|
|
30
|
+
async createContract(db, data) {
|
|
31
|
+
const [row] = await db.insert(channelContracts).values(data).returning();
|
|
32
|
+
return row;
|
|
33
|
+
},
|
|
34
|
+
async updateContract(db, id, data) {
|
|
35
|
+
const [row] = await db
|
|
36
|
+
.update(channelContracts)
|
|
37
|
+
.set({ ...data, updatedAt: new Date() })
|
|
38
|
+
.where(eq(channelContracts.id, id))
|
|
39
|
+
.returning();
|
|
40
|
+
return row ?? null;
|
|
41
|
+
},
|
|
42
|
+
async deleteContract(db, id) {
|
|
43
|
+
const [row] = await db
|
|
44
|
+
.delete(channelContracts)
|
|
45
|
+
.where(eq(channelContracts.id, id))
|
|
46
|
+
.returning({ id: channelContracts.id });
|
|
47
|
+
return row ?? null;
|
|
48
|
+
},
|
|
49
|
+
async listCommissionRules(db, query) {
|
|
50
|
+
const conditions = [];
|
|
51
|
+
if (query.contractId)
|
|
52
|
+
conditions.push(eq(channelCommissionRules.contractId, query.contractId));
|
|
53
|
+
if (query.productId)
|
|
54
|
+
conditions.push(eq(channelCommissionRules.productId, query.productId));
|
|
55
|
+
if (query.scope)
|
|
56
|
+
conditions.push(eq(channelCommissionRules.scope, query.scope));
|
|
57
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
58
|
+
return paginate(db
|
|
59
|
+
.select()
|
|
60
|
+
.from(channelCommissionRules)
|
|
61
|
+
.where(where)
|
|
62
|
+
.limit(query.limit)
|
|
63
|
+
.offset(query.offset)
|
|
64
|
+
.orderBy(desc(channelCommissionRules.createdAt)), db.select({ count: sql `count(*)::int` }).from(channelCommissionRules).where(where), query.limit, query.offset);
|
|
65
|
+
},
|
|
66
|
+
async getCommissionRuleById(db, id) {
|
|
67
|
+
const [row] = await db
|
|
68
|
+
.select()
|
|
69
|
+
.from(channelCommissionRules)
|
|
70
|
+
.where(eq(channelCommissionRules.id, id))
|
|
71
|
+
.limit(1);
|
|
72
|
+
return row ?? null;
|
|
73
|
+
},
|
|
74
|
+
async createCommissionRule(db, data) {
|
|
75
|
+
const [row] = await db.insert(channelCommissionRules).values(data).returning();
|
|
76
|
+
return row;
|
|
77
|
+
},
|
|
78
|
+
async updateCommissionRule(db, id, data) {
|
|
79
|
+
const [row] = await db
|
|
80
|
+
.update(channelCommissionRules)
|
|
81
|
+
.set({ ...data, updatedAt: new Date() })
|
|
82
|
+
.where(eq(channelCommissionRules.id, id))
|
|
83
|
+
.returning();
|
|
84
|
+
return row ?? null;
|
|
85
|
+
},
|
|
86
|
+
async deleteCommissionRule(db, id) {
|
|
87
|
+
const [row] = await db
|
|
88
|
+
.delete(channelCommissionRules)
|
|
89
|
+
.where(eq(channelCommissionRules.id, id))
|
|
90
|
+
.returning({ id: channelCommissionRules.id });
|
|
91
|
+
return row ?? null;
|
|
92
|
+
},
|
|
93
|
+
async listProductMappings(db, query) {
|
|
94
|
+
const conditions = [];
|
|
95
|
+
if (query.channelId)
|
|
96
|
+
conditions.push(eq(channelProductMappings.channelId, query.channelId));
|
|
97
|
+
if (query.productId)
|
|
98
|
+
conditions.push(eq(channelProductMappings.productId, query.productId));
|
|
99
|
+
if (query.active !== undefined)
|
|
100
|
+
conditions.push(eq(channelProductMappings.active, query.active));
|
|
101
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
102
|
+
return paginate(db
|
|
103
|
+
.select()
|
|
104
|
+
.from(channelProductMappings)
|
|
105
|
+
.where(where)
|
|
106
|
+
.limit(query.limit)
|
|
107
|
+
.offset(query.offset)
|
|
108
|
+
.orderBy(desc(channelProductMappings.createdAt)), db.select({ count: sql `count(*)::int` }).from(channelProductMappings).where(where), query.limit, query.offset);
|
|
109
|
+
},
|
|
110
|
+
async getProductMappingById(db, id) {
|
|
111
|
+
const [row] = await db
|
|
112
|
+
.select()
|
|
113
|
+
.from(channelProductMappings)
|
|
114
|
+
.where(eq(channelProductMappings.id, id))
|
|
115
|
+
.limit(1);
|
|
116
|
+
return row ?? null;
|
|
117
|
+
},
|
|
118
|
+
async createProductMapping(db, data) {
|
|
119
|
+
const [row] = await db.insert(channelProductMappings).values(data).returning();
|
|
120
|
+
return row;
|
|
121
|
+
},
|
|
122
|
+
async updateProductMapping(db, id, data) {
|
|
123
|
+
const [row] = await db
|
|
124
|
+
.update(channelProductMappings)
|
|
125
|
+
.set({ ...data, updatedAt: new Date() })
|
|
126
|
+
.where(eq(channelProductMappings.id, id))
|
|
127
|
+
.returning();
|
|
128
|
+
return row ?? null;
|
|
129
|
+
},
|
|
130
|
+
async deleteProductMapping(db, id) {
|
|
131
|
+
const [row] = await db
|
|
132
|
+
.delete(channelProductMappings)
|
|
133
|
+
.where(eq(channelProductMappings.id, id))
|
|
134
|
+
.returning({ id: channelProductMappings.id });
|
|
135
|
+
return row ?? null;
|
|
136
|
+
},
|
|
137
|
+
async listBookingLinks(db, query) {
|
|
138
|
+
const conditions = [];
|
|
139
|
+
if (query.channelId)
|
|
140
|
+
conditions.push(eq(channelBookingLinks.channelId, query.channelId));
|
|
141
|
+
if (query.bookingId)
|
|
142
|
+
conditions.push(eq(channelBookingLinks.bookingId, query.bookingId));
|
|
143
|
+
if (query.externalBookingId)
|
|
144
|
+
conditions.push(eq(channelBookingLinks.externalBookingId, query.externalBookingId));
|
|
145
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
146
|
+
return paginate(db
|
|
147
|
+
.select()
|
|
148
|
+
.from(channelBookingLinks)
|
|
149
|
+
.where(where)
|
|
150
|
+
.limit(query.limit)
|
|
151
|
+
.offset(query.offset)
|
|
152
|
+
.orderBy(desc(channelBookingLinks.createdAt)), db.select({ count: sql `count(*)::int` }).from(channelBookingLinks).where(where), query.limit, query.offset);
|
|
153
|
+
},
|
|
154
|
+
async getBookingLinkById(db, id) {
|
|
155
|
+
const [row] = await db
|
|
156
|
+
.select()
|
|
157
|
+
.from(channelBookingLinks)
|
|
158
|
+
.where(eq(channelBookingLinks.id, id))
|
|
159
|
+
.limit(1);
|
|
160
|
+
return row ?? null;
|
|
161
|
+
},
|
|
162
|
+
async createBookingLink(db, data) {
|
|
163
|
+
const [row] = await db
|
|
164
|
+
.insert(channelBookingLinks)
|
|
165
|
+
.values({
|
|
166
|
+
...data,
|
|
167
|
+
bookedAtExternal: toDateOrNull(data.bookedAtExternal),
|
|
168
|
+
lastSyncedAt: toDateOrNull(data.lastSyncedAt),
|
|
169
|
+
})
|
|
170
|
+
.returning();
|
|
171
|
+
return row;
|
|
172
|
+
},
|
|
173
|
+
async updateBookingLink(db, id, data) {
|
|
174
|
+
const [row] = await db
|
|
175
|
+
.update(channelBookingLinks)
|
|
176
|
+
.set({
|
|
177
|
+
...data,
|
|
178
|
+
bookedAtExternal: data.bookedAtExternal === undefined ? undefined : toDateOrNull(data.bookedAtExternal),
|
|
179
|
+
lastSyncedAt: data.lastSyncedAt === undefined ? undefined : toDateOrNull(data.lastSyncedAt),
|
|
180
|
+
updatedAt: new Date(),
|
|
181
|
+
})
|
|
182
|
+
.where(eq(channelBookingLinks.id, id))
|
|
183
|
+
.returning();
|
|
184
|
+
return row ?? null;
|
|
185
|
+
},
|
|
186
|
+
async deleteBookingLink(db, id) {
|
|
187
|
+
const [row] = await db
|
|
188
|
+
.delete(channelBookingLinks)
|
|
189
|
+
.where(eq(channelBookingLinks.id, id))
|
|
190
|
+
.returning({ id: channelBookingLinks.id });
|
|
191
|
+
return row ?? null;
|
|
192
|
+
},
|
|
193
|
+
async listWebhookEvents(db, query) {
|
|
194
|
+
const conditions = [];
|
|
195
|
+
if (query.channelId)
|
|
196
|
+
conditions.push(eq(channelWebhookEvents.channelId, query.channelId));
|
|
197
|
+
if (query.status)
|
|
198
|
+
conditions.push(eq(channelWebhookEvents.status, query.status));
|
|
199
|
+
if (query.eventType)
|
|
200
|
+
conditions.push(eq(channelWebhookEvents.eventType, query.eventType));
|
|
201
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
202
|
+
return paginate(db
|
|
203
|
+
.select()
|
|
204
|
+
.from(channelWebhookEvents)
|
|
205
|
+
.where(where)
|
|
206
|
+
.limit(query.limit)
|
|
207
|
+
.offset(query.offset)
|
|
208
|
+
.orderBy(desc(channelWebhookEvents.receivedAt)), db.select({ count: sql `count(*)::int` }).from(channelWebhookEvents).where(where), query.limit, query.offset);
|
|
209
|
+
},
|
|
210
|
+
async getWebhookEventById(db, id) {
|
|
211
|
+
const [row] = await db
|
|
212
|
+
.select()
|
|
213
|
+
.from(channelWebhookEvents)
|
|
214
|
+
.where(eq(channelWebhookEvents.id, id))
|
|
215
|
+
.limit(1);
|
|
216
|
+
return row ?? null;
|
|
217
|
+
},
|
|
218
|
+
async createWebhookEvent(db, data) {
|
|
219
|
+
const [row] = await db
|
|
220
|
+
.insert(channelWebhookEvents)
|
|
221
|
+
.values({
|
|
222
|
+
...data,
|
|
223
|
+
receivedAt: toDateOrNull(data.receivedAt) ?? new Date(),
|
|
224
|
+
processedAt: toDateOrNull(data.processedAt),
|
|
225
|
+
})
|
|
226
|
+
.returning();
|
|
227
|
+
return row;
|
|
228
|
+
},
|
|
229
|
+
async updateWebhookEvent(db, id, data) {
|
|
230
|
+
const [row] = await db
|
|
231
|
+
.update(channelWebhookEvents)
|
|
232
|
+
.set({
|
|
233
|
+
...data,
|
|
234
|
+
receivedAt: data.receivedAt ? new Date(data.receivedAt) : undefined,
|
|
235
|
+
processedAt: data.processedAt === undefined ? undefined : toDateOrNull(data.processedAt),
|
|
236
|
+
})
|
|
237
|
+
.where(eq(channelWebhookEvents.id, id))
|
|
238
|
+
.returning();
|
|
239
|
+
return row ?? null;
|
|
240
|
+
},
|
|
241
|
+
async deleteWebhookEvent(db, id) {
|
|
242
|
+
const [row] = await db
|
|
243
|
+
.delete(channelWebhookEvents)
|
|
244
|
+
.where(eq(channelWebhookEvents.id, id))
|
|
245
|
+
.returning({ id: channelWebhookEvents.id });
|
|
246
|
+
return row ?? null;
|
|
247
|
+
},
|
|
248
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function paginate<T extends object>(rowsQuery: Promise<T[]>, countQuery: Promise<Array<{
|
|
2
|
+
count: number;
|
|
3
|
+
}>>, limit: number, offset: number): Promise<{
|
|
4
|
+
data: T[];
|
|
5
|
+
total: number;
|
|
6
|
+
limit: number;
|
|
7
|
+
offset: number;
|
|
8
|
+
}>;
|
|
9
|
+
export declare function toDateOrNull(value: string | null | undefined): Date | null;
|
|
10
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../src/service/helpers.ts"],"names":[],"mappings":"AAAA,wBAAsB,QAAQ,CAAC,CAAC,SAAS,MAAM,EAC7C,SAAS,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,EACvB,UAAU,EAAE,OAAO,CAAC,KAAK,CAAC;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,EAC7C,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM;;;;;GAIf;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,eAE5D"}
|
|
@@ -0,0 +1,7 @@
|
|
|
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 toDateOrNull(value) {
|
|
6
|
+
return value ? new Date(value) : null;
|
|
7
|
+
}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import type { PostgresJsDatabase } from "drizzle-orm/postgres-js";
|
|
2
|
+
import type { ChannelInventoryAllotmentListQuery, ChannelInventoryAllotmentTargetListQuery, ChannelInventoryReleaseRuleListQuery, CreateChannelInventoryAllotmentInput, CreateChannelInventoryAllotmentTargetInput, CreateChannelInventoryReleaseRuleInput, UpdateChannelInventoryAllotmentInput, UpdateChannelInventoryAllotmentTargetInput, UpdateChannelInventoryReleaseRuleInput } from "./types.js";
|
|
3
|
+
export declare const inventoryServiceOperations: {
|
|
4
|
+
listInventoryAllotments(db: PostgresJsDatabase, query: ChannelInventoryAllotmentListQuery): Promise<{
|
|
5
|
+
data: {
|
|
6
|
+
id: string;
|
|
7
|
+
channelId: string;
|
|
8
|
+
contractId: string | null;
|
|
9
|
+
productId: string;
|
|
10
|
+
optionId: string | null;
|
|
11
|
+
startTimeId: string | null;
|
|
12
|
+
validFrom: string | null;
|
|
13
|
+
validTo: string | null;
|
|
14
|
+
guaranteedCapacity: number | null;
|
|
15
|
+
maxCapacity: number | null;
|
|
16
|
+
active: boolean;
|
|
17
|
+
notes: string | null;
|
|
18
|
+
createdAt: Date;
|
|
19
|
+
updatedAt: Date;
|
|
20
|
+
}[];
|
|
21
|
+
total: number;
|
|
22
|
+
limit: number;
|
|
23
|
+
offset: number;
|
|
24
|
+
}>;
|
|
25
|
+
getInventoryAllotmentById(db: PostgresJsDatabase, id: string): Promise<{
|
|
26
|
+
id: string;
|
|
27
|
+
channelId: string;
|
|
28
|
+
contractId: string | null;
|
|
29
|
+
productId: string;
|
|
30
|
+
optionId: string | null;
|
|
31
|
+
startTimeId: string | null;
|
|
32
|
+
validFrom: string | null;
|
|
33
|
+
validTo: string | null;
|
|
34
|
+
guaranteedCapacity: number | null;
|
|
35
|
+
maxCapacity: number | null;
|
|
36
|
+
active: boolean;
|
|
37
|
+
notes: string | null;
|
|
38
|
+
createdAt: Date;
|
|
39
|
+
updatedAt: Date;
|
|
40
|
+
} | null>;
|
|
41
|
+
createInventoryAllotment(db: PostgresJsDatabase, data: CreateChannelInventoryAllotmentInput): Promise<{
|
|
42
|
+
createdAt: Date;
|
|
43
|
+
updatedAt: Date;
|
|
44
|
+
id: string;
|
|
45
|
+
active: boolean;
|
|
46
|
+
channelId: string;
|
|
47
|
+
productId: string;
|
|
48
|
+
notes: string | null;
|
|
49
|
+
contractId: string | null;
|
|
50
|
+
optionId: string | null;
|
|
51
|
+
startTimeId: string | null;
|
|
52
|
+
validFrom: string | null;
|
|
53
|
+
validTo: string | null;
|
|
54
|
+
guaranteedCapacity: number | null;
|
|
55
|
+
maxCapacity: number | null;
|
|
56
|
+
} | undefined>;
|
|
57
|
+
updateInventoryAllotment(db: PostgresJsDatabase, id: string, data: UpdateChannelInventoryAllotmentInput): Promise<{
|
|
58
|
+
id: string;
|
|
59
|
+
channelId: string;
|
|
60
|
+
contractId: string | null;
|
|
61
|
+
productId: string;
|
|
62
|
+
optionId: string | null;
|
|
63
|
+
startTimeId: string | null;
|
|
64
|
+
validFrom: string | null;
|
|
65
|
+
validTo: string | null;
|
|
66
|
+
guaranteedCapacity: number | null;
|
|
67
|
+
maxCapacity: number | null;
|
|
68
|
+
active: boolean;
|
|
69
|
+
notes: string | null;
|
|
70
|
+
createdAt: Date;
|
|
71
|
+
updatedAt: Date;
|
|
72
|
+
} | null>;
|
|
73
|
+
deleteInventoryAllotment(db: PostgresJsDatabase, id: string): Promise<{
|
|
74
|
+
id: string;
|
|
75
|
+
} | null>;
|
|
76
|
+
listInventoryAllotmentTargets(db: PostgresJsDatabase, query: ChannelInventoryAllotmentTargetListQuery): Promise<{
|
|
77
|
+
data: {
|
|
78
|
+
id: string;
|
|
79
|
+
allotmentId: string;
|
|
80
|
+
slotId: string | null;
|
|
81
|
+
startTimeId: string | null;
|
|
82
|
+
dateLocal: string | null;
|
|
83
|
+
guaranteedCapacity: number | null;
|
|
84
|
+
maxCapacity: number | null;
|
|
85
|
+
soldCapacity: number | null;
|
|
86
|
+
remainingCapacity: number | null;
|
|
87
|
+
active: boolean;
|
|
88
|
+
createdAt: Date;
|
|
89
|
+
updatedAt: Date;
|
|
90
|
+
}[];
|
|
91
|
+
total: number;
|
|
92
|
+
limit: number;
|
|
93
|
+
offset: number;
|
|
94
|
+
}>;
|
|
95
|
+
getInventoryAllotmentTargetById(db: PostgresJsDatabase, id: string): Promise<{
|
|
96
|
+
id: string;
|
|
97
|
+
allotmentId: string;
|
|
98
|
+
slotId: string | null;
|
|
99
|
+
startTimeId: string | null;
|
|
100
|
+
dateLocal: string | null;
|
|
101
|
+
guaranteedCapacity: number | null;
|
|
102
|
+
maxCapacity: number | null;
|
|
103
|
+
soldCapacity: number | null;
|
|
104
|
+
remainingCapacity: number | null;
|
|
105
|
+
active: boolean;
|
|
106
|
+
createdAt: Date;
|
|
107
|
+
updatedAt: Date;
|
|
108
|
+
} | null>;
|
|
109
|
+
createInventoryAllotmentTarget(db: PostgresJsDatabase, data: CreateChannelInventoryAllotmentTargetInput): Promise<{
|
|
110
|
+
createdAt: Date;
|
|
111
|
+
updatedAt: Date;
|
|
112
|
+
id: string;
|
|
113
|
+
active: boolean;
|
|
114
|
+
startTimeId: string | null;
|
|
115
|
+
guaranteedCapacity: number | null;
|
|
116
|
+
maxCapacity: number | null;
|
|
117
|
+
slotId: string | null;
|
|
118
|
+
allotmentId: string;
|
|
119
|
+
dateLocal: string | null;
|
|
120
|
+
soldCapacity: number | null;
|
|
121
|
+
remainingCapacity: number | null;
|
|
122
|
+
} | undefined>;
|
|
123
|
+
updateInventoryAllotmentTarget(db: PostgresJsDatabase, id: string, data: UpdateChannelInventoryAllotmentTargetInput): Promise<{
|
|
124
|
+
id: string;
|
|
125
|
+
allotmentId: string;
|
|
126
|
+
slotId: string | null;
|
|
127
|
+
startTimeId: string | null;
|
|
128
|
+
dateLocal: string | null;
|
|
129
|
+
guaranteedCapacity: number | null;
|
|
130
|
+
maxCapacity: number | null;
|
|
131
|
+
soldCapacity: number | null;
|
|
132
|
+
remainingCapacity: number | null;
|
|
133
|
+
active: boolean;
|
|
134
|
+
createdAt: Date;
|
|
135
|
+
updatedAt: Date;
|
|
136
|
+
} | null>;
|
|
137
|
+
deleteInventoryAllotmentTarget(db: PostgresJsDatabase, id: string): Promise<{
|
|
138
|
+
id: string;
|
|
139
|
+
} | null>;
|
|
140
|
+
listInventoryReleaseRules(db: PostgresJsDatabase, query: ChannelInventoryReleaseRuleListQuery): Promise<{
|
|
141
|
+
data: {
|
|
142
|
+
id: string;
|
|
143
|
+
allotmentId: string;
|
|
144
|
+
releaseMode: "manual" | "automatic";
|
|
145
|
+
releaseDaysBeforeStart: number | null;
|
|
146
|
+
releaseHoursBeforeStart: number | null;
|
|
147
|
+
unsoldAction: "release_to_general_pool" | "expire" | "retain";
|
|
148
|
+
notes: string | null;
|
|
149
|
+
createdAt: Date;
|
|
150
|
+
updatedAt: Date;
|
|
151
|
+
}[];
|
|
152
|
+
total: number;
|
|
153
|
+
limit: number;
|
|
154
|
+
offset: number;
|
|
155
|
+
}>;
|
|
156
|
+
getInventoryReleaseRuleById(db: PostgresJsDatabase, id: string): Promise<{
|
|
157
|
+
id: string;
|
|
158
|
+
allotmentId: string;
|
|
159
|
+
releaseMode: "manual" | "automatic";
|
|
160
|
+
releaseDaysBeforeStart: number | null;
|
|
161
|
+
releaseHoursBeforeStart: number | null;
|
|
162
|
+
unsoldAction: "release_to_general_pool" | "expire" | "retain";
|
|
163
|
+
notes: string | null;
|
|
164
|
+
createdAt: Date;
|
|
165
|
+
updatedAt: Date;
|
|
166
|
+
} | null>;
|
|
167
|
+
createInventoryReleaseRule(db: PostgresJsDatabase, data: CreateChannelInventoryReleaseRuleInput): Promise<{
|
|
168
|
+
createdAt: Date;
|
|
169
|
+
updatedAt: Date;
|
|
170
|
+
id: string;
|
|
171
|
+
notes: string | null;
|
|
172
|
+
allotmentId: string;
|
|
173
|
+
releaseMode: "manual" | "automatic";
|
|
174
|
+
releaseDaysBeforeStart: number | null;
|
|
175
|
+
releaseHoursBeforeStart: number | null;
|
|
176
|
+
unsoldAction: "release_to_general_pool" | "expire" | "retain";
|
|
177
|
+
} | undefined>;
|
|
178
|
+
updateInventoryReleaseRule(db: PostgresJsDatabase, id: string, data: UpdateChannelInventoryReleaseRuleInput): Promise<{
|
|
179
|
+
id: string;
|
|
180
|
+
allotmentId: string;
|
|
181
|
+
releaseMode: "manual" | "automatic";
|
|
182
|
+
releaseDaysBeforeStart: number | null;
|
|
183
|
+
releaseHoursBeforeStart: number | null;
|
|
184
|
+
unsoldAction: "release_to_general_pool" | "expire" | "retain";
|
|
185
|
+
notes: string | null;
|
|
186
|
+
createdAt: Date;
|
|
187
|
+
updatedAt: Date;
|
|
188
|
+
} | null>;
|
|
189
|
+
deleteInventoryReleaseRule(db: PostgresJsDatabase, id: string): Promise<{
|
|
190
|
+
id: string;
|
|
191
|
+
} | null>;
|
|
192
|
+
};
|
|
193
|
+
//# sourceMappingURL=inventory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inventory.d.ts","sourceRoot":"","sources":["../../src/service/inventory.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAQjE,OAAO,KAAK,EACV,kCAAkC,EAClC,wCAAwC,EACxC,oCAAoC,EACpC,oCAAoC,EACpC,0CAA0C,EAC1C,sCAAsC,EACtC,oCAAoC,EACpC,0CAA0C,EAC1C,sCAAsC,EACvC,MAAM,YAAY,CAAA;AAEnB,eAAO,MAAM,0BAA0B;gCACH,kBAAkB,SAAS,kCAAkC;;;;;;;;;;;;;;;;;;;;;kCA6B3D,kBAAkB,MAAM,MAAM;;;;;;;;;;;;;;;;iCAU5D,kBAAkB,QAChB,oCAAoC;;;;;;;;;;;;;;;;iCAOtC,kBAAkB,MAClB,MAAM,QACJ,oCAAoC;;;;;;;;;;;;;;;;iCAUT,kBAAkB,MAAM,MAAM;;;sCAS3D,kBAAkB,SACf,wCAAwC;;;;;;;;;;;;;;;;;;;wCA8BP,kBAAkB,MAAM,MAAM;;;;;;;;;;;;;;uCAUlE,kBAAkB,QAChB,0CAA0C;;;;;;;;;;;;;;uCAO5C,kBAAkB,MAClB,MAAM,QACJ,0CAA0C;;;;;;;;;;;;;;uCAUT,kBAAkB,MAAM,MAAM;;;kCASjE,kBAAkB,SACf,oCAAoC;;;;;;;;;;;;;;;;oCAyBP,kBAAkB,MAAM,MAAM;;;;;;;;;;;mCAU9D,kBAAkB,QAChB,sCAAsC;;;;;;;;;;;mCAOxC,kBAAkB,MAClB,MAAM,QACJ,sCAAsC;;;;;;;;;;;mCAUT,kBAAkB,MAAM,MAAM;;;CAOpE,CAAA"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { and, desc, eq, sql } from "drizzle-orm";
|
|
2
|
+
import { channelInventoryAllotments, channelInventoryAllotmentTargets, channelInventoryReleaseRules, } from "../schema.js";
|
|
3
|
+
import { paginate } from "./helpers.js";
|
|
4
|
+
export const inventoryServiceOperations = {
|
|
5
|
+
async listInventoryAllotments(db, query) {
|
|
6
|
+
const conditions = [];
|
|
7
|
+
if (query.channelId)
|
|
8
|
+
conditions.push(eq(channelInventoryAllotments.channelId, query.channelId));
|
|
9
|
+
if (query.contractId)
|
|
10
|
+
conditions.push(eq(channelInventoryAllotments.contractId, query.contractId));
|
|
11
|
+
if (query.productId)
|
|
12
|
+
conditions.push(eq(channelInventoryAllotments.productId, query.productId));
|
|
13
|
+
if (query.optionId)
|
|
14
|
+
conditions.push(eq(channelInventoryAllotments.optionId, query.optionId));
|
|
15
|
+
if (query.startTimeId)
|
|
16
|
+
conditions.push(eq(channelInventoryAllotments.startTimeId, query.startTimeId));
|
|
17
|
+
if (query.active !== undefined)
|
|
18
|
+
conditions.push(eq(channelInventoryAllotments.active, query.active));
|
|
19
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
20
|
+
return paginate(db
|
|
21
|
+
.select()
|
|
22
|
+
.from(channelInventoryAllotments)
|
|
23
|
+
.where(where)
|
|
24
|
+
.limit(query.limit)
|
|
25
|
+
.offset(query.offset)
|
|
26
|
+
.orderBy(desc(channelInventoryAllotments.updatedAt)), db
|
|
27
|
+
.select({ count: sql `count(*)::int` })
|
|
28
|
+
.from(channelInventoryAllotments)
|
|
29
|
+
.where(where), query.limit, query.offset);
|
|
30
|
+
},
|
|
31
|
+
async getInventoryAllotmentById(db, id) {
|
|
32
|
+
const [row] = await db
|
|
33
|
+
.select()
|
|
34
|
+
.from(channelInventoryAllotments)
|
|
35
|
+
.where(eq(channelInventoryAllotments.id, id))
|
|
36
|
+
.limit(1);
|
|
37
|
+
return row ?? null;
|
|
38
|
+
},
|
|
39
|
+
async createInventoryAllotment(db, data) {
|
|
40
|
+
const [row] = await db.insert(channelInventoryAllotments).values(data).returning();
|
|
41
|
+
return row;
|
|
42
|
+
},
|
|
43
|
+
async updateInventoryAllotment(db, id, data) {
|
|
44
|
+
const [row] = await db
|
|
45
|
+
.update(channelInventoryAllotments)
|
|
46
|
+
.set({ ...data, updatedAt: new Date() })
|
|
47
|
+
.where(eq(channelInventoryAllotments.id, id))
|
|
48
|
+
.returning();
|
|
49
|
+
return row ?? null;
|
|
50
|
+
},
|
|
51
|
+
async deleteInventoryAllotment(db, id) {
|
|
52
|
+
const [row] = await db
|
|
53
|
+
.delete(channelInventoryAllotments)
|
|
54
|
+
.where(eq(channelInventoryAllotments.id, id))
|
|
55
|
+
.returning({ id: channelInventoryAllotments.id });
|
|
56
|
+
return row ?? null;
|
|
57
|
+
},
|
|
58
|
+
async listInventoryAllotmentTargets(db, query) {
|
|
59
|
+
const conditions = [];
|
|
60
|
+
if (query.allotmentId)
|
|
61
|
+
conditions.push(eq(channelInventoryAllotmentTargets.allotmentId, query.allotmentId));
|
|
62
|
+
if (query.slotId)
|
|
63
|
+
conditions.push(eq(channelInventoryAllotmentTargets.slotId, query.slotId));
|
|
64
|
+
if (query.startTimeId)
|
|
65
|
+
conditions.push(eq(channelInventoryAllotmentTargets.startTimeId, query.startTimeId));
|
|
66
|
+
if (query.dateLocal)
|
|
67
|
+
conditions.push(eq(channelInventoryAllotmentTargets.dateLocal, query.dateLocal));
|
|
68
|
+
if (query.active !== undefined)
|
|
69
|
+
conditions.push(eq(channelInventoryAllotmentTargets.active, query.active));
|
|
70
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
71
|
+
return paginate(db
|
|
72
|
+
.select()
|
|
73
|
+
.from(channelInventoryAllotmentTargets)
|
|
74
|
+
.where(where)
|
|
75
|
+
.limit(query.limit)
|
|
76
|
+
.offset(query.offset)
|
|
77
|
+
.orderBy(desc(channelInventoryAllotmentTargets.updatedAt)), db
|
|
78
|
+
.select({ count: sql `count(*)::int` })
|
|
79
|
+
.from(channelInventoryAllotmentTargets)
|
|
80
|
+
.where(where), query.limit, query.offset);
|
|
81
|
+
},
|
|
82
|
+
async getInventoryAllotmentTargetById(db, id) {
|
|
83
|
+
const [row] = await db
|
|
84
|
+
.select()
|
|
85
|
+
.from(channelInventoryAllotmentTargets)
|
|
86
|
+
.where(eq(channelInventoryAllotmentTargets.id, id))
|
|
87
|
+
.limit(1);
|
|
88
|
+
return row ?? null;
|
|
89
|
+
},
|
|
90
|
+
async createInventoryAllotmentTarget(db, data) {
|
|
91
|
+
const [row] = await db.insert(channelInventoryAllotmentTargets).values(data).returning();
|
|
92
|
+
return row;
|
|
93
|
+
},
|
|
94
|
+
async updateInventoryAllotmentTarget(db, id, data) {
|
|
95
|
+
const [row] = await db
|
|
96
|
+
.update(channelInventoryAllotmentTargets)
|
|
97
|
+
.set({ ...data, updatedAt: new Date() })
|
|
98
|
+
.where(eq(channelInventoryAllotmentTargets.id, id))
|
|
99
|
+
.returning();
|
|
100
|
+
return row ?? null;
|
|
101
|
+
},
|
|
102
|
+
async deleteInventoryAllotmentTarget(db, id) {
|
|
103
|
+
const [row] = await db
|
|
104
|
+
.delete(channelInventoryAllotmentTargets)
|
|
105
|
+
.where(eq(channelInventoryAllotmentTargets.id, id))
|
|
106
|
+
.returning({ id: channelInventoryAllotmentTargets.id });
|
|
107
|
+
return row ?? null;
|
|
108
|
+
},
|
|
109
|
+
async listInventoryReleaseRules(db, query) {
|
|
110
|
+
const conditions = [];
|
|
111
|
+
if (query.allotmentId)
|
|
112
|
+
conditions.push(eq(channelInventoryReleaseRules.allotmentId, query.allotmentId));
|
|
113
|
+
if (query.releaseMode)
|
|
114
|
+
conditions.push(eq(channelInventoryReleaseRules.releaseMode, query.releaseMode));
|
|
115
|
+
const where = conditions.length ? and(...conditions) : undefined;
|
|
116
|
+
return paginate(db
|
|
117
|
+
.select()
|
|
118
|
+
.from(channelInventoryReleaseRules)
|
|
119
|
+
.where(where)
|
|
120
|
+
.limit(query.limit)
|
|
121
|
+
.offset(query.offset)
|
|
122
|
+
.orderBy(desc(channelInventoryReleaseRules.updatedAt)), db
|
|
123
|
+
.select({ count: sql `count(*)::int` })
|
|
124
|
+
.from(channelInventoryReleaseRules)
|
|
125
|
+
.where(where), query.limit, query.offset);
|
|
126
|
+
},
|
|
127
|
+
async getInventoryReleaseRuleById(db, id) {
|
|
128
|
+
const [row] = await db
|
|
129
|
+
.select()
|
|
130
|
+
.from(channelInventoryReleaseRules)
|
|
131
|
+
.where(eq(channelInventoryReleaseRules.id, id))
|
|
132
|
+
.limit(1);
|
|
133
|
+
return row ?? null;
|
|
134
|
+
},
|
|
135
|
+
async createInventoryReleaseRule(db, data) {
|
|
136
|
+
const [row] = await db.insert(channelInventoryReleaseRules).values(data).returning();
|
|
137
|
+
return row;
|
|
138
|
+
},
|
|
139
|
+
async updateInventoryReleaseRule(db, id, data) {
|
|
140
|
+
const [row] = await db
|
|
141
|
+
.update(channelInventoryReleaseRules)
|
|
142
|
+
.set({ ...data, updatedAt: new Date() })
|
|
143
|
+
.where(eq(channelInventoryReleaseRules.id, id))
|
|
144
|
+
.returning();
|
|
145
|
+
return row ?? null;
|
|
146
|
+
},
|
|
147
|
+
async deleteInventoryReleaseRule(db, id) {
|
|
148
|
+
const [row] = await db
|
|
149
|
+
.delete(channelInventoryReleaseRules)
|
|
150
|
+
.where(eq(channelInventoryReleaseRules.id, id))
|
|
151
|
+
.returning({ id: channelInventoryReleaseRules.id });
|
|
152
|
+
return row ?? null;
|
|
153
|
+
},
|
|
154
|
+
};
|