@voyantjs/distribution 0.5.0 → 0.6.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.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { parseJsonBody, parseQuery } from "@voyantjs/hono";
1
2
  import { insertContactPointForEntitySchema, insertNamedContactForEntitySchema, updateContactPointSchema as updateIdentityContactPointSchema, updateNamedContactSchema as updateIdentityNamedContactSchema, } from "@voyantjs/identity/validation";
2
3
  import { Hono } from "hono";
3
4
  import { z } from "zod";
@@ -55,16 +56,16 @@ async function handleBatchDelete({ db, ids, remove, }) {
55
56
  }
56
57
  export const distributionRoutes = new Hono()
57
58
  .get("/channels", async (c) => {
58
- const query = channelListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
59
+ const query = await parseQuery(c, channelListQuerySchema);
59
60
  return c.json(await distributionService.listChannels(c.get("db"), query));
60
61
  })
61
62
  .post("/channels", async (c) => {
62
63
  return c.json({
63
- data: await distributionService.createChannel(c.get("db"), insertChannelSchema.parse(await c.req.json())),
64
+ data: await distributionService.createChannel(c.get("db"), await parseJsonBody(c, insertChannelSchema)),
64
65
  }, 201);
65
66
  })
66
67
  .post("/channels/batch-update", async (c) => {
67
- const body = batchUpdateChannelSchema.parse(await c.req.json());
68
+ const body = await parseJsonBody(c, batchUpdateChannelSchema);
68
69
  return c.json(await handleBatchUpdate({
69
70
  db: c.get("db"),
70
71
  ids: body.ids,
@@ -73,7 +74,7 @@ export const distributionRoutes = new Hono()
73
74
  }));
74
75
  })
