@revenexx/cover 0.2.6 → 0.2.8
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/api/account.ts +4 -0
- package/app/app.config.ts +2 -0
- package/app/components/account/orders/AccountOrderDetail.vue +198 -2
- package/app/components/account/organization/AccountOrganization.vue +159 -0
- package/app/components/account/team/AccountTeam.vue +346 -0
- package/app/composables/useAccountOrganization.ts +25 -0
- package/app/composables/useAccountTeam.ts +34 -0
- package/app/config/navigation.ts +2 -1
- package/app/interfaces/account/order-list.ts +13 -0
- package/app/interfaces/account/organization.ts +19 -0
- package/app/interfaces/account/team.ts +25 -0
- package/i18n/locales/de/account.json +86 -0
- package/i18n/locales/en/account.json +86 -0
- package/package.json +2 -2
- package/server/api/account/orders/[id]/return.post.ts +69 -0
- package/server/api/account/orders/[id].get.ts +27 -2
- package/server/api/account/organization.get.ts +5 -0
- package/server/api/account/organization.put.ts +9 -0
- package/server/api/account/team/[id].put.ts +21 -0
- package/server/api/account/team.get.ts +5 -0
- package/server/api/account/team.post.ts +21 -0
- package/server/interfaces/organization.ts +16 -0
- package/server/interfaces/team.ts +17 -0
- package/server/services/ApiOrganizationService.ts +68 -0
- package/server/services/ApiTeamService.ts +109 -0
- package/server/services/MockOrganizationService.ts +29 -0
- package/server/services/MockTeamService.ts +48 -0
- package/server/utils/liveOrders.ts +68 -3
- package/server/utils/organizationService.ts +25 -0
- package/server/utils/teamService.ts +25 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { H3Event } from "h3";
|
|
2
2
|
|
|
3
3
|
import type { StoredSession } from "../../app/interfaces/auth";
|
|
4
|
-
import type { AccountOrder, AccountOrderPosition, AccountOrderStatus, AccountOrderPaymentStatus } from "../../app/interfaces/account/order-list";
|
|
4
|
+
import type { AccountOrder, AccountOrderPosition, AccountOrderReturn, AccountOrderStatus, AccountOrderPaymentStatus } from "../../app/interfaces/account/order-list";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Live orders via the orders app — placing from the checkout snapshot and
|
|
@@ -42,6 +42,14 @@ export interface LiveOrder {
|
|
|
42
42
|
completed_at: string | null;
|
|
43
43
|
items?: LiveOrderItem[];
|
|
44
44
|
shipments?: Array<{ number: string; carrier: string | null; tracking_code: string | null; shipped_at: string }>;
|
|
45
|
+
returns?: LiveOrderReturn[];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface LiveOrderReturn {
|
|
49
|
+
id: string;
|
|
50
|
+
number: string;
|
|
51
|
+
status: string;
|
|
52
|
+
positions?: Array<{ order_item_id?: string; name?: string | null; quantity: number }>;
|
|
45
53
|
}
|
|
46
54
|
|
|
47
55
|
/** The buyer's identity refs from the session cookie (guests place openly). */
|
|
@@ -78,9 +86,25 @@ const addressLine = (a: Record<string, unknown> | null | undefined): string =>
|
|
|
78
86
|
[a?.companyName, a?.street, `${a?.postalCode ?? ""} ${a?.city ?? ""}`.trim()]
|
|
79
87
|
.filter(Boolean).join(" · ");
|
|
80
88
|
|
|
81
|
-
|
|
89
|
+
/** Units already returned per order_item id, summed across all return records. */
|
|
90
|
+
function returnedByOrderItem(returns: LiveOrderReturn[] | undefined): Record<string, number> {
|
|
91
|
+
const totals: Record<string, number> = {};
|
|
92
|
+
for (const ret of returns ?? []) {
|
|
93
|
+
for (const pos of ret.positions ?? []) {
|
|
94
|
+
if (pos.order_item_id) {
|
|
95
|
+
totals[pos.order_item_id] = (totals[pos.order_item_id] ?? 0) + Number(pos.quantity);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return totals;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function mapPositions(items: LiveOrderItem[] | undefined, returns: LiveOrderReturn[] | undefined): AccountOrderPosition[] {
|
|
103
|
+
const returned = returnedByOrderItem(returns);
|
|
82
104
|
return (items ?? []).map((item) => {
|
|
83
105
|
const snapshot = (item.product ?? {}) as Record<string, unknown>;
|
|
106
|
+
const shipped = Number(item.quantity_shipped) || 0;
|
|
107
|
+
const returnable = Math.max(0, shipped - (returned[item.id] ?? 0));
|
|
84
108
|
return {
|
|
85
109
|
id: item.product_id ?? item.sku ?? item.id,
|
|
86
110
|
sku: item.sku ?? "",
|
|
@@ -91,10 +115,24 @@ function mapPositions(items: LiveOrderItem[] | undefined): AccountOrderPosition[
|
|
|
91
115
|
lineTotal: Number(item.line_total),
|
|
92
116
|
...(snapshot.categorySlug ? { categorySlug: String(snapshot.categorySlug) } : {}),
|
|
93
117
|
...(snapshot.subcategorySlug ? { subcategorySlug: String(snapshot.subcategorySlug) } : {}),
|
|
118
|
+
orderItemId: item.id,
|
|
119
|
+
returnableQuantity: returnable,
|
|
94
120
|
};
|
|
95
121
|
});
|
|
96
122
|
}
|
|
97
123
|
|
|
124
|
+
function mapReturns(returns: LiveOrderReturn[] | undefined): AccountOrderReturn[] {
|
|
125
|
+
return (returns ?? []).map(ret => ({
|
|
126
|
+
id: ret.id,
|
|
127
|
+
number: ret.number,
|
|
128
|
+
status: ret.status,
|
|
129
|
+
positions: (ret.positions ?? []).map(pos => ({
|
|
130
|
+
name: pos.name ?? "",
|
|
131
|
+
quantity: Number(pos.quantity),
|
|
132
|
+
})),
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
135
|
+
|
|
98
136
|
/** Live order aggregate → the account history contract. */
|
|
99
137
|
export function mapLiveOrderToAccount(order: LiveOrder): AccountOrder {
|
|
100
138
|
const placed = order.placed_at ?? order.created_at;
|
|
@@ -122,7 +160,8 @@ export function mapLiveOrderToAccount(order: LiveOrder): AccountOrder {
|
|
|
122
160
|
total: Number(order.grand_total),
|
|
123
161
|
currency: order.currency,
|
|
124
162
|
...(order.customer_order_number ? { orderNumber: order.customer_order_number } : {}),
|
|
125
|
-
positions: mapPositions(order.items),
|
|
163
|
+
positions: mapPositions(order.items, order.returns),
|
|
164
|
+
...(order.returns?.length ? { returns: mapReturns(order.returns) } : {}),
|
|
126
165
|
deliveryAddress: addressLine(order.shipping_address),
|
|
127
166
|
billingAddress: addressLine(order.billing_address),
|
|
128
167
|
...(order.payment?.method ? { paymentMethod: order.payment.method } : {}),
|
|
@@ -146,3 +185,29 @@ export async function getLiveOrderByNumber(number: string): Promise<LiveOrder |
|
|
|
146
185
|
}
|
|
147
186
|
return await sdk.orders.ordersGet({ id: row.id }) as unknown as LiveOrder;
|
|
148
187
|
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Request a return for shipped positions of an order (by display number).
|
|
191
|
+
* Resolves the order id, submits the return via the orders app — which guards
|
|
192
|
+
* each quantity against the still-returnable amount — and returns the freshly
|
|
193
|
+
* mapped order aggregate so the UI reflects the new return immediately.
|
|
194
|
+
*/
|
|
195
|
+
export async function requestOrderReturn(
|
|
196
|
+
orderNumber: string,
|
|
197
|
+
positions: { orderItemId: string; quantity: number }[],
|
|
198
|
+
reason?: string,
|
|
199
|
+
): Promise<AccountOrder | null> {
|
|
200
|
+
const sdk = useRevenexxSdk();
|
|
201
|
+
const { items } = await sdk.orders.ordersList({ number: orderNumber, limit: 1 }) as unknown as { items: LiveOrder[] };
|
|
202
|
+
const row = items[0];
|
|
203
|
+
if (!row) {
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
await sdk.orders.ordersReturn({
|
|
207
|
+
id: row.id,
|
|
208
|
+
positions: positions.map(p => ({ order_item_id: p.orderItemId, quantity: p.quantity })),
|
|
209
|
+
...(reason ? { reason } : {}),
|
|
210
|
+
} as unknown as Parameters<typeof sdk.orders.ordersReturn>[0]);
|
|
211
|
+
const refreshed = await sdk.orders.ordersGet({ id: row.id }) as unknown as LiveOrder;
|
|
212
|
+
return mapLiveOrderToAccount(refreshed);
|
|
213
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
|
|
3
|
+
import type { IOrganizationService } from "../interfaces/organization";
|
|
4
|
+
import { ApiOrganizationService } from "../services/ApiOrganizationService";
|
|
5
|
+
import { MockOrganizationService } from "../services/MockOrganizationService";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Registry of organization (company) service implementations. The active one
|
|
9
|
+
* is selected by the `organizationService` key in app.config.ts:
|
|
10
|
+
* - "mock" — bundled demo company (account/organization.json)
|
|
11
|
+
* - "api" — the contact's organization in the customers app (public revenexx API)
|
|
12
|
+
*/
|
|
13
|
+
const serviceRegistry: Record<string, IOrganizationService> = {
|
|
14
|
+
mock: new MockOrganizationService(),
|
|
15
|
+
api: new ApiOrganizationService(),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function getOrganizationService(event?: H3Event): IOrganizationService {
|
|
19
|
+
const key = resolveServiceKey(event, {
|
|
20
|
+
domain: "organizationService",
|
|
21
|
+
mockKey: "mock",
|
|
22
|
+
liveKey: "api",
|
|
23
|
+
});
|
|
24
|
+
return serviceRegistry[key] ?? serviceRegistry["mock"]!;
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
|
|
3
|
+
import type { ITeamService } from "../interfaces/team";
|
|
4
|
+
import { ApiTeamService } from "../services/ApiTeamService";
|
|
5
|
+
import { MockTeamService } from "../services/MockTeamService";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Registry of team (company contacts) service implementations. The active one
|
|
9
|
+
* is selected by the `contactsService` key in app.config.ts:
|
|
10
|
+
* - "mock" — bundled demo members (kept in-memory for the process lifetime)
|
|
11
|
+
* - "api" — the organization's contacts in the customers app (public revenexx API)
|
|
12
|
+
*/
|
|
13
|
+
const serviceRegistry: Record<string, ITeamService> = {
|
|
14
|
+
mock: new MockTeamService(),
|
|
15
|
+
api: new ApiTeamService(),
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export function getTeamService(event?: H3Event): ITeamService {
|
|
19
|
+
const key = resolveServiceKey(event, {
|
|
20
|
+
domain: "contactsService",
|
|
21
|
+
mockKey: "mock",
|
|
22
|
+
liveKey: "api",
|
|
23
|
+
});
|
|
24
|
+
return serviceRegistry[key] ?? serviceRegistry["mock"]!;
|
|
25
|
+
}
|