@revenexx/cover 0.2.3 → 0.2.5
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/app/components/account/orders/AccountOrdersTable.vue +37 -1
- package/app/composables/useAccountOrders.ts +16 -4
- package/app/interfaces/account/order-list.ts +4 -0
- package/i18n/locales/de/account.json +1 -0
- package/i18n/locales/en/account.json +1 -0
- package/package.json +2 -2
- package/server/api/account/orders.get.ts +20 -8
- package/server/utils/liveOrderLists.ts +59 -45
- package/server/utils/liveOrders.ts +4 -3
- package/server/utils/revenexxSdk.ts +3 -0
|
@@ -14,8 +14,16 @@ const localePath = useLocalePath();
|
|
|
14
14
|
const { to } = useAppUrl();
|
|
15
15
|
const toast = useToast();
|
|
16
16
|
const cart = useCartStore();
|
|
17
|
-
const { orders, status, error } = useAccountOrders();
|
|
17
|
+
const { orders, total, page, pageSize, status, error } = useAccountOrders();
|
|
18
18
|
const { formatCurrency } = useCartSummaryFormatting();
|
|
19
|
+
|
|
20
|
+
const pageCount = computed(() => Math.max(1, Math.ceil(total.value / pageSize)));
|
|
21
|
+
function prevPage(): void {
|
|
22
|
+
if (page.value > 1) page.value -= 1;
|
|
23
|
+
}
|
|
24
|
+
function nextPage(): void {
|
|
25
|
+
if (page.value < pageCount.value) page.value += 1;
|
|
26
|
+
}
|
|
19
27
|
const { tableUi } = useDataTable();
|
|
20
28
|
|
|
21
29
|
const statusColors: Record<AccountOrderStatus, "info" | "warning" | "primary" | "success" | "error"> = {
|
|
@@ -276,6 +284,34 @@ async function orderAgain(order: AccountOrder): Promise<void> {
|
|
|
276
284
|
/>
|
|
277
285
|
</template>
|
|
278
286
|
</UTable>
|
|
287
|
+
|
|
288
|
+
<div
|
|
289
|
+
v-if="total > pageSize"
|
|
290
|
+
class="flex items-center justify-between gap-4 pt-4 border-t border-(--ui-border)"
|
|
291
|
+
>
|
|
292
|
+
<span class="text-sm text-muted">
|
|
293
|
+
{{ t('orders.pagination.summary', { from: (page - 1) * pageSize + 1, to: Math.min(page * pageSize, total), total }) }}
|
|
294
|
+
</span>
|
|
295
|
+
<div class="flex items-center gap-2">
|
|
296
|
+
<UButton
|
|
297
|
+
:icon="icon('chevron-left')"
|
|
298
|
+
color="neutral"
|
|
299
|
+
variant="outline"
|
|
300
|
+
:disabled="page <= 1"
|
|
301
|
+
:label="t('orders.pagination.prev')"
|
|
302
|
+
@click="prevPage"
|
|
303
|
+
/>
|
|
304
|
+
<UButton
|
|
305
|
+
:icon="icon('chevron-right')"
|
|
306
|
+
color="neutral"
|
|
307
|
+
variant="outline"
|
|
308
|
+
trailing
|
|
309
|
+
:disabled="page >= pageCount"
|
|
310
|
+
:label="t('orders.pagination.next')"
|
|
311
|
+
@click="nextPage"
|
|
312
|
+
/>
|
|
313
|
+
</div>
|
|
314
|
+
</div>
|
|
279
315
|
</template>
|
|
280
316
|
</div>
|
|
281
317
|
</template>
|
|
@@ -1,16 +1,28 @@
|
|
|
1
1
|
import { accountApi } from "../api/account";
|
|
2
2
|
import type { AccountOrder, AccountOrderListResponse } from "../interfaces/account/order-list";
|
|
3
3
|
|
|
4
|
+
const PAGE_SIZE = 20;
|
|
5
|
+
|
|
4
6
|
export const useAccountOrders = () => {
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const page = ref(1);
|
|
8
|
+
|
|
9
|
+
const { data, status, error, refresh } = useFetch<AccountOrderListResponse>(
|
|
10
|
+
() => `${accountApi.orders()}?offset=${(page.value - 1) * PAGE_SIZE}&limit=${PAGE_SIZE}`,
|
|
11
|
+
{
|
|
12
|
+
key: "account-orders",
|
|
13
|
+
default: () => ({ orders: [] as AccountOrder[] }),
|
|
14
|
+
watch: [page],
|
|
15
|
+
},
|
|
16
|
+
);
|
|
9
17
|
|
|
10
18
|
const orders = computed(() => data.value.orders);
|
|
19
|
+
const total = computed(() => data.value.total ?? orders.value.length);
|
|
11
20
|
|
|
12
21
|
return {
|
|
13
22
|
orders,
|
|
23
|
+
total,
|
|
24
|
+
page,
|
|
25
|
+
pageSize: PAGE_SIZE,
|
|
14
26
|
status,
|
|
15
27
|
error,
|
|
16
28
|
refresh,
|
|
@@ -50,4 +50,8 @@ export interface AccountOrder {
|
|
|
50
50
|
|
|
51
51
|
export interface AccountOrderListResponse {
|
|
52
52
|
readonly orders: AccountOrder[];
|
|
53
|
+
/** Total orders for the contact (server-paginated history). */
|
|
54
|
+
readonly total?: number;
|
|
55
|
+
/** More pages beyond this window. */
|
|
56
|
+
readonly hasMore?: boolean;
|
|
53
57
|
}
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"orders": {
|
|
57
57
|
"title": "Ihre Bestellungen",
|
|
58
58
|
"description": "Alle Ihre bisherigen Bestellungen im Überblick.",
|
|
59
|
+
"pagination": { "summary": "{from}–{to} von {total} Bestellungen", "prev": "Zurück", "next": "Weiter" },
|
|
59
60
|
"errorTitle": "Bestellungen konnten nicht geladen werden",
|
|
60
61
|
"errorDescription": "Bitte versuchen Sie es später erneut.",
|
|
61
62
|
"empty": {
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"orders": {
|
|
57
57
|
"title": "Your orders",
|
|
58
58
|
"description": "View and track all your past orders.",
|
|
59
|
+
"pagination": { "summary": "{from}–{to} of {total} orders", "prev": "Back", "next": "Next" },
|
|
59
60
|
"errorTitle": "Orders could not be loaded",
|
|
60
61
|
"errorDescription": "Please try again later.",
|
|
61
62
|
"empty": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revenexx/cover",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.5",
|
|
4
4
|
"description": "Cover — revenexx design system for Nuxt. Distributed as a Nuxt layer: generic UI components, theming tokens and stores shared by the demo shop, custom storefronts and the Blokkli theme.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./nuxt.config.ts",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"@formkit/vue": "^1.6.0",
|
|
39
39
|
"@iconify-json/lucide": "^1.2.111",
|
|
40
40
|
"@internationalized/date": "^3.12.0",
|
|
41
|
-
"@revenexx/sdk": "^0.0.
|
|
41
|
+
"@revenexx/sdk": "^0.0.10",
|
|
42
42
|
"@revenexx/storage-model-viewer": "^0.3.0",
|
|
43
43
|
"@vueuse/core": "^14.3.0",
|
|
44
44
|
"typesense": "^3.0.5"
|
|
@@ -19,20 +19,32 @@ export default defineEventHandler(async (event): Promise<AccountOrderListRespons
|
|
|
19
19
|
}
|
|
20
20
|
try {
|
|
21
21
|
const sdk = useRevenexxSdk();
|
|
22
|
-
//
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
//
|
|
28
|
-
//
|
|
22
|
+
// Server-paginated: page through the contact's full history.
|
|
23
|
+
const q = getQuery(event);
|
|
24
|
+
const limit = Math.min(Math.max(Number(q.limit) || LIVE_HISTORY_LIMIT, 1), 100);
|
|
25
|
+
const offset = Math.max(Number(q.offset) || 0, 0);
|
|
26
|
+
// Typed list call (orders.list now declares its query parameters —
|
|
27
|
+
// @revenexx/sdk >= 0.0.9). order=created_at.desc is REQUIRED: without
|
|
28
|
+
// it mountCrud returns the oldest rows first, so with a limit the
|
|
29
|
+
// NEWEST orders fall outside the window and never show. created_at is
|
|
30
|
+
// not-null (placed_at can be null), so it sorts deterministically.
|
|
31
|
+
// The list response stays untyped (the page schema is unnamed), so
|
|
32
|
+
// cast to the known list shape.
|
|
33
|
+
const { items, page } = await sdk.orders.ordersList({
|
|
34
|
+
contactId, limit, offset, order: "created_at.desc",
|
|
35
|
+
}) as unknown as {
|
|
36
|
+
items: LiveOrder[];
|
|
37
|
+
page?: { total?: number; hasMore?: boolean };
|
|
38
|
+
};
|
|
39
|
+
// The list rows carry no positions — load the aggregates (one page
|
|
40
|
+
// at a time, so this stays a bounded fan-out).
|
|
29
41
|
const aggregates = await Promise.all(
|
|
30
42
|
items.map(async row => await sdk.orders.ordersGet({ id: row.id }) as unknown as LiveOrder),
|
|
31
43
|
);
|
|
32
44
|
const orders = aggregates
|
|
33
45
|
.sort((a, b) => (b.placed_at ?? b.created_at).localeCompare(a.placed_at ?? a.created_at))
|
|
34
46
|
.map(mapLiveOrderToAccount);
|
|
35
|
-
return { orders };
|
|
47
|
+
return { orders, total: page?.total ?? offset + orders.length, hasMore: page?.hasMore ?? false };
|
|
36
48
|
}
|
|
37
49
|
catch (err) {
|
|
38
50
|
getLogService().error("Live order history failed", apiErrorContext(err));
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import type { H3Event } from "h3";
|
|
2
|
+
import type { Models } from "@revenexx/sdk";
|
|
2
3
|
|
|
3
4
|
import type { OrderList, OrderListPosition } from "../../app/interfaces/account/order-lists";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Live order lists through the `orderlists` gateway app
|
|
7
|
-
* (revenexx-apps/orderlists)
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* (revenexx-apps/orderlists), via the typed @revenexx/sdk `orderlists`
|
|
9
|
+
* service. Request params are camelCase (the SDK maps to the gateway's
|
|
10
|
+
* snake_case); responses come back snake_case.
|
|
10
11
|
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
* app
|
|
12
|
+
* Only the visibility-filtered LIST still uses the `sdk.call()` escape
|
|
13
|
+
* hatch: `orderlistsList()` declares no query parameters in the contract
|
|
14
|
+
* yet, so it cannot filter by owner/organization. Everything else is typed.
|
|
15
|
+
*
|
|
16
|
+
* Identity: the app stores `owner_id`/`organization_id` and `GET /orderlists`
|
|
17
|
+
* returns the owner's own lists ∪ the organization's shared lists. We supply
|
|
18
|
+
* both from the authenticated contact (auth/me). The cover OrderList keeps
|
|
19
|
+
* `public` UI-side; it maps to the app's `shared`.
|
|
16
20
|
*/
|
|
17
21
|
|
|
18
22
|
interface AppItem {
|
|
@@ -71,21 +75,30 @@ function toCoverPosition(item: AppItem): OrderListPosition {
|
|
|
71
75
|
};
|
|
72
76
|
}
|
|
73
77
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
/**
|
|
79
|
+
* cover position → the gateway's item payload. `Models.OrderListItemInput`
|
|
80
|
+
* is snake_case (tax_rate, cost_center_id, …), so we build snake_case keys
|
|
81
|
+
* that match the typed shape directly. (The SDK also deep-converts nested
|
|
82
|
+
* camelCase keys since @revenexx/sdk >= 0.0.10 / DX-55, but building the
|
|
83
|
+
* wire keys here keeps this type-aligned with the model.) The conditional
|
|
84
|
+
* spreads still need a cast for exactness.
|
|
85
|
+
*/
|
|
86
|
+
function toItemInput(position: OrderListPosition): Models.OrderListItemInput {
|
|
87
|
+
const item: Record<string, unknown> = {
|
|
77
88
|
name: position.name,
|
|
78
89
|
quantity: Number(position.quantity) || 1,
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
90
|
+
...(position.sku ? { sku: position.sku } : {}),
|
|
91
|
+
...(position.image ? { image: position.image } : {}),
|
|
92
|
+
...(position.unit ? { unit: position.unit } : {}),
|
|
93
|
+
...(position.price != null ? { price: position.price } : {}),
|
|
94
|
+
...(position.taxRate != null ? { tax_rate: position.taxRate } : {}),
|
|
95
|
+
...(position.costCenterId ? { cost_center_id: position.costCenterId } : {}),
|
|
96
|
+
...(position.positionTexts ? { position_texts: position.positionTexts } : {}),
|
|
97
|
+
...(position.customSku ? { custom_sku: position.customSku } : {}),
|
|
98
|
+
...(position.categorySlug ? { category_slug: position.categorySlug } : {}),
|
|
99
|
+
...(position.subcategorySlug ? { subcategory_slug: position.subcategorySlug } : {}),
|
|
88
100
|
};
|
|
101
|
+
return item as Models.OrderListItemInput;
|
|
89
102
|
}
|
|
90
103
|
|
|
91
104
|
function toCoverList(row: AppList): OrderList {
|
|
@@ -101,21 +114,23 @@ function toCoverList(row: AppList): OrderList {
|
|
|
101
114
|
};
|
|
102
115
|
}
|
|
103
116
|
|
|
104
|
-
/** Own lists ∪ org-
|
|
117
|
+
/** Own lists ∪ org-shared, each with its positions (bounded fan-out). */
|
|
105
118
|
export async function listOrderLists(event: H3Event): Promise<OrderList[]> {
|
|
106
119
|
const me = await actor(event);
|
|
107
120
|
const sdk = useRevenexxSdk();
|
|
121
|
+
// Escape hatch: orderlistsList() declares no query params, so it cannot
|
|
122
|
+
// filter by owner/organization. The fan-out to full lists is typed.
|
|
108
123
|
const { items } = await sdk.call<{ items: AppList[] }>("GET", "/v1/orderlists", {
|
|
109
124
|
query: { owner_id: me.contactId, ...(me.organizationId ? { organization_id: me.organizationId } : {}) },
|
|
110
125
|
});
|
|
111
|
-
const full = await Promise.all(items.map(async row => sdk.
|
|
112
|
-
return full.map(toCoverList);
|
|
126
|
+
const full = await Promise.all(items.map(async row => sdk.orderlists.orderlistsGet({ id: row.id })));
|
|
127
|
+
return full.map(row => toCoverList(row as unknown as AppList));
|
|
113
128
|
}
|
|
114
129
|
|
|
115
130
|
export async function getOrderList(event: H3Event, id: string): Promise<OrderList> {
|
|
116
131
|
await actor(event);
|
|
117
|
-
const row = await useRevenexxSdk().
|
|
118
|
-
return toCoverList(row);
|
|
132
|
+
const row = await useRevenexxSdk().orderlists.orderlistsGet({ id });
|
|
133
|
+
return toCoverList(row as unknown as AppList);
|
|
119
134
|
}
|
|
120
135
|
|
|
121
136
|
export async function createOrderList(
|
|
@@ -123,18 +138,16 @@ export async function createOrderList(
|
|
|
123
138
|
body: { name: string; kind?: string; public?: boolean; positions?: OrderListPosition[] },
|
|
124
139
|
): Promise<OrderList> {
|
|
125
140
|
const me = await actor(event);
|
|
126
|
-
const row = await useRevenexxSdk().
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
items: Array.isArray(body.positions) ? body.positions.map(toAppItem) : [],
|
|
135
|
-
},
|
|
141
|
+
const row = await useRevenexxSdk().orderlists.orderlistsCreate({
|
|
142
|
+
name: body.name,
|
|
143
|
+
ownerId: me.contactId,
|
|
144
|
+
ownerName: me.name,
|
|
145
|
+
kind: body.kind === "label" ? "label" : "shopping",
|
|
146
|
+
shared: Boolean(body.public),
|
|
147
|
+
...(me.organizationId ? { organizationId: me.organizationId } : {}),
|
|
148
|
+
...(Array.isArray(body.positions) ? { items: body.positions.map(toItemInput) } : {}),
|
|
136
149
|
});
|
|
137
|
-
return toCoverList(row);
|
|
150
|
+
return toCoverList(row as unknown as AppList);
|
|
138
151
|
}
|
|
139
152
|
|
|
140
153
|
export async function updateOrderList(
|
|
@@ -145,24 +158,25 @@ export async function updateOrderList(
|
|
|
145
158
|
await actor(event);
|
|
146
159
|
const sdk = useRevenexxSdk();
|
|
147
160
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
161
|
+
if (typeof body.name === "string" && body.name.trim() || typeof body.public === "boolean") {
|
|
162
|
+
await sdk.orderlists.orderlistsUpdate({
|
|
163
|
+
id,
|
|
164
|
+
...(typeof body.name === "string" && body.name.trim() ? { name: body.name.trim() } : {}),
|
|
165
|
+
...(typeof body.public === "boolean" ? { shared: body.public } : {}),
|
|
166
|
+
});
|
|
153
167
|
}
|
|
154
168
|
|
|
155
169
|
if (Array.isArray(body.positions)) {
|
|
156
|
-
await sdk.
|
|
170
|
+
await sdk.orderlists.orderlistsItemsReplace({ listId: id, items: body.positions.map(toItemInput) });
|
|
157
171
|
}
|
|
158
172
|
for (const position of body.appendPositions ?? []) {
|
|
159
|
-
await sdk.
|
|
173
|
+
await sdk.orderlists.orderlistsItemsCreate({ listId: id, ...toItemInput(position) });
|
|
160
174
|
}
|
|
161
175
|
|
|
162
|
-
return toCoverList(await sdk.
|
|
176
|
+
return toCoverList(await sdk.orderlists.orderlistsGet({ id }) as unknown as AppList);
|
|
163
177
|
}
|
|
164
178
|
|
|
165
179
|
export async function deleteOrderList(event: H3Event, id: string): Promise<void> {
|
|
166
180
|
await actor(event);
|
|
167
|
-
await useRevenexxSdk().
|
|
181
|
+
await useRevenexxSdk().orderlists.orderlistsDelete({ id });
|
|
168
182
|
}
|
|
@@ -136,9 +136,10 @@ export function mapLiveOrderToAccount(order: LiveOrder): AccountOrder {
|
|
|
136
136
|
/** Fetch one live order by its display number (the account history id). */
|
|
137
137
|
export async function getLiveOrderByNumber(number: string): Promise<LiveOrder | null> {
|
|
138
138
|
const sdk = useRevenexxSdk();
|
|
139
|
-
//
|
|
140
|
-
//
|
|
141
|
-
|
|
139
|
+
// Typed list filter — orders.list now declares its query parameters
|
|
140
|
+
// (@revenexx/sdk >= 0.0.10). The list response stays untyped (unnamed page
|
|
141
|
+
// schema), so cast to the known shape.
|
|
142
|
+
const { items } = await sdk.orders.ordersList({ number, limit: 1 }) as unknown as { items: LiveOrder[] };
|
|
142
143
|
const row = items[0];
|
|
143
144
|
if (!row) {
|
|
144
145
|
return null;
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
Customers,
|
|
5
5
|
Inventories,
|
|
6
6
|
Markets,
|
|
7
|
+
Orderlists,
|
|
7
8
|
Orders,
|
|
8
9
|
Payments,
|
|
9
10
|
Prices,
|
|
@@ -39,6 +40,7 @@ export interface RevenexxSdk {
|
|
|
39
40
|
readonly customers: Customers;
|
|
40
41
|
readonly inventories: Inventories;
|
|
41
42
|
readonly markets: Markets;
|
|
43
|
+
readonly orderlists: Orderlists;
|
|
42
44
|
readonly orders: Orders;
|
|
43
45
|
readonly payments: Payments;
|
|
44
46
|
readonly prices: Prices;
|
|
@@ -202,6 +204,7 @@ export function useRevenexxSdk(): RevenexxSdk {
|
|
|
202
204
|
customers: new Customers(client),
|
|
203
205
|
inventories: new Inventories(client),
|
|
204
206
|
markets: new Markets(client),
|
|
207
|
+
orderlists: new Orderlists(client),
|
|
205
208
|
orders: new Orders(client),
|
|
206
209
|
payments: new Payments(client),
|
|
207
210
|
prices: new Prices(client),
|