75
76
  .post("/channels/batch-delete", async (c) => {
76
- const body = batchIdsSchema.parse(await c.req.json());
77
+ const body = await parseJsonBody(c, batchIdsSchema);
77
78
  return c.json(await handleBatchDelete({
78
79
  db: c.get("db"),
79
80
  ids: body.ids,
@@ -87,7 +88,7 @@ export const distributionRoutes = new Hono()
87
88
  return c.json({ data: row });
88
89
  })
89
90
  .patch("/channels/:id", async (c) => {
90
- const row = await distributionService.updateChannel(c.get("db"), c.req.param("id"), updateChannelSchema.parse(await c.req.json()));
91
+ const row = await distributionService.updateChannel(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateChannelSchema));
91
92
  if (!row)
92
93
  return c.json({ error: "Channel not found" }, 404);
93
94
  return c.json({ data: row });
@@ -105,13 +106,13 @@ export const distributionRoutes = new Hono()
105
106
  return c.json({ data: rows });
106
107
  })
107
108
  .post("/channels/:id/contact-points", async (c) => {
108
- const row = await distributionService.createChannelContactPoint(c.get("db"), c.req.param("id"), insertContactPointForEntitySchema.parse(await c.req.json()));
109
+ const row = await distributionService.createChannelContactPoint(c.get("db"), c.req.param("id"), await parseJsonBody(c, insertContactPointForEntitySchema));
109
110
  if (!row)
110
111
  return c.json({ error: "Channel not found" }, 404);
111
112
  return c.json({ data: row }, 201);
112
113
  })
113
114
  .patch("/channel-contact-points/:contactPointId", async (c) => {
114
- const row = await distributionService.updateChannelContactPoint(c.get("db"), c.req.param("contactPointId"), updateIdentityContactPointSchema.parse(await c.req.json()));
115
+ const row = await distributionService.updateChannelContactPoint(c.get("db"), c.req.param("contactPointId"), await parseJsonBody(c, updateIdentityContactPointSchema));
115
116
  if (!row)
116
117
  return c.json({ error: "Channel contact point not found" }, 404);
117
118
  return c.json({ data: row });
@@ -129,13 +130,13 @@ export const distributionRoutes = new Hono()
129
130
  return c.json({ data: rows });
130
131
  })
131
132
  .post("/channels/:id/contacts", async (c) => {
132
- const row = await distributionService.createChannelContact(c.get("db"), c.req.param("id"), insertNamedContactForEntitySchema.parse(await c.req.json()));
133
+ const row = await distributionService.createChannelContact(c.get("db"), c.req.param("id"), await parseJsonBody(c, insertNamedContactForEntitySchema));
133
134
  if (!row)
134
135
  return c.json({ error: "Channel not found" }, 404);
135
136
  return c.json({ data: row }, 201);
136
137
  })
137
138
  .patch("/channel-contacts/:contactId", async (c) => {
138
- const row = await distributionService.updateChannelContact(c.get("db"), c.req.param("contactId"), updateIdentityNamedContactSchema.parse(await c.req.json()));
139
+ const row = await distributionService.updateChannelContact(c.get("db"), c.req.param("contactId"), await parseJsonBody(c, updateIdentityNamedContactSchema));
139
140
  if (!row)
140
141
  return c.json({ error: "Channel contact not found" }, 404);
141
142
  return c.json({ data: row });
@@ -147,16 +148,16 @@ export const distributionRoutes = new Hono()
147
148
  return c.json({ success: true });
148
149
  })
149
150
  .get("/contracts", async (c) => {
150
- const query = channelContractListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
151
+ const query = await parseQuery(c, channelContractListQuerySchema);
151
152
  return c.json(await distributionService.listContracts(c.get("db"), query));
152
153
  })
153
154
  .post("/contracts", async (c) => {
154
155
  return c.json({
155
- data: await distributionService.createContract(c.get("db"), insertChannelContractSchema.parse(await c.req.json())),
156
+ data: await distributionService.createContract(c.get("db"), await parseJsonBody(c, insertChannelContractSchema)),
156
157
  }, 201);
157
158
  })
158
159
  .post("/contracts/batch-update", async (c) => {
159
- const body = batchUpdateChannelContractSchema.parse(await c.req.json());
160
+ const body = await parseJsonBody(c, batchUpdateChannelContractSchema);
160
161
  return c.json(await handleBatchUpdate({
161
162
  db: c.get("db"),
162
163
  ids: body.ids,
@@ -165,7 +166,7 @@ export const distributionRoutes = new Hono()
165
166
  }));
166
167
  })
167
168
  .post("/contracts/batch-delete", async (c) => {
168
- const body = batchIdsSchema.parse(await c.req.json());
169
+ const body = await parseJsonBody(c, batchIdsSchema);
169
170
  return c.json(await handleBatchDelete({
170
171
  db: c.get("db"),
171
172
  ids: body.ids,
@@ -179,7 +180,7 @@ export const distributionRoutes = new Hono()
179
180
  return c.json({ data: row });
180
181
  })
181
182
  .patch("/contracts/:id", async (c) => {
182
- const row = await distributionService.updateContract(c.get("db"), c.req.param("id"), updateChannelContractSchema.parse(await c.req.json()));
183
+ const row = await distributionService.updateContract(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateChannelContractSchema));
183
184
  if (!row)
184
185
  return c.json({ error: "Channel contract not found" }, 404);
185
186
  return c.json({ data: row });
@@ -191,16 +192,16 @@ export const distributionRoutes = new Hono()
191
192
  return c.json({ success: true });
192
193
  })
193
194
  .get("/commission-rules", async (c) => {
194
- const query = channelCommissionRuleListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
195
+ const query = await parseQuery(c, channelCommissionRuleListQuerySchema);
195
196
  return c.json(await distributionService.listCommissionRules(c.get("db"), query));
196
197
  })
197
198
  .post("/commission-rules", async (c) => {
198
199
  return c.json({
199
- data: await distributionService.createCommissionRule(c.get("db"), insertChannelCommissionRuleSchema.parse(await c.req.json())),
200
+ data: await distributionService.createCommissionRule(c.get("db"), await parseJsonBody(c, insertChannelCommissionRuleSchema)),
200
201
  }, 201);
201
202
  })
202
203
  .post("/commission-rules/batch-update", async (c) => {
203
- const body = batchUpdateChannelCommissionRuleSchema.parse(await c.req.json());
204
+ const body = await parseJsonBody(c, batchUpdateChannelCommissionRuleSchema);
204
205
  return c.json(await handleBatchUpdate({
205
206
  db: c.get("db"),
206
207
  ids: body.ids,
@@ -209,7 +210,7 @@ export const distributionRoutes = new Hono()
209
210
  }));
210
211
  })
211
212
  .post("/commission-rules/batch-delete", async (c) => {
212
- const body = batchIdsSchema.parse(await c.req.json());
213
+ const body = await parseJsonBody(c, batchIdsSchema);
213
214
  return c.json(await handleBatchDelete({
214
215
  db: c.get("db"),
215
216
  ids: body.ids,
@@ -223,7 +224,7 @@ export const distributionRoutes = new Hono()
223
224
  return c.json({ data: row });
224
225
  })
225
226
  .patch("/commission-rules/:id", async (c) => {
226
- const row = await distributionService.updateCommissionRule(c.get("db"), c.req.param("id"), updateChannelCommissionRuleSchema.parse(await c.req.json()));
227
+ const row = await distributionService.updateCommissionRule(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateChannelCommissionRuleSchema));
227
228
  if (!row)
228
229
  return c.json({ error: "Channel commission rule not found" }, 404);
229
230
  return c.json({ data: row });
@@ -235,16 +236,16 @@ export const distributionRoutes = new Hono()
235
236
  return c.json({ success: true });
236
237
  })
237
238
  .get("/product-mappings", async (c) => {
238
- const query = channelProductMappingListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
239
+ const query = await parseQuery(c, channelProductMappingListQuerySchema);
239
240
  return c.json(await distributionService.listProductMappings(c.get("db"), query));
240
241
  })
241
242
  .post("/product-mappings", async (c) => {
242
243
  return c.json({
243
- data: await distributionService.createProductMapping(c.get("db"), insertChannelProductMappingSchema.parse(await c.req.json())),
244
+ data: await distributionService.createProductMapping(c.get("db"), await parseJsonBody(c, insertChannelProductMappingSchema)),
244
245
  }, 201);
245
246
  })
246
247
  .post("/product-mappings/batch-update", async (c) => {
247
- const body = batchUpdateChannelProductMappingSchema.parse(await c.req.json());
248
+ const body = await parseJsonBody(c, batchUpdateChannelProductMappingSchema);
248
249
  return c.json(await handleBatchUpdate({
249
250
  db: c.get("db"),
250
251
  ids: body.ids,
@@ -253,7 +254,7 @@ export const distributionRoutes = new Hono()
253
254
  }));
254
255
  })
255
256
  .post("/product-mappings/batch-delete", async (c) => {
256
- const body = batchIdsSchema.parse(await c.req.json());
257
+ const body = await parseJsonBody(c, batchIdsSchema);
257
258
  return c.json(await handleBatchDelete({
258
259
  db: c.get("db"),
259
260
  ids: body.ids,
@@ -267,7 +268,7 @@ export const distributionRoutes = new Hono()
267
268
  return c.json({ data: row });
268
269
  })
269
270
  .patch("/product-mappings/:id", async (c) => {
270
- const row = await distributionService.updateProductMapping(c.get("db"), c.req.param("id"), updateChannelProductMappingSchema.parse(await c.req.json()));
271
+ const row = await distributionService.updateProductMapping(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateChannelProductMappingSchema));
271
272
  if (!row)
272
273
  return c.json({ error: "Channel product mapping not found" }, 404);
273
274
  return c.json({ data: row });
@@ -279,16 +280,16 @@ export const distributionRoutes = new Hono()
279
280
  return c.json({ success: true });
280
281
  })
281
282
  .get("/booking-links", async (c) => {
282
- const query = channelBookingLinkListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
283
+ const query = await parseQuery(c, channelBookingLinkListQuerySchema);
283
284
  return c.json(await distributionService.listBookingLinks(c.get("db"), query));
284
285
  })
285
286
  .post("/booking-links", async (c) => {
286
287
  return c.json({
287
- data: await distributionService.createBookingLink(c.get("db"), insertChannelBookingLinkSchema.parse(await c.req.json())),
288
+ data: await distributionService.createBookingLink(c.get("db"), await parseJsonBody(c, insertChannelBookingLinkSchema)),
288
289
  }, 201);
289
290
  })
290
291
  .post("/booking-links/batch-update", async (c) => {
291
- const body = batchUpdateChannelBookingLinkSchema.parse(await c.req.json());
292
+ const body = await parseJsonBody(c, batchUpdateChannelBookingLinkSchema);
292
293
  return c.json(await handleBatchUpdate({
293
294
  db: c.get("db"),
294
295
  ids: body.ids,
@@ -297,7 +298,7 @@ export const distributionRoutes = new Hono()
297
298
  }));
298
299
  })
299
300
  .post("/booking-links/batch-delete", async (c) => {
300
- const body = batchIdsSchema.parse(await c.req.json());
301
+ const body = await parseJsonBody(c, batchIdsSchema);
301
302
  return c.json(await handleBatchDelete({
302
303
  db: c.get("db"),
303
304
  ids: body.ids,
@@ -311,7 +312,7 @@ export const distributionRoutes = new Hono()
311
312
  return c.json({ data: row });
312
313
  })
313
314
  .patch("/booking-links/:id", async (c) => {
314
- const row = await distributionService.updateBookingLink(c.get("db"), c.req.param("id"), updateChannelBookingLinkSchema.parse(await c.req.json()));
315
+ const row = await distributionService.updateBookingLink(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateChannelBookingLinkSchema));
315
316
  if (!row)
316
317
  return c.json({ error: "Channel booking link not found" }, 404);
317
318
  return c.json({ data: row });
@@ -323,16 +324,16 @@ export const distributionRoutes = new Hono()
323
324
  return c.json({ success: true });
324
325
  })
325
326
  .get("/webhook-events", async (c) => {
326
- const query = channelWebhookEventListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
327
+ const query = await parseQuery(c, channelWebhookEventListQuerySchema);
327
328
  return c.json(await distributionService.listWebhookEvents(c.get("db"), query));
328
329
  })
329
330
  .post("/webhook-events", async (c) => {
330
331
  return c.json({
331
- data: await distributionService.createWebhookEvent(c.get("db"), insertChannelWebhookEventSchema.parse(await c.req.json())),
332
+ data: await distributionService.createWebhookEvent(c.get("db"), await parseJsonBody(c, insertChannelWebhookEventSchema)),
332
333
  }, 201);
333
334
  })
334
335
  .post("/webhook-events/batch-update", async (c) => {
335
- const body = batchUpdateChannelWebhookEventSchema.parse(await c.req.json());
336
+ const body = await parseJsonBody(c, batchUpdateChannelWebhookEventSchema);
336
337
  return c.json(await handleBatchUpdate({
337
338
  db: c.get("db"),
338
339
  ids: body.ids,
@@ -341,7 +342,7 @@ export const distributionRoutes = new Hono()
341
342
  }));
342
343
  })
343
344
  .post("/webhook-events/batch-delete", async (c) => {
344
- const body = batchIdsSchema.parse(await c.req.json());
345
+ const body = await parseJsonBody(c, batchIdsSchema);
345
346
  return c.json(await handleBatchDelete({
346
347
  db: c.get("db"),
347
348
  ids: body.ids,
@@ -355,7 +356,7 @@ export const distributionRoutes = new Hono()
355
356
  return c.json({ data: row });
356
357
  })
357
358
  .patch("/webhook-events/:id", async (c) => {
358
- const row = await distributionService.updateWebhookEvent(c.get("db"), c.req.param("id"), updateChannelWebhookEventSchema.parse(await c.req.json()));
359
+ const row = await distributionService.updateWebhookEvent(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateChannelWebhookEventSchema));
359
360
  if (!row)
360
361
  return c.json({ error: "Channel webhook event not found" }, 404);
361
362
  return c.json({ data: row });
@@ -367,16 +368,16 @@ export const distributionRoutes = new Hono()
367
368
  return c.json({ success: true });
368
369
  })
369
370
  .get("/inventory-allotments", async (c) => {
370
- const query = channelInventoryAllotmentListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
371
+ const query = await parseQuery(c, channelInventoryAllotmentListQuerySchema);
371
372
  return c.json(await distributionService.listInventoryAllotments(c.get("db"), query));
372
373
  })
373
374
  .post("/inventory-allotments", async (c) => {
374
375
  return c.json({
375
- data: await distributionService.createInventoryAllotment(c.get("db"), insertChannelInventoryAllotmentSchema.parse(await c.req.json())),
376
+ data: await distributionService.createInventoryAllotment(c.get("db"), await parseJsonBody(c, insertChannelInventoryAllotmentSchema)),
376
377
  }, 201);
377
378
  })
378
379
  .post("/inventory-allotments/batch-update", async (c) => {
379
- const body = batchUpdateChannelInventoryAllotmentSchema.parse(await c.req.json());
380
+ const body = await parseJsonBody(c, batchUpdateChannelInventoryAllotmentSchema);
380
381
  return c.json(await handleBatchUpdate({
381
382
  db: c.get("db"),
382
383
  ids: body.ids,
@@ -385,7 +386,7 @@ export const distributionRoutes = new Hono()
385
386
  }));
386
387
  })
387
388
  .post("/inventory-allotments/batch-delete", async (c) => {
388
- const body = batchIdsSchema.parse(await c.req.json());
389
+ const body = await parseJsonBody(c, batchIdsSchema);
389
390
  return c.json(await handleBatchDelete({
390
391
  db: c.get("db"),
391
392
  ids: body.ids,
@@ -399,7 +400,7 @@ export const distributionRoutes = new Hono()
399
400
  return c.json({ data: row });
400
401
  })
401
402
  .patch("/inventory-allotments/:id", async (c) => {
402
- const row = await distributionService.updateInventoryAllotment(c.get("db"), c.req.param("id"), updateChannelInventoryAllotmentSchema.parse(await c.req.json()));
403
+ const row = await distributionService.updateInventoryAllotment(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateChannelInventoryAllotmentSchema));
403
404
  if (!row)
404
405
  return c.json({ error: "Channel inventory allotment not found" }, 404);
405
406
  return c.json({ data: row });
@@ -411,16 +412,16 @@ export const distributionRoutes = new Hono()
411
412
  return c.json({ success: true });
412
413
  })
413
414
  .get("/inventory-allotment-targets", async (c) => {
414
- const query = channelInventoryAllotmentTargetListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
415
+ const query = await parseQuery(c, channelInventoryAllotmentTargetListQuerySchema);
415
416
  return c.json(await distributionService.listInventoryAllotmentTargets(c.get("db"), query));
416
417
  })
417
418
  .post("/inventory-allotment-targets", async (c) => {
418
419
  return c.json({
419
- data: await distributionService.createInventoryAllotmentTarget(c.get("db"), insertChannelInventoryAllotmentTargetSchema.parse(await c.req.json())),
420
+ data: await distributionService.createInventoryAllotmentTarget(c.get("db"), await parseJsonBody(c, insertChannelInventoryAllotmentTargetSchema)),
420
421
  }, 201);
421
422
  })
422
423
  .post("/inventory-allotment-targets/batch-update", async (c) => {
423
- const body = batchUpdateChannelInventoryAllotmentTargetSchema.parse(await c.req.json());
424
+ const body = await parseJsonBody(c, batchUpdateChannelInventoryAllotmentTargetSchema);
424
425
  return c.json(await handleBatchUpdate({
425
426
  db: c.get("db"),
426
427
  ids: body.ids,
@@ -429,7 +430,7 @@ export const distributionRoutes = new Hono()
429
430
  }));
430
431
  })
431
432
  .post("/inventory-allotment-targets/batch-delete", async (c) => {
432
- const body = batchIdsSchema.parse(await c.req.json());
433
+ const body = await parseJsonBody(c, batchIdsSchema);
433
434
  return c.json(await handleBatchDelete({
434
435
  db: c.get("db"),
435
436
  ids: body.ids,
@@ -443,7 +444,7 @@ export const distributionRoutes = new Hono()
443
444
  return c.json({ data: row });
444
445
  })
445
446
  .patch("/inventory-allotment-targets/:id", async (c) => {
446
- const row = await distributionService.updateInventoryAllotmentTarget(c.get("db"), c.req.param("id"), updateChannelInventoryAllotmentTargetSchema.parse(await c.req.json()));
447
+ const row = await distributionService.updateInventoryAllotmentTarget(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateChannelInventoryAllotmentTargetSchema));
447
448
  if (!row)
448
449
  return c.json({ error: "Channel inventory allotment target not found" }, 404);
449
450
  return c.json({ data: row });
@@ -455,16 +456,16 @@ export const distributionRoutes = new Hono()
455
456
  return c.json({ success: true });
456
457
  })
457
458
  .get("/inventory-release-rules", async (c) => {
458
- const query = channelInventoryReleaseRuleListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
459
+ const query = await parseQuery(c, channelInventoryReleaseRuleListQuerySchema);
459
460
  return c.json(await distributionService.listInventoryReleaseRules(c.get("db"), query));
460
461
  })
461
462
  .post("/inventory-release-rules", async (c) => {
462
463
  return c.json({
463
- data: await distributionService.createInventoryReleaseRule(c.get("db"), insertChannelInventoryReleaseRuleSchema.parse(await c.req.json())),
464
+ data: await distributionService.createInventoryReleaseRule(c.get("db"), await parseJsonBody(c, insertChannelInventoryReleaseRuleSchema)),
464
465
  }, 201);
465
466
  })
466
467
  .post("/inventory-release-rules/batch-update", async (c) => {
467
- const body = batchUpdateChannelInventoryReleaseRuleSchema.parse(await c.req.json());
468
+ const body = await parseJsonBody(c, batchUpdateChannelInventoryReleaseRuleSchema);
468
469
  return c.json(await handleBatchUpdate({
469
470
  db: c.get("db"),
470
471
  ids: body.ids,
@@ -473,7 +474,7 @@ export const distributionRoutes = new Hono()
473
474
  }));
474
475
  })
475
476
  .post("/inventory-release-rules/batch-delete", async (c) => {
476
- const body = batchIdsSchema.parse(await c.req.json());
477
+ const body = await parseJsonBody(c, batchIdsSchema);
477
478
  return c.json(await handleBatchDelete({
478
479
  db: c.get("db"),
479
480
  ids: body.ids,
@@ -487,7 +488,7 @@ export const distributionRoutes = new Hono()
487
488
  return c.json({ data: row });
488
489
  })
489
490
  .patch("/inventory-release-rules/:id", async (c) => {
490
- const row = await distributionService.updateInventoryReleaseRule(c.get("db"), c.req.param("id"), updateChannelInventoryReleaseRuleSchema.parse(await c.req.json()));
491
+ const row = await distributionService.updateInventoryReleaseRule(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateChannelInventoryReleaseRuleSchema));
491
492
  if (!row)
492
493
  return c.json({ error: "Channel inventory release rule not found" }, 404);
493
494
  return c.json({ data: row });
@@ -499,12 +500,12 @@ export const distributionRoutes = new Hono()
499
500
  return c.json({ success: true });
500
501
  })
501
502
  .get("/settlement-runs", async (c) => {
502
- const query = channelSettlementRunListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
503
+ const query = await parseQuery(c, channelSettlementRunListQuerySchema);
503
504
  return c.json(await distributionService.listSettlementRuns(c.get("db"), query));
504
505
  })
505
506
  .post("/settlement-runs", async (c) => {
506
507
  return c.json({
507
- data: await distributionService.createSettlementRun(c.get("db"), insertChannelSettlementRunSchema.parse(await c.req.json())),
508
+ data: await distributionService.createSettlementRun(c.get("db"), await parseJsonBody(c, insertChannelSettlementRunSchema)),
508
509
  }, 201);
509
510
  })
510
511
  .get("/settlement-runs/:id", async (c) => {
@@ -514,7 +515,7 @@ export const distributionRoutes = new Hono()
514
515
  return c.json({ data: row });
515
516
  })
516
517
  .patch("/settlement-runs/:id", async (c) => {
517
- const row = await distributionService.updateSettlementRun(c.get("db"), c.req.param("id"), updateChannelSettlementRunSchema.parse(await c.req.json()));
518
+ const row = await distributionService.updateSettlementRun(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateChannelSettlementRunSchema));
518
519
  if (!row)
519
520
  return c.json({ error: "Channel settlement run not found" }, 404);
520
521
  return c.json({ data: row });
@@ -526,12 +527,12 @@ export const distributionRoutes = new Hono()
526
527
  return c.json({ success: true });
527
528
  })
528
529
  .get("/settlement-items", async (c) => {
529
- const query = channelSettlementItemListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
530
+ const query = await parseQuery(c, channelSettlementItemListQuerySchema);
530
531
  return c.json(await distributionService.listSettlementItems(c.get("db"), query));
531
532
  })
532
533
  .post("/settlement-items", async (c) => {
533
534
  return c.json({
534
- data: await distributionService.createSettlementItem(c.get("db"), insertChannelSettlementItemSchema.parse(await c.req.json())),
535
+ data: await distributionService.createSettlementItem(c.get("db"), await parseJsonBody(c, insertChannelSettlementItemSchema)),
535
536
  }, 201);
536
537
  })
537
538
  .get("/settlement-items/:id", async (c) => {
@@ -541,7 +542,7 @@ export const distributionRoutes = new Hono()
541
542
  return c.json({ data: row });
542
543
  })
543
544
  .patch("/settlement-items/:id", async (c) => {
544
- const row = await distributionService.updateSettlementItem(c.get("db"), c.req.param("id"), updateChannelSettlementItemSchema.parse(await c.req.json()));
545
+ const row = await distributionService.updateSettlementItem(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateChannelSettlementItemSchema));
545
546
  if (!row)
546
547
  return c.json({ error: "Channel settlement item not found" }, 404);
547
548
  return c.json({ data: row });
@@ -553,12 +554,12 @@ export const distributionRoutes = new Hono()
553
554
  return c.json({ success: true });
554
555
  })
555
556
  .get("/reconciliation-runs", async (c) => {
556
- const query = channelReconciliationRunListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
557
+ const query = await parseQuery(c, channelReconciliationRunListQuerySchema);
557
558
  return c.json(await distributionService.listReconciliationRuns(c.get("db"), query));
558
559
  })
559
560
  .post("/reconciliation-runs", async (c) => {
560
561
  return c.json({
561
- data: await distributionService.createReconciliationRun(c.get("db"), insertChannelReconciliationRunSchema.parse(await c.req.json())),
562
+ data: await distributionService.createReconciliationRun(c.get("db"), await parseJsonBody(c, insertChannelReconciliationRunSchema)),
562
563
  }, 201);
563
564
  })
564
565
  .get("/reconciliation-runs/:id", async (c) => {
@@ -568,7 +569,7 @@ export const distributionRoutes = new Hono()
568
569
  return c.json({ data: row });
569
570
  })
570
571
  .patch("/reconciliation-runs/:id", async (c) => {
571
- const row = await distributionService.updateReconciliationRun(c.get("db"), c.req.param("id"), updateChannelReconciliationRunSchema.parse(await c.req.json()));
572
+ const row = await distributionService.updateReconciliationRun(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateChannelReconciliationRunSchema));
572
573
  if (!row)
573
574
  return c.json({ error: "Channel reconciliation run not found" }, 404);
574
575
  return c.json({ data: row });
@@ -580,12 +581,12 @@ export const distributionRoutes = new Hono()
580
581
  return c.json({ success: true });
581
582
  })
582
583
  .get("/reconciliation-items", async (c) => {
583
- const query = channelReconciliationItemListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
584
+ const query = await parseQuery(c, channelReconciliationItemListQuerySchema);
584
585
  return c.json(await distributionService.listReconciliationItems(c.get("db"), query));
585
586
  })
586
587
  .post("/reconciliation-items", async (c) => {
587
588
  return c.json({
588
- data: await distributionService.createReconciliationItem(c.get("db"), insertChannelReconciliationItemSchema.parse(await c.req.json())),
589
+ data: await distributionService.createReconciliationItem(c.get("db"), await parseJsonBody(c, insertChannelReconciliationItemSchema)),
589
590
  }, 201);
590
591
  })
591
592
  .get("/reconciliation-items/:id", async (c) => {
@@ -595,7 +596,7 @@ export const distributionRoutes = new Hono()
595
596
  return c.json({ data: row });
596
597
  })
597
598
  .patch("/reconciliation-items/:id", async (c) => {
598
- const row = await distributionService.updateReconciliationItem(c.get("db"), c.req.param("id"), updateChannelReconciliationItemSchema.parse(await c.req.json()));
599
+ const row = await distributionService.updateReconciliationItem(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateChannelReconciliationItemSchema));
599
600
  if (!row)
600
601
  return c.json({ error: "Channel reconciliation item not found" }, 404);
601
602
  return c.json({ data: row });
@@ -607,12 +608,12 @@ export const distributionRoutes = new Hono()
607
608
  return c.json({ success: true });
608
609
  })
609
610
  .get("/inventory-release-executions", async (c) => {
610
- const query = channelInventoryReleaseExecutionListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
611
+ const query = await parseQuery(c, channelInventoryReleaseExecutionListQuerySchema);
611
612
  return c.json(await distributionService.listReleaseExecutions(c.get("db"), query));
612
613
  })
613
614
  .post("/inventory-release-executions", async (c) => {
614
615
  return c.json({
615
- data: await distributionService.createReleaseExecution(c.get("db"), insertChannelInventoryReleaseExecutionSchema.parse(await c.req.json())),
616
+ data: await distributionService.createReleaseExecution(c.get("db"), await parseJsonBody(c, insertChannelInventoryReleaseExecutionSchema)),
616
617
  }, 201);
617
618
  })
618
619
  .get("/inventory-release-executions/:id", async (c) => {
@@ -622,7 +623,7 @@ export const distributionRoutes = new Hono()
622
623
  return c.json({ data: row });
623
624
  })
624
625
  .patch("/inventory-release-executions/:id", async (c) => {
625
- const row = await distributionService.updateReleaseExecution(c.get("db"), c.req.param("id"), updateChannelInventoryReleaseExecutionSchema.parse(await c.req.json()));
626
+ const row = await distributionService.updateReleaseExecution(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateChannelInventoryReleaseExecutionSchema));
626
627
  if (!row)
627
628
  return c.json({ error: "Channel inventory release execution not found" }, 404);
628
629
  return c.json({ data: row });
@@ -634,11 +635,11 @@ export const distributionRoutes = new Hono()
634
635
  return c.json({ success: true });
635
636
  })
636
637
  .get("/settlement-policies", async (c) => {
637
- const query = channelSettlementPolicyListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
638
+ const query = await parseQuery(c, channelSettlementPolicyListQuerySchema);
638
639
  return c.json(await distributionService.listSettlementPolicies(c.get("db"), query));
639
640
  })
640
641
  .post("/settlement-policies", async (c) => c.json({
641
- data: await distributionService.createSettlementPolicy(c.get("db"), insertChannelSettlementPolicySchema.parse(await c.req.json())),
642
+ data: await distributionService.createSettlementPolicy(c.get("db"), await parseJsonBody(c, insertChannelSettlementPolicySchema)),
642
643
  }, 201))
643
644
  .get("/settlement-policies/:id", async (c) => {
644
645
  const row = await distributionService.getSettlementPolicyById(c.get("db"), c.req.param("id"));
@@ -647,7 +648,7 @@ export const distributionRoutes = new Hono()
647
648
  return c.json({ data: row });
648
649
  })
649
650
  .patch("/settlement-policies/:id", async (c) => {
650
- const row = await distributionService.updateSettlementPolicy(c.get("db"), c.req.param("id"), updateChannelSettlementPolicySchema.parse(await c.req.json()));
651
+ const row = await distributionService.updateSettlementPolicy(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateChannelSettlementPolicySchema));
651
652
  if (!row)
652
653
  return c.json({ error: "Channel settlement policy not found" }, 404);
653
654
  return c.json({ data: row });
@@ -659,11 +660,11 @@ export const distributionRoutes = new Hono()
659
660
  return c.json({ success: true });
660
661
  })
661
662
  .get("/reconciliation-policies", async (c) => {
662
- const query = channelReconciliationPolicyListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
663
+ const query = await parseQuery(c, channelReconciliationPolicyListQuerySchema);
663
664
  return c.json(await distributionService.listReconciliationPolicies(c.get("db"), query));
664
665
  })
665
666
  .post("/reconciliation-policies", async (c) => c.json({
666
- data: await distributionService.createReconciliationPolicy(c.get("db"), insertChannelReconciliationPolicySchema.parse(await c.req.json())),
667
+ data: await distributionService.createReconciliationPolicy(c.get("db"), await parseJsonBody(c, insertChannelReconciliationPolicySchema)),
667
668
  }, 201))
668
669
  .get("/reconciliation-policies/:id", async (c) => {
669
670
  const row = await distributionService.getReconciliationPolicyById(c.get("db"), c.req.param("id"));
@@ -672,7 +673,7 @@ export const distributionRoutes = new Hono()
672
673
  return c.json({ data: row });
673
674
  })
674
675
  .patch("/reconciliation-policies/:id", async (c) => {
675
- const row = await distributionService.updateReconciliationPolicy(c.get("db"), c.req.param("id"), updateChannelReconciliationPolicySchema.parse(await c.req.json()));
676
+ const row = await distributionService.updateReconciliationPolicy(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateChannelReconciliationPolicySchema));
676
677
  if (!row)
677
678
  return c.json({ error: "Channel reconciliation policy not found" }, 404);
678
679
  return c.json({ data: row });
@@ -684,11 +685,11 @@ export const distributionRoutes = new Hono()
684
685
  return c.json({ success: true });
685
686
  })
686
687
  .get("/release-schedules", async (c) => {
687
- const query = channelReleaseScheduleListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
688
+ const query = await parseQuery(c, channelReleaseScheduleListQuerySchema);
688
689
  return c.json(await distributionService.listReleaseSchedules(c.get("db"), query));
689
690
  })
690
691
  .post("/release-schedules", async (c) => c.json({
691
- data: await distributionService.createReleaseSchedule(c.get("db"), insertChannelReleaseScheduleSchema.parse(await c.req.json())),
692
+ data: await distributionService.createReleaseSchedule(c.get("db"), await parseJsonBody(c, insertChannelReleaseScheduleSchema)),
692
693
  }, 201))
693
694
  .get("/release-schedules/:id", async (c) => {
694
695
  const row = await distributionService.getReleaseScheduleById(c.get("db"), c.req.param("id"));
@@ -697,7 +698,7 @@ export const distributionRoutes = new Hono()
697
698
  return c.json({ data: row });
698
699
  })
699
700
  .patch("/release-schedules/:id", async (c) => {
700
- const row = await distributionService.updateReleaseSchedule(c.get("db"), c.req.param("id"), updateChannelReleaseScheduleSchema.parse(await c.req.json()));
701
+ const row = await distributionService.updateReleaseSchedule(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateChannelReleaseScheduleSchema));
701
702
  if (!row)
702
703
  return c.json({ error: "Channel release schedule not found" }, 404);
703
704
  return c.json({ data: row });
@@ -709,11 +710,11 @@ export const distributionRoutes = new Hono()
709
710
  return c.json({ success: true });
710
711
  })
711
712
  .get("/remittance-exceptions", async (c) => {
712
- const query = channelRemittanceExceptionListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
713
+ const query = await parseQuery(c, channelRemittanceExceptionListQuerySchema);
713
714
  return c.json(await distributionService.listRemittanceExceptions(c.get("db"), query));
714
715
  })
715
716
  .post("/remittance-exceptions", async (c) => c.json({
716
- data: await distributionService.createRemittanceException(c.get("db"), insertChannelRemittanceExceptionSchema.parse(await c.req.json())),
717
+ data: await distributionService.createRemittanceException(c.get("db"), await parseJsonBody(c, insertChannelRemittanceExceptionSchema)),
717
718
  }, 201))
718
719
  .get("/remittance-exceptions/:id", async (c) => {
719
720
  const row = await distributionService.getRemittanceExceptionById(c.get("db"), c.req.param("id"));
@@ -722,7 +723,7 @@ export const distributionRoutes = new Hono()
722
723
  return c.json({ data: row });
723
724
  })
724
725
  .patch("/remittance-exceptions/:id", async (c) => {
725
- const row = await distributionService.updateRemittanceException(c.get("db"), c.req.param("id"), updateChannelRemittanceExceptionSchema.parse(await c.req.json()));
726
+ const row = await distributionService.updateRemittanceException(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateChannelRemittanceExceptionSchema));
726
727
  if (!row)
727
728
  return c.json({ error: "Channel remittance exception not found" }, 404);
728
729
  return c.json({ data: row });
@@ -734,11 +735,11 @@ export const distributionRoutes = new Hono()
734
735
  return c.json({ success: true });
735
736
  })
736
737
  .get("/settlement-approvals", async (c) => {
737
- const query = channelSettlementApprovalListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
738
+ const query = await parseQuery(c, channelSettlementApprovalListQuerySchema);
738
739
  return c.json(await distributionService.listSettlementApprovals(c.get("db"), query));
739
740
  })
740
741
  .post("/settlement-approvals", async (c) => c.json({
741
- data: await distributionService.createSettlementApproval(c.get("db"), insertChannelSettlementApprovalSchema.parse(await c.req.json())),
742
+ data: await distributionService.createSettlementApproval(c.get("db"), await parseJsonBody(c, insertChannelSettlementApprovalSchema)),
742
743
  }, 201))
743
744
  .get("/settlement-approvals/:id", async (c) => {
744
745
  const row = await distributionService.getSettlementApprovalById(c.get("db"), c.req.param("id"));
@@ -747,7 +748,7 @@ export const distributionRoutes = new Hono()
747
748
  return c.json({ data: row });
748
749
  })
749
750
  .patch("/settlement-approvals/:id", async (c) => {
750
- const row = await distributionService.updateSettlementApproval(c.get("db"), c.req.param("id"), updateChannelSettlementApprovalSchema.parse(await c.req.json()));
751
+ const row = await distributionService.updateSettlementApproval(c.get("db"), c.req.param("id"), await parseJsonBody(c, updateChannelSettlementApprovalSchema));
751
752
  if (!row)
752
753
  return c.json({ error: "Channel settlement approval not found" }, 404);
753
754
  return c.json({ data: row });
@@ -58,7 +58,7 @@ export declare const channels: import("drizzle-orm/pg-core").PgTableWithColumns<
58
58
  tableName: "channels";
59
59
  dataType: "string";
60
60
  columnType: "PgEnumColumn";
61
- data: "direct" | "affiliate" | "ota" | "reseller" | "marketplace" | "api_partner";
61
+ data: "reseller" | "direct" | "affiliate" | "ota" | "marketplace" | "api_partner";
62
62
  driverParam: string;
63
63
  notNull: true;
64
64
  hasDefault: false;
@@ -75,7 +75,7 @@ export declare const channels: import("drizzle-orm/pg-core").PgTableWithColumns<
75
75
  tableName: "channels";
76
76
  dataType: "string";
77
77
  columnType: "PgEnumColumn";
78
- data: "active" | "archived" | "inactive" | "pending";
78
+ data: "pending" | "active" | "archived" | "inactive";
79
79
  driverParam: string;
80
80
  notNull: true;
81
81
  hasDefault: true;
@@ -254,7 +254,7 @@ export declare const channelContracts: import("drizzle-orm/pg-core").PgTableWith
254
254
  tableName: "channel_contracts";
255
255
  dataType: "string";
256
256
  columnType: "PgEnumColumn";
257
- data: "operator" | "channel" | "split";
257
+ data: "split" | "operator" | "channel";
258
258
  driverParam: string;
259
259
  notNull: true;
260
260
  hasDefault: true;
@@ -397,7 +397,7 @@ export declare const channelCommissionRules: import("drizzle-orm/pg-core").PgTab
397
397
  tableName: "channel_commission_rules";
398
398
  dataType: "string";
399
399
  columnType: "PgEnumColumn";
400
- data: "product" | "category" | "booking" | "rate";
400
+ data: "category" | "product" | "booking" | "rate";
401
401
  driverParam: string;
402
402
  notNull: true;
403
403
  hasDefault: false;