@revenexx/cover 0.2.10 → 0.2.11
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.
|
@@ -24,7 +24,7 @@ const { data: list, status, error, refresh } = useFetch<OrderList>(
|
|
|
24
24
|
{ key: `account-order-list:${props.listId}` },
|
|
25
25
|
);
|
|
26
26
|
|
|
27
|
-
const isOwner = computed(() =>
|
|
27
|
+
const isOwner = computed(() => !!list.value && isOwnOrderList(list.value, authStore.user));
|
|
28
28
|
const listValue = computed(() =>
|
|
29
29
|
Math.round((list.value?.positions ?? []).reduce((sum, p) => sum + p.price * p.quantity, 0) * 100) / 100,
|
|
30
30
|
);
|
|
@@ -53,7 +53,7 @@ const listsWithProduct = computed(() =>
|
|
|
53
53
|
|
|
54
54
|
const onListNames = computed(() => listsWithProduct.value.map(list => list.name).join(", "));
|
|
55
55
|
|
|
56
|
-
const isOwn = (list: OrderList): boolean => list
|
|
56
|
+
const isOwn = (list: OrderList): boolean => isOwnOrderList(list, auth.user);
|
|
57
57
|
|
|
58
58
|
const lastUsedList = computed(() =>
|
|
59
59
|
(lists.value ?? []).find(list => list.id === lastUsedId.value && isOwn(list)) ?? null);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { AuthUser } from "../interfaces/auth";
|
|
2
|
+
import type { OrderList } from "../interfaces/account/order-lists";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Whether the signed-in user owns an order list.
|
|
6
|
+
*
|
|
7
|
+
* The cover `OrderList.owner.id` is NOT one stable identity across data modes:
|
|
8
|
+
* in live mode the orderlists app keys lists by the **contact** id
|
|
9
|
+
* (`owner_id = contactId`), while the mock service stores the platform **user**
|
|
10
|
+
* id (`user.$id`). The auth user carries both, so match either — comparing only
|
|
11
|
+
* against `$id` silently failed in live (contactId ≠ $id), which made every
|
|
12
|
+
* list look un-owned and disabled the "add to an existing list" toggles.
|
|
13
|
+
*/
|
|
14
|
+
export function isOwnOrderList(
|
|
15
|
+
list: Pick<OrderList, "owner">,
|
|
16
|
+
user: Pick<AuthUser, "$id" | "contactId"> | null | undefined,
|
|
17
|
+
): boolean {
|
|
18
|
+
if (!user) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
return list.owner.id === user.$id || (!!user.contactId && list.owner.id === user.contactId);
|
|
22
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revenexx/cover",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.11",
|
|
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",
|
|
@@ -58,7 +58,11 @@ async function actor(event: H3Event): Promise<{ contactId: string; name: string;
|
|
|
58
58
|
|
|
59
59
|
function toCoverPosition(item: AppItem): OrderListPosition {
|
|
60
60
|
return {
|
|
61
|
-
id
|
|
61
|
+
// cover treats position.id as the PRODUCT id (membership flag on the
|
|
62
|
+
// PDP, cart line identity) — map it from product_id, not the item row
|
|
63
|
+
// id. Legacy items written before product_id was persisted fall back to
|
|
64
|
+
// the row id so they still render (they just won't match a PDP product).
|
|
65
|
+
id: item.product_id ?? String(item.id),
|
|
62
66
|
sku: item.sku ?? "",
|
|
63
67
|
name: item.name,
|
|
64
68
|
...(item.image ? { image: item.image } : {}),
|
|
@@ -86,6 +90,9 @@ function toItemInput(position: OrderListPosition): Models.OrderListItemInput {
|
|
|
86
90
|
const item: Record<string, unknown> = {
|
|
87
91
|
name: position.name,
|
|
88
92
|
quantity: Number(position.quantity) || 1,
|
|
93
|
+
// position.id is the cover product id — persist it as product_id so the
|
|
94
|
+
// PDP "on these lists" flag and cart de-dup can match by product later.
|
|
95
|
+
...(position.id ? { product_id: position.id } : {}),
|
|
89
96
|
...(position.sku ? { sku: position.sku } : {}),
|
|
90
97
|
...(position.image ? { image: position.image } : {}),
|
|
91
98
|
...(position.unit ? { unit: position.unit } : {}),
|
|
@@ -100,6 +107,32 @@ function toItemInput(position: OrderListPosition): Models.OrderListItemInput {
|
|
|
100
107
|
return item as Models.OrderListItemInput;
|
|
101
108
|
}
|
|
102
109
|
|
|
110
|
+
/**
|
|
111
|
+
* cover position → the FLAT, camelCase params of `orderlistsItemsCreate`
|
|
112
|
+
* (single-item append). Distinct from `toItemInput`: that builds the
|
|
113
|
+
* snake_case `OrderListItemInput` wire model for the `items[]` arrays of
|
|
114
|
+
* create/replace, but `orderlistsItemsCreate` is a flat camelCase-param method
|
|
115
|
+
* — spreading the snake_case shape there silently dropped product_id/tax_rate/
|
|
116
|
+
* the *_slug fields (the SDK only reads its declared camelCase params).
|
|
117
|
+
*/
|
|
118
|
+
function toItemCreateParams(position: OrderListPosition): Record<string, unknown> {
|
|
119
|
+
return {
|
|
120
|
+
name: position.name,
|
|
121
|
+
quantity: Number(position.quantity) || 1,
|
|
122
|
+
...(position.id ? { productId: position.id } : {}),
|
|
123
|
+
...(position.sku ? { sku: position.sku } : {}),
|
|
124
|
+
...(position.image ? { image: position.image } : {}),
|
|
125
|
+
...(position.unit ? { unit: position.unit } : {}),
|
|
126
|
+
...(position.price != null ? { price: Number(position.price) } : {}),
|
|
127
|
+
...(position.taxRate != null ? { taxRate: Number(position.taxRate) } : {}),
|
|
128
|
+
...(position.costCenterId ? { costCenterId: position.costCenterId } : {}),
|
|
129
|
+
...(position.positionTexts ? { positionTexts: position.positionTexts } : {}),
|
|
130
|
+
...(position.customSku ? { customSku: position.customSku } : {}),
|
|
131
|
+
...(position.categorySlug ? { categorySlug: position.categorySlug } : {}),
|
|
132
|
+
...(position.subcategorySlug ? { subcategorySlug: position.subcategorySlug } : {}),
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
103
136
|
function toCoverList(row: AppList): OrderList {
|
|
104
137
|
return {
|
|
105
138
|
id: row.id,
|
|
@@ -170,7 +203,7 @@ export async function updateOrderList(
|
|
|
170
203
|
await sdk.orderlists.orderlistsItemsReplace({ listId: id, items: body.positions.map(toItemInput) });
|
|
171
204
|
}
|
|
172
205
|
for (const position of body.appendPositions ?? []) {
|
|
173
|
-
await sdk.orderlists.orderlistsItemsCreate({ listId: id, ...
|
|
206
|
+
await sdk.orderlists.orderlistsItemsCreate({ listId: id, ...toItemCreateParams(position) } as Parameters<typeof sdk.orderlists.orderlistsItemsCreate>[0]);
|
|
174
207
|
}
|
|
175
208
|
|
|
176
209
|
return toCoverList(await sdk.orderlists.orderlistsGet({ id }) as unknown as AppList);
|