@voyantjs/markets 0.1.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AA+BjE,KAAK,GAAG,GAAG;IACT,SAAS,EAAE;QACT,EAAE,EAAE,kBAAkB,CAAA;QACtB,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,CAAA;CACF,CAAA;AAED,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAgQtB,CAAA;AAEJ,MAAM,MAAM,aAAa,GAAG,OAAO,aAAa,CAAA"}
package/dist/routes.js ADDED
@@ -0,0 +1,208 @@
1
+ import { Hono } from "hono";
2
+ import { marketsService } from "./service.js";
3
+ import { exchangeRateListQuerySchema, fxRateSetListQuerySchema, insertExchangeRateSchema, insertFxRateSetSchema, insertMarketChannelRuleSchema, insertMarketCurrencySchema, insertMarketLocaleSchema, insertMarketPriceCatalogSchema, insertMarketProductRuleSchema, insertMarketSchema, marketChannelRuleListQuerySchema, marketCurrencyListQuerySchema, marketListQuerySchema, marketLocaleListQuerySchema, marketPriceCatalogListQuerySchema, marketProductRuleListQuerySchema, updateExchangeRateSchema, updateFxRateSetSchema, updateMarketChannelRuleSchema, updateMarketCurrencySchema, updateMarketLocaleSchema, updateMarketPriceCatalogSchema, updateMarketProductRuleSchema, updateMarketSchema, } from "./validation.js";
4
+ export const marketsRoutes = new Hono()
5
+ .get("/markets", async (c) => {
6
+ const query = marketListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
7
+ return c.json(await marketsService.listMarkets(c.get("db"), query));
8
+ })
9
+ .post("/markets", async (c) => {
10
+ return c.json({
11
+ data: await marketsService.createMarket(c.get("db"), insertMarketSchema.parse(await c.req.json())),
12
+ }, 201);
13
+ })
14
+ .get("/markets/:id", async (c) => {
15
+ const row = await marketsService.getMarketById(c.get("db"), c.req.param("id"));
16
+ if (!row)
17
+ return c.json({ error: "Market not found" }, 404);
18
+ return c.json({ data: row });
19
+ })
20
+ .patch("/markets/:id", async (c) => {
21
+ const row = await marketsService.updateMarket(c.get("db"), c.req.param("id"), updateMarketSchema.parse(await c.req.json()));
22
+ if (!row)
23
+ return c.json({ error: "Market not found" }, 404);
24
+ return c.json({ data: row });
25
+ })
26
+ .delete("/markets/:id", async (c) => {
27
+ const row = await marketsService.deleteMarket(c.get("db"), c.req.param("id"));
28
+ if (!row)
29
+ return c.json({ error: "Market not found" }, 404);
30
+ return c.json({ success: true });
31
+ })
32
+ .get("/market-locales", async (c) => {
33
+ const query = marketLocaleListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
34
+ return c.json(await marketsService.listMarketLocales(c.get("db"), query));
35
+ })
36
+ .post("/markets/:id/locales", async (c) => {
37
+ const row = await marketsService.createMarketLocale(c.get("db"), c.req.param("id"), insertMarketLocaleSchema.parse(await c.req.json()));
38
+ if (!row)
39
+ return c.json({ error: "Market not found" }, 404);
40
+ return c.json({ data: row }, 201);
41
+ })
42
+ .patch("/market-locales/:id", async (c) => {
43
+ const row = await marketsService.updateMarketLocale(c.get("db"), c.req.param("id"), updateMarketLocaleSchema.parse(await c.req.json()));
44
+ if (!row)
45
+ return c.json({ error: "Market locale not found" }, 404);
46
+ return c.json({ data: row });
47
+ })
48
+ .delete("/market-locales/:id", async (c) => {
49
+ const row = await marketsService.deleteMarketLocale(c.get("db"), c.req.param("id"));
50
+ if (!row)
51
+ return c.json({ error: "Market locale not found" }, 404);
52
+ return c.json({ success: true });
53
+ })
54
+ .get("/market-currencies", async (c) => {
55
+ const query = marketCurrencyListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
56
+ return c.json(await marketsService.listMarketCurrencies(c.get("db"), query));
57
+ })
58
+ .post("/markets/:id/currencies", async (c) => {
59
+ const row = await marketsService.createMarketCurrency(c.get("db"), c.req.param("id"), insertMarketCurrencySchema.parse(await c.req.json()));
60
+ if (!row)
61
+ return c.json({ error: "Market not found" }, 404);
62
+ return c.json({ data: row }, 201);
63
+ })
64
+ .patch("/market-currencies/:id", async (c) => {
65
+ const row = await marketsService.updateMarketCurrency(c.get("db"), c.req.param("id"), updateMarketCurrencySchema.parse(await c.req.json()));
66
+ if (!row)
67
+ return c.json({ error: "Market currency not found" }, 404);
68
+ return c.json({ data: row });
69
+ })
70
+ .delete("/market-currencies/:id", async (c) => {
71
+ const row = await marketsService.deleteMarketCurrency(c.get("db"), c.req.param("id"));
72
+ if (!row)
73
+ return c.json({ error: "Market currency not found" }, 404);
74
+ return c.json({ success: true });
75
+ })
76
+ .get("/fx-rate-sets", async (c) => {
77
+ const query = fxRateSetListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
78
+ return c.json(await marketsService.listFxRateSets(c.get("db"), query));
79
+ })
80
+ .post("/fx-rate-sets", async (c) => {
81
+ return c.json({
82
+ data: await marketsService.createFxRateSet(c.get("db"), insertFxRateSetSchema.parse(await c.req.json())),
83
+ }, 201);
84
+ })
85
+ .get("/fx-rate-sets/:id", async (c) => {
86
+ const row = await marketsService.getFxRateSetById(c.get("db"), c.req.param("id"));
87
+ if (!row)
88
+ return c.json({ error: "FX rate set not found" }, 404);
89
+ return c.json({ data: row });
90
+ })
91
+ .patch("/fx-rate-sets/:id", async (c) => {
92
+ const row = await marketsService.updateFxRateSet(c.get("db"), c.req.param("id"), updateFxRateSetSchema.parse(await c.req.json()));
93
+ if (!row)
94
+ return c.json({ error: "FX rate set not found" }, 404);
95
+ return c.json({ data: row });
96
+ })
97
+ .delete("/fx-rate-sets/:id", async (c) => {
98
+ const row = await marketsService.deleteFxRateSet(c.get("db"), c.req.param("id"));
99
+ if (!row)
100
+ return c.json({ error: "FX rate set not found" }, 404);
101
+ return c.json({ success: true });
102
+ })
103
+ .get("/exchange-rates", async (c) => {
104
+ const query = exchangeRateListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
105
+ return c.json(await marketsService.listExchangeRates(c.get("db"), query));
106
+ })
107
+ .post("/fx-rate-sets/:id/exchange-rates", async (c) => {
108
+ const row = await marketsService.createExchangeRate(c.get("db"), c.req.param("id"), insertExchangeRateSchema.parse(await c.req.json()));
109
+ if (!row)
110
+ return c.json({ error: "FX rate set not found" }, 404);
111
+ return c.json({ data: row }, 201);
112
+ })
113
+ .patch("/exchange-rates/:id", async (c) => {
114
+ const row = await marketsService.updateExchangeRate(c.get("db"), c.req.param("id"), updateExchangeRateSchema.parse(await c.req.json()));
115
+ if (!row)
116
+ return c.json({ error: "Exchange rate not found" }, 404);
117
+ return c.json({ data: row });
118
+ })
119
+ .delete("/exchange-rates/:id", async (c) => {
120
+ const row = await marketsService.deleteExchangeRate(c.get("db"), c.req.param("id"));
121
+ if (!row)
122
+ return c.json({ error: "Exchange rate not found" }, 404);
123
+ return c.json({ success: true });
124
+ })
125
+ .get("/price-catalogs", async (c) => {
126
+ const query = marketPriceCatalogListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
127
+ return c.json(await marketsService.listMarketPriceCatalogs(c.get("db"), query));
128
+ })
129
+ .post("/price-catalogs", async (c) => {
130
+ const row = await marketsService.createMarketPriceCatalog(c.get("db"), insertMarketPriceCatalogSchema.parse(await c.req.json()));
131
+ if (!row)
132
+ return c.json({ error: "Market not found" }, 404);
133
+ return c.json({ data: row }, 201);
134
+ })
135
+ .get("/price-catalogs/:id", async (c) => {
136
+ const row = await marketsService.getMarketPriceCatalogById(c.get("db"), c.req.param("id"));
137
+ if (!row)
138
+ return c.json({ error: "Market price catalog not found" }, 404);
139
+ return c.json({ data: row });
140
+ })
141
+ .patch("/price-catalogs/:id", async (c) => {
142
+ const row = await marketsService.updateMarketPriceCatalog(c.get("db"), c.req.param("id"), updateMarketPriceCatalogSchema.parse(await c.req.json()));
143
+ if (!row)
144
+ return c.json({ error: "Market price catalog not found" }, 404);
145
+ return c.json({ data: row });
146
+ })
147
+ .delete("/price-catalogs/:id", async (c) => {
148
+ const row = await marketsService.deleteMarketPriceCatalog(c.get("db"), c.req.param("id"));
149
+ if (!row)
150
+ return c.json({ error: "Market price catalog not found" }, 404);
151
+ return c.json({ success: true });
152
+ })
153
+ .get("/product-rules", async (c) => {
154
+ const query = marketProductRuleListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
155
+ return c.json(await marketsService.listMarketProductRules(c.get("db"), query));
156
+ })
157
+ .post("/product-rules", async (c) => {
158
+ const row = await marketsService.createMarketProductRule(c.get("db"), insertMarketProductRuleSchema.parse(await c.req.json()));
159
+ if (!row)
160
+ return c.json({ error: "Market not found" }, 404);
161
+ return c.json({ data: row }, 201);
162
+ })
163
+ .get("/product-rules/:id", async (c) => {
164
+ const row = await marketsService.getMarketProductRuleById(c.get("db"), c.req.param("id"));
165
+ if (!row)
166
+ return c.json({ error: "Market product rule not found" }, 404);
167
+ return c.json({ data: row });
168
+ })
169
+ .patch("/product-rules/:id", async (c) => {
170
+ const row = await marketsService.updateMarketProductRule(c.get("db"), c.req.param("id"), updateMarketProductRuleSchema.parse(await c.req.json()));
171
+ if (!row)
172
+ return c.json({ error: "Market product rule not found" }, 404);
173
+ return c.json({ data: row });
174
+ })
175
+ .delete("/product-rules/:id", async (c) => {
176
+ const row = await marketsService.deleteMarketProductRule(c.get("db"), c.req.param("id"));
177
+ if (!row)
178
+ return c.json({ error: "Market product rule not found" }, 404);
179
+ return c.json({ success: true });
180
+ })
181
+ .get("/channel-rules", async (c) => {
182
+ const query = marketChannelRuleListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
183
+ return c.json(await marketsService.listMarketChannelRules(c.get("db"), query));
184
+ })
185
+ .post("/channel-rules", async (c) => {
186
+ const row = await marketsService.createMarketChannelRule(c.get("db"), insertMarketChannelRuleSchema.parse(await c.req.json()));
187
+ if (!row)
188
+ return c.json({ error: "Market not found" }, 404);
189
+ return c.json({ data: row }, 201);
190
+ })
191
+ .get("/channel-rules/:id", async (c) => {
192
+ const row = await marketsService.getMarketChannelRuleById(c.get("db"), c.req.param("id"));
193
+ if (!row)
194
+ return c.json({ error: "Market channel rule not found" }, 404);
195
+ return c.json({ data: row });
196
+ })
197
+ .patch("/channel-rules/:id", async (c) => {
198
+ const row = await marketsService.updateMarketChannelRule(c.get("db"), c.req.param("id"), updateMarketChannelRuleSchema.parse(await c.req.json()));
199
+ if (!row)
200
+ return c.json({ error: "Market channel rule not found" }, 404);
201
+ return c.json({ data: row });
202
+ })
203
+ .delete("/channel-rules/:id", async (c) => {
204
+ const row = await marketsService.deleteMarketChannelRule(c.get("db"), c.req.param("id"));
205
+ if (!row)
206
+ return c.json({ error: "Market channel rule not found" }, 404);
207
+ return c.json({ success: true });
208
+ });