@voyantjs/transactions 0.1.1 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/routes-offers.d.ts +885 -0
- package/dist/routes-offers.d.ts.map +1 -0
- package/dist/routes-offers.js +161 -0
- package/dist/routes-orders.d.ts +1056 -0
- package/dist/routes-orders.d.ts.map +1 -0
- package/dist/routes-orders.js +180 -0
- package/dist/routes-shared.d.ts +103 -0
- package/dist/routes-shared.d.ts.map +1 -0
- package/dist/routes-shared.js +97 -0
- package/dist/routes.d.ts +3 -1979
- package/dist/routes.d.ts.map +1 -1
- package/dist/routes.js +5 -604
- package/dist/schema-audit.d.ts +216 -0
- package/dist/schema-audit.d.ts.map +1 -0
- package/dist/schema-audit.js +22 -0
- package/dist/schema-offers.d.ts +1301 -0
- package/dist/schema-offers.d.ts.map +1 -0
- package/dist/schema-offers.js +120 -0
- package/dist/schema-orders.d.ts +1582 -0
- package/dist/schema-orders.d.ts.map +1 -0
- package/dist/schema-orders.js +149 -0
- package/dist/schema-relations.d.ts +42 -0
- package/dist/schema-relations.d.ts.map +1 -0
- package/dist/schema-relations.js +56 -0
- package/dist/schema-shared.d.ts +12 -0
- package/dist/schema-shared.d.ts.map +1 -0
- package/dist/schema-shared.js +84 -0
- package/dist/schema.d.ts +5 -3148
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +5 -420
- package/dist/service-offers.d.ts +447 -0
- package/dist/service-offers.d.ts.map +1 -0
- package/dist/service-offers.js +262 -0
- package/dist/service-orders.d.ts +443 -0
- package/dist/service-orders.d.ts.map +1 -0
- package/dist/service-orders.js +278 -0
- package/dist/service-shared.d.ts +86 -0
- package/dist/service-shared.d.ts.map +1 -0
- package/dist/service-shared.js +49 -0
- package/dist/service.d.ts +48 -927
- package/dist/service.d.ts.map +1 -1
- package/dist/service.js +48 -595
- package/package.json +5 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"routes-off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,161 @@
|
|
|
1
|
+
import { Hono } from "hono";
|
|
2
|
+
import { authorizeTransactionPiiAccess, createPiiService, hasParticipantIdentityInput, logTransactionPiiAccess, notFound, } from "./routes-shared.js";
|
|
3
|
+
import { transactionsService } from "./service.js";
|
|
4
|
+
import { insertOfferItemParticipantSchema, insertOfferItemSchema, insertOfferParticipantSchema, insertOfferSchema, offerItemListQuerySchema, offerItemParticipantListQuerySchema, offerListQuerySchema, offerParticipantListQuerySchema, updateOfferItemParticipantSchema, updateOfferItemSchema, updateOfferParticipantSchema, updateOfferSchema, } from "./validation.js";
|
|
5
|
+
export const transactionOfferRoutes = new Hono()
|
|
6
|
+
.get("/offers", async (c) => {
|
|
7
|
+
const query = offerListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
|
|
8
|
+
return c.json(await transactionsService.listOffers(c.get("db"), query));
|
|
9
|
+
})
|
|
10
|
+
.post("/offers", async (c) => c.json({
|
|
11
|
+
data: await transactionsService.createOffer(c.get("db"), insertOfferSchema.parse(await c.req.json())),
|
|
12
|
+
}, 201))
|
|
13
|
+
.get("/offers/:id", async (c) => {
|
|
14
|
+
const row = await transactionsService.getOfferById(c.get("db"), c.req.param("id"));
|
|
15
|
+
return row ? c.json({ data: row }) : notFound(c, "Offer not found");
|
|
16
|
+
})
|
|
17
|
+
.patch("/offers/:id", async (c) => {
|
|
18
|
+
const row = await transactionsService.updateOffer(c.get("db"), c.req.param("id"), updateOfferSchema.parse(await c.req.json()));
|
|
19
|
+
return row ? c.json({ data: row }) : notFound(c, "Offer not found");
|
|
20
|
+
})
|
|
21
|
+
.delete("/offers/:id", async (c) => {
|
|
22
|
+
const row = await transactionsService.deleteOffer(c.get("db"), c.req.param("id"));
|
|
23
|
+
return row ? c.json({ success: true }) : notFound(c, "Offer not found");
|
|
24
|
+
})
|
|
25
|
+
.get("/offer-participants", async (c) => {
|
|
26
|
+
const query = offerParticipantListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
|
|
27
|
+
return c.json(await transactionsService.listOfferParticipants(c.get("db"), query));
|
|
28
|
+
})
|
|
29
|
+
.post("/offer-participants", async (c) => {
|
|
30
|
+
const payload = insertOfferParticipantSchema.parse(await c.req.json());
|
|
31
|
+
const row = await transactionsService.createOfferParticipant(c.get("db"), payload);
|
|
32
|
+
if (!row)
|
|
33
|
+
return c.json({ data: row }, 201);
|
|
34
|
+
if (hasParticipantIdentityInput(payload)) {
|
|
35
|
+
const pii = createPiiService(c, "offer", row.offerId);
|
|
36
|
+
await pii.upsertParticipantIdentity(c.get("db"), "offer", row.id, payload, c.get("userId"));
|
|
37
|
+
return c.json({ data: await transactionsService.getOfferParticipantById(c.get("db"), row.id) }, 201);
|
|
38
|
+
}
|
|
39
|
+
return c.json({ data: row }, 201);
|
|
40
|
+
})
|
|
41
|
+
.get("/offer-participants/:id", async (c) => {
|
|
42
|
+
const row = await transactionsService.getOfferParticipantById(c.get("db"), c.req.param("id"));
|
|
43
|
+
return row ? c.json({ data: row }) : notFound(c, "Offer participant not found");
|
|
44
|
+
})
|
|
45
|
+
.patch("/offer-participants/:id", async (c) => {
|
|
46
|
+
const payload = updateOfferParticipantSchema.parse(await c.req.json());
|
|
47
|
+
const row = await transactionsService.updateOfferParticipant(c.get("db"), c.req.param("id"), payload);
|
|
48
|
+
if (!row)
|
|
49
|
+
return notFound(c, "Offer participant not found");
|
|
50
|
+
if (hasParticipantIdentityInput(payload)) {
|
|
51
|
+
const pii = createPiiService(c, "offer", row.offerId);
|
|
52
|
+
await pii.upsertParticipantIdentity(c.get("db"), "offer", row.id, payload, c.get("userId"));
|
|
53
|
+
return c.json({
|
|
54
|
+
data: await transactionsService.getOfferParticipantById(c.get("db"), row.id),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
return c.json({ data: row });
|
|
58
|
+
})
|
|
59
|
+
.get("/offer-participants/:id/travel-details", async (c) => {
|
|
60
|
+
const participant = await transactionsService.getOfferParticipantById(c.get("db"), c.req.param("id"));
|
|
61
|
+
if (!participant)
|
|
62
|
+
return notFound(c, "Offer participant not found");
|
|
63
|
+
const auth = await authorizeTransactionPiiAccess(c, {
|
|
64
|
+
participantKind: "offer",
|
|
65
|
+
participantId: participant.id,
|
|
66
|
+
parentId: participant.offerId,
|
|
67
|
+
action: "read",
|
|
68
|
+
});
|
|
69
|
+
if (!auth.allowed)
|
|
70
|
+
return auth.response;
|
|
71
|
+
const pii = createPiiService(c, "offer", participant.offerId);
|
|
72
|
+
const row = await pii.getParticipantIdentity(c.get("db"), "offer", participant.id, c.get("userId"));
|
|
73
|
+
if (!row) {
|
|
74
|
+
await logTransactionPiiAccess(c, {
|
|
75
|
+
participantKind: "offer",
|
|
76
|
+
parentId: participant.offerId,
|
|
77
|
+
participantId: participant.id,
|
|
78
|
+
action: "read",
|
|
79
|
+
outcome: "denied",
|
|
80
|
+
reason: "travel_details_not_found",
|
|
81
|
+
});
|
|
82
|
+
return c.json({ error: "Offer participant travel details not found" }, 404);
|
|
83
|
+
}
|
|
84
|
+
return c.json({ data: row });
|
|
85
|
+
})
|
|
86
|
+
.patch("/offer-participants/:id/travel-details", async (c) => {
|
|
87
|
+
const participant = await transactionsService.getOfferParticipantById(c.get("db"), c.req.param("id"));
|
|
88
|
+
if (!participant)
|
|
89
|
+
return notFound(c, "Offer participant not found");
|
|
90
|
+
const auth = await authorizeTransactionPiiAccess(c, {
|
|
91
|
+
participantKind: "offer",
|
|
92
|
+
participantId: participant.id,
|
|
93
|
+
parentId: participant.offerId,
|
|
94
|
+
action: "update",
|
|
95
|
+
});
|
|
96
|
+
if (!auth.allowed)
|
|
97
|
+
return auth.response;
|
|
98
|
+
const pii = createPiiService(c, "offer", participant.offerId);
|
|
99
|
+
const row = await pii.upsertParticipantIdentity(c.get("db"), "offer", participant.id, updateOfferParticipantSchema.parse(await c.req.json()), c.get("userId"));
|
|
100
|
+
return row ? c.json({ data: row }) : notFound(c, "Offer participant not found");
|
|
101
|
+
})
|
|
102
|
+
.delete("/offer-participants/:id/travel-details", async (c) => {
|
|
103
|
+
const participant = await transactionsService.getOfferParticipantById(c.get("db"), c.req.param("id"));
|
|
104
|
+
if (!participant)
|
|
105
|
+
return notFound(c, "Offer participant not found");
|
|
106
|
+
const auth = await authorizeTransactionPiiAccess(c, {
|
|
107
|
+
participantKind: "offer",
|
|
108
|
+
participantId: participant.id,
|
|
109
|
+
parentId: participant.offerId,
|
|
110
|
+
action: "delete",
|
|
111
|
+
});
|
|
112
|
+
if (!auth.allowed)
|
|
113
|
+
return auth.response;
|
|
114
|
+
const pii = createPiiService(c, "offer", participant.offerId);
|
|
115
|
+
const row = await pii.deleteParticipantIdentity(c.get("db"), "offer", participant.id, c.get("userId"));
|
|
116
|
+
return row
|
|
117
|
+
? c.json({ success: true })
|
|
118
|
+
: c.json({ error: "Offer participant travel details not found" }, 404);
|
|
119
|
+
})
|
|
120
|
+
.delete("/offer-participants/:id", async (c) => {
|
|
121
|
+
const row = await transactionsService.deleteOfferParticipant(c.get("db"), c.req.param("id"));
|
|
122
|
+
return row ? c.json({ success: true }) : notFound(c, "Offer participant not found");
|
|
123
|
+
})
|
|
124
|
+
.get("/offer-items", async (c) => {
|
|
125
|
+
const query = offerItemListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
|
|
126
|
+
return c.json(await transactionsService.listOfferItems(c.get("db"), query));
|
|
127
|
+
})
|
|
128
|
+
.post("/offer-items", async (c) => c.json({
|
|
129
|
+
data: await transactionsService.createOfferItem(c.get("db"), insertOfferItemSchema.parse(await c.req.json())),
|
|
130
|
+
}, 201))
|
|
131
|
+
.get("/offer-items/:id", async (c) => {
|
|
132
|
+
const row = await transactionsService.getOfferItemById(c.get("db"), c.req.param("id"));
|
|
133
|
+
return row ? c.json({ data: row }) : notFound(c, "Offer item not found");
|
|
134
|
+
})
|
|
135
|
+
.patch("/offer-items/:id", async (c) => {
|
|
136
|
+
const row = await transactionsService.updateOfferItem(c.get("db"), c.req.param("id"), updateOfferItemSchema.parse(await c.req.json()));
|
|
137
|
+
return row ? c.json({ data: row }) : notFound(c, "Offer item not found");
|
|
138
|
+
})
|
|
139
|
+
.delete("/offer-items/:id", async (c) => {
|
|
140
|
+
const row = await transactionsService.deleteOfferItem(c.get("db"), c.req.param("id"));
|
|
141
|
+
return row ? c.json({ success: true }) : notFound(c, "Offer item not found");
|
|
142
|
+
})
|
|
143
|
+
.get("/offer-item-participants", async (c) => {
|
|
144
|
+
const query = offerItemParticipantListQuerySchema.parse(Object.fromEntries(new URL(c.req.url).searchParams));
|
|
145
|
+
return c.json(await transactionsService.listOfferItemParticipants(c.get("db"), query));
|
|
146
|
+
})
|
|
147
|
+
.post("/offer-item-participants", async (c) => c.json({
|
|
148
|
+
data: await transactionsService.createOfferItemParticipant(c.get("db"), insertOfferItemParticipantSchema.parse(await c.req.json())),
|
|
149
|
+
}, 201))
|
|
150
|
+
.get("/offer-item-participants/:id", async (c) => {
|
|
151
|
+
const row = await transactionsService.getOfferItemParticipantById(c.get("db"), c.req.param("id"));
|
|
152
|
+
return row ? c.json({ data: row }) : notFound(c, "Offer item participant not found");
|
|
153
|
+
})
|
|
154
|
+
.patch("/offer-item-participants/:id", async (c) => {
|
|
155
|
+
const row = await transactionsService.updateOfferItemParticipant(c.get("db"), c.req.param("id"), updateOfferItemParticipantSchema.parse(await c.req.json()));
|
|
156
|
+
return row ? c.json({ data: row }) : notFound(c, "Offer item participant not found");
|
|
157
|
+
})
|
|
158
|
+
.delete("/offer-item-participants/:id", async (c) => {
|
|
159
|
+
const row = await transactionsService.deleteOfferItemParticipant(c.get("db"), c.req.param("id"));
|
|
160
|
+
return row ? c.json({ success: true }) : notFound(c, "Offer item participant not found");
|
|
161
|
+
});
|