@voyantjs/suppliers 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.
- package/LICENSE +109 -0
- package/README.md +41 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/routes.d.ts +1183 -0
- package/dist/routes.d.ts.map +1 -0
- package/dist/routes.js +267 -0
- package/dist/schema.d.ts +1040 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +186 -0
- package/dist/service.d.ts +1755 -0
- package/dist/service.d.ts.map +1 -0
- package/dist/service.js +602 -0
- package/dist/validation.d.ts +231 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +109 -0
- package/package.json +53 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes.d.ts","sourceRoot":"","sources":["../src/routes.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAmBjE,KAAK,GAAG,GAAG;IACT,SAAS,EAAE;QACT,EAAE,EAAE,kBAAkB,CAAA;QACtB,MAAM,CAAC,EAAE,MAAM,CAAA;KAChB,CAAA;CACF,CAAA;AAMD,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qCA0ZvB,CAAA;AAEJ,MAAM,MAAM,cAAc,GAAG,OAAO,cAAc,CAAA"}
|
package/dist/routes.js
ADDED
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { insertAddressForEntitySchema, insertContactPointForEntitySchema, insertNamedContactForEntitySchema, updateAddressSchema as updateIdentityAddressSchema, updateContactPointSchema as updateIdentityContactPointSchema, updateNamedContactSchema as updateIdentityNamedContactSchema, } from "@voyantjs/identity/validation";
|
|
2
|
+
import { Hono } from "hono";
|
|
3
|
+
import { suppliersService } from "./service.js";
|
|
4
|
+
import { availabilityQuerySchema, insertAvailabilitySchema, insertContractSchema, insertRateSchema, insertServiceSchema, insertSupplierNoteSchema, insertSupplierSchema, supplierListQuerySchema, updateContractSchema, updateRateSchema, updateServiceSchema, updateSupplierSchema, } from "./validation.js";
|
|
5
|
+
// ==========================================================================
|
|
6
|
+
// Suppliers — method-chained for Hono RPC type inference
|
|
7
|
+
// ==========================================================================
|
|
8
|
+
export const supplierRoutes = new Hono()
|
|
9
|
+
// ========================================================================
|
|
10
|
+
// Suppliers CRUD
|
|
11
|
+
// ========================================================================
|
|
12
|
+
// GET / — List suppliers
|
|
13
|
+
.get("/", async (c) => {
|
|
14
|
+
const query = supplierListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
|
|
15
|
+
return c.json(await suppliersService.listSuppliers(c.get("db"), query));
|
|
16
|
+
})
|
|
17
|
+
// PATCH /contact-points/:contactPointId — Update supplier contact point
|
|
18
|
+
.patch("/contact-points/:contactPointId", async (c) => {
|
|
19
|
+
const row = await suppliersService.updateContactPoint(c.get("db"), c.req.param("contactPointId"), updateIdentityContactPointSchema.parse(await c.req.json()));
|
|
20
|
+
if (!row) {
|
|
21
|
+
return c.json({ error: "Contact point not found" }, 404);
|
|
22
|
+
}
|
|
23
|
+
return c.json({ data: row });
|
|
24
|
+
})
|
|
25
|
+
// PATCH /contacts/:contactId — Update supplier named contact
|
|
26
|
+
.patch("/contacts/:contactId", async (c) => {
|
|
27
|
+
const row = await suppliersService.updateNamedContact(c.get("db"), c.req.param("contactId"), updateIdentityNamedContactSchema.parse(await c.req.json()));
|
|
28
|
+
if (!row) {
|
|
29
|
+
return c.json({ error: "Contact not found" }, 404);
|
|
30
|
+
}
|
|
31
|
+
return c.json({ data: row });
|
|
32
|
+
})
|
|
33
|
+
// DELETE /contacts/:contactId — Delete supplier named contact
|
|
34
|
+
.delete("/contacts/:contactId", async (c) => {
|
|
35
|
+
const row = await suppliersService.deleteNamedContact(c.get("db"), c.req.param("contactId"));
|
|
36
|
+
if (!row) {
|
|
37
|
+
return c.json({ error: "Contact not found" }, 404);
|
|
38
|
+
}
|
|
39
|
+
return c.json({ success: true }, 200);
|
|
40
|
+
})
|
|
41
|
+
// DELETE /contact-points/:contactPointId — Delete supplier contact point
|
|
42
|
+
.delete("/contact-points/:contactPointId", async (c) => {
|
|
43
|
+
const row = await suppliersService.deleteContactPoint(c.get("db"), c.req.param("contactPointId"));
|
|
44
|
+
if (!row) {
|
|
45
|
+
return c.json({ error: "Contact point not found" }, 404);
|
|
46
|
+
}
|
|
47
|
+
return c.json({ success: true }, 200);
|
|
48
|
+
})
|
|
49
|
+
// PATCH /addresses/:addressId — Update supplier address
|
|
50
|
+
.patch("/addresses/:addressId", async (c) => {
|
|
51
|
+
const row = await suppliersService.updateAddress(c.get("db"), c.req.param("addressId"), updateIdentityAddressSchema.parse(await c.req.json()));
|
|
52
|
+
if (!row) {
|
|
53
|
+
return c.json({ error: "Address not found" }, 404);
|
|
54
|
+
}
|
|
55
|
+
return c.json({ data: row });
|
|
56
|
+
})
|
|
57
|
+
// DELETE /addresses/:addressId — Delete supplier address
|
|
58
|
+
.delete("/addresses/:addressId", async (c) => {
|
|
59
|
+
const row = await suppliersService.deleteAddress(c.get("db"), c.req.param("addressId"));
|
|
60
|
+
if (!row) {
|
|
61
|
+
return c.json({ error: "Address not found" }, 404);
|
|
62
|
+
}
|
|
63
|
+
return c.json({ success: true }, 200);
|
|
64
|
+
})
|
|
65
|
+
// GET /:id — Get single supplier
|
|
66
|
+
.get("/:id", async (c) => {
|
|
67
|
+
const row = await suppliersService.getSupplierById(c.get("db"), c.req.param("id"));
|
|
68
|
+
if (!row) {
|
|
69
|
+
return c.json({ error: "Supplier not found" }, 404);
|
|
70
|
+
}
|
|
71
|
+
return c.json({ data: row });
|
|
72
|
+
})
|
|
73
|
+
// POST / — Create supplier
|
|
74
|
+
.post("/", async (c) => {
|
|
75
|
+
const data = insertSupplierSchema.parse(await c.req.json());
|
|
76
|
+
return c.json({ data: await suppliersService.createSupplier(c.get("db"), data) }, 201);
|
|
77
|
+
})
|
|
78
|
+
// PATCH /:id — Update supplier
|
|
79
|
+
.patch("/:id", async (c) => {
|
|
80
|
+
const row = await suppliersService.updateSupplier(c.get("db"), c.req.param("id"), updateSupplierSchema.parse(await c.req.json()));
|
|
81
|
+
if (!row) {
|
|
82
|
+
return c.json({ error: "Supplier not found" }, 404);
|
|
83
|
+
}
|
|
84
|
+
return c.json({ data: row });
|
|
85
|
+
})
|
|
86
|
+
// DELETE /:id — Delete supplier
|
|
87
|
+
.delete("/:id", async (c) => {
|
|
88
|
+
const row = await suppliersService.deleteSupplier(c.get("db"), c.req.param("id"));
|
|
89
|
+
if (!row) {
|
|
90
|
+
return c.json({ error: "Supplier not found" }, 404);
|
|
91
|
+
}
|
|
92
|
+
return c.json({ success: true }, 200);
|
|
93
|
+
})
|
|
94
|
+
// GET /:id/contact-points — List shared contact points for a supplier
|
|
95
|
+
.get("/:id/contact-points", async (c) => {
|
|
96
|
+
return c.json({
|
|
97
|
+
data: await suppliersService.listContactPoints(c.get("db"), c.req.param("id")),
|
|
98
|
+
});
|
|
99
|
+
})
|
|
100
|
+
// POST /:id/contact-points — Create shared contact point for a supplier
|
|
101
|
+
.post("/:id/contact-points", async (c) => {
|
|
102
|
+
const row = await suppliersService.createContactPoint(c.get("db"), c.req.param("id"), insertContactPointForEntitySchema.parse(await c.req.json()));
|
|
103
|
+
if (!row) {
|
|
104
|
+
return c.json({ error: "Supplier not found" }, 404);
|
|
105
|
+
}
|
|
106
|
+
return c.json({ data: row }, 201);
|
|
107
|
+
})
|
|
108
|
+
// GET /:id/contacts — List shared named contacts for a supplier
|
|
109
|
+
.get("/:id/contacts", async (c) => {
|
|
110
|
+
return c.json({
|
|
111
|
+
data: await suppliersService.listNamedContacts(c.get("db"), c.req.param("id")),
|
|
112
|
+
});
|
|
113
|
+
})
|
|
114
|
+
// POST /:id/contacts — Create shared named contact for a supplier
|
|
115
|
+
.post("/:id/contacts", async (c) => {
|
|
116
|
+
const row = await suppliersService.createNamedContact(c.get("db"), c.req.param("id"), insertNamedContactForEntitySchema.parse(await c.req.json()));
|
|
117
|
+
if (!row) {
|
|
118
|
+
return c.json({ error: "Supplier not found" }, 404);
|
|
119
|
+
}
|
|
120
|
+
return c.json({ data: row }, 201);
|
|
121
|
+
})
|
|
122
|
+
// GET /:id/addresses — List shared addresses for a supplier
|
|
123
|
+
.get("/:id/addresses", async (c) => {
|
|
124
|
+
return c.json({ data: await suppliersService.listAddresses(c.get("db"), c.req.param("id")) });
|
|
125
|
+
})
|
|
126
|
+
// POST /:id/addresses — Create shared address for a supplier
|
|
127
|
+
.post("/:id/addresses", async (c) => {
|
|
128
|
+
const row = await suppliersService.createAddress(c.get("db"), c.req.param("id"), insertAddressForEntitySchema.parse(await c.req.json()));
|
|
129
|
+
if (!row) {
|
|
130
|
+
return c.json({ error: "Supplier not found" }, 404);
|
|
131
|
+
}
|
|
132
|
+
return c.json({ data: row }, 201);
|
|
133
|
+
})
|
|
134
|
+
// ========================================================================
|
|
135
|
+
// Services
|
|
136
|
+
// ========================================================================
|
|
137
|
+
// GET /:id/services — List services for a supplier
|
|
138
|
+
.get("/:id/services", async (c) => {
|
|
139
|
+
return c.json({ data: await suppliersService.listServices(c.get("db"), c.req.param("id")) });
|
|
140
|
+
})
|
|
141
|
+
// POST /:id/services — Add service to supplier
|
|
142
|
+
.post("/:id/services", async (c) => {
|
|
143
|
+
const row = await suppliersService.createService(c.get("db"), c.req.param("id"), insertServiceSchema.parse(await c.req.json()));
|
|
144
|
+
if (!row) {
|
|
145
|
+
return c.json({ error: "Supplier not found" }, 404);
|
|
146
|
+
}
|
|
147
|
+
return c.json({ data: row }, 201);
|
|
148
|
+
})
|
|
149
|
+
// PATCH /:id/services/:serviceId — Update service
|
|
150
|
+
.patch("/:id/services/:serviceId", async (c) => {
|
|
151
|
+
const row = await suppliersService.updateService(c.get("db"), c.req.param("serviceId"), updateServiceSchema.parse(await c.req.json()));
|
|
152
|
+
if (!row) {
|
|
153
|
+
return c.json({ error: "Service not found" }, 404);
|
|
154
|
+
}
|
|
155
|
+
return c.json({ data: row });
|
|
156
|
+
})
|
|
157
|
+
// DELETE /:id/services/:serviceId — Delete service
|
|
158
|
+
.delete("/:id/services/:serviceId", async (c) => {
|
|
159
|
+
const row = await suppliersService.deleteService(c.get("db"), c.req.param("serviceId"));
|
|
160
|
+
if (!row) {
|
|
161
|
+
return c.json({ error: "Service not found" }, 404);
|
|
162
|
+
}
|
|
163
|
+
return c.json({ success: true }, 200);
|
|
164
|
+
})
|
|
165
|
+
// ========================================================================
|
|
166
|
+
// Rates
|
|
167
|
+
// ========================================================================
|
|
168
|
+
// GET /:id/services/:serviceId/rates — List rates for a service
|
|
169
|
+
.get("/:id/services/:serviceId/rates", async (c) => {
|
|
170
|
+
return c.json({
|
|
171
|
+
data: await suppliersService.listRates(c.get("db"), c.req.param("serviceId")),
|
|
172
|
+
});
|
|
173
|
+
})
|
|
174
|
+
// POST /:id/services/:serviceId/rates — Add rate to service
|
|
175
|
+
.post("/:id/services/:serviceId/rates", async (c) => {
|
|
176
|
+
const row = await suppliersService.createRate(c.get("db"), c.req.param("serviceId"), insertRateSchema.parse(await c.req.json()));
|
|
177
|
+
if (!row) {
|
|
178
|
+
return c.json({ error: "Service not found" }, 404);
|
|
179
|
+
}
|
|
180
|
+
return c.json({ data: row }, 201);
|
|
181
|
+
})
|
|
182
|
+
// PATCH /:id/services/:serviceId/rates/:rateId — Update rate
|
|
183
|
+
.patch("/:id/services/:serviceId/rates/:rateId", async (c) => {
|
|
184
|
+
const row = await suppliersService.updateRate(c.get("db"), c.req.param("rateId"), updateRateSchema.parse(await c.req.json()));
|
|
185
|
+
if (!row) {
|
|
186
|
+
return c.json({ error: "Rate not found" }, 404);
|
|
187
|
+
}
|
|
188
|
+
return c.json({ data: row });
|
|
189
|
+
})
|
|
190
|
+
// DELETE /:id/services/:serviceId/rates/:rateId — Delete rate
|
|
191
|
+
.delete("/:id/services/:serviceId/rates/:rateId", async (c) => {
|
|
192
|
+
const row = await suppliersService.deleteRate(c.get("db"), c.req.param("rateId"));
|
|
193
|
+
if (!row) {
|
|
194
|
+
return c.json({ error: "Rate not found" }, 404);
|
|
195
|
+
}
|
|
196
|
+
return c.json({ success: true }, 200);
|
|
197
|
+
})
|
|
198
|
+
// ========================================================================
|
|
199
|
+
// Notes
|
|
200
|
+
// ========================================================================
|
|
201
|
+
// GET /:id/notes — List notes for supplier
|
|
202
|
+
.get("/:id/notes", async (c) => {
|
|
203
|
+
return c.json({ data: await suppliersService.listNotes(c.get("db"), c.req.param("id")) });
|
|
204
|
+
})
|
|
205
|
+
// POST /:id/notes — Add note to supplier
|
|
206
|
+
.post("/:id/notes", async (c) => {
|
|
207
|
+
const userId = c.get("userId");
|
|
208
|
+
if (!userId) {
|
|
209
|
+
return c.json({ error: "User ID required to create notes" }, 400);
|
|
210
|
+
}
|
|
211
|
+
const row = await suppliersService.createNote(c.get("db"), c.req.param("id"), userId, insertSupplierNoteSchema.parse(await c.req.json()));
|
|
212
|
+
if (!row) {
|
|
213
|
+
return c.json({ error: "Supplier not found" }, 404);
|
|
214
|
+
}
|
|
215
|
+
return c.json({ data: row }, 201);
|
|
216
|
+
})
|
|
217
|
+
// ========================================================================
|
|
218
|
+
// Availability
|
|
219
|
+
// ========================================================================
|
|
220
|
+
// GET /:id/availability — List availability entries
|
|
221
|
+
.get("/:id/availability", async (c) => {
|
|
222
|
+
const query = availabilityQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
|
|
223
|
+
return c.json({
|
|
224
|
+
data: await suppliersService.listAvailability(c.get("db"), c.req.param("id"), query),
|
|
225
|
+
});
|
|
226
|
+
})
|
|
227
|
+
// POST /:id/availability — Add availability entries (bulk)
|
|
228
|
+
.post("/:id/availability", async (c) => {
|
|
229
|
+
const body = await c.req.json();
|
|
230
|
+
const entries = Array.isArray(body) ? body : [body];
|
|
231
|
+
const row = await suppliersService.createAvailability(c.get("db"), c.req.param("id"), entries.map((entry) => insertAvailabilitySchema.parse(entry)));
|
|
232
|
+
if (!row) {
|
|
233
|
+
return c.json({ error: "Supplier not found" }, 404);
|
|
234
|
+
}
|
|
235
|
+
return c.json({ data: row }, 201);
|
|
236
|
+
})
|
|
237
|
+
// ========================================================================
|
|
238
|
+
// Contracts
|
|
239
|
+
// ========================================================================
|
|
240
|
+
// GET /:id/contracts — List contracts
|
|
241
|
+
.get("/:id/contracts", async (c) => {
|
|
242
|
+
return c.json({ data: await suppliersService.listContracts(c.get("db"), c.req.param("id")) });
|
|
243
|
+
})
|
|
244
|
+
// POST /:id/contracts — Create contract
|
|
245
|
+
.post("/:id/contracts", async (c) => {
|
|
246
|
+
const row = await suppliersService.createContract(c.get("db"), c.req.param("id"), insertContractSchema.parse(await c.req.json()));
|
|
247
|
+
if (!row) {
|
|
248
|
+
return c.json({ error: "Supplier not found" }, 404);
|
|
249
|
+
}
|
|
250
|
+
return c.json({ data: row }, 201);
|
|
251
|
+
})
|
|
252
|
+
// PATCH /:id/contracts/:contractId — Update contract
|
|
253
|
+
.patch("/:id/contracts/:contractId", async (c) => {
|
|
254
|
+
const row = await suppliersService.updateContract(c.get("db"), c.req.param("contractId"), updateContractSchema.parse(await c.req.json()));
|
|
255
|
+
if (!row) {
|
|
256
|
+
return c.json({ error: "Contract not found" }, 404);
|
|
257
|
+
}
|
|
258
|
+
return c.json({ data: row });
|
|
259
|
+
})
|
|
260
|
+
// DELETE /:id/contracts/:contractId — Delete contract
|
|
261
|
+
.delete("/:id/contracts/:contractId", async (c) => {
|
|
262
|
+
const row = await suppliersService.deleteContract(c.get("db"), c.req.param("contractId"));
|
|
263
|
+
if (!row) {
|
|
264
|
+
return c.json({ error: "Contract not found" }, 404);
|
|
265
|
+
}
|
|
266
|
+
return c.json({ success: true }, 200);
|
|
267
|
+
});
|