@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
|
@@ -96,6 +96,27 @@
|
|
|
96
96
|
"refresh": "Refresh",
|
|
97
97
|
"notFound": "Order not found",
|
|
98
98
|
"searchPlaceholder": "Search by order number or item…",
|
|
99
|
+
"returns": {
|
|
100
|
+
"requestReturn": "Request return",
|
|
101
|
+
"modalTitle": "Request a return",
|
|
102
|
+
"reason": "Reason (optional)",
|
|
103
|
+
"reasonPlaceholder": "Tell us why you're returning these items…",
|
|
104
|
+
"quantity": "Quantity",
|
|
105
|
+
"maxReturnable": "Up to {count} returnable",
|
|
106
|
+
"submit": "Submit return",
|
|
107
|
+
"cancel": "Cancel",
|
|
108
|
+
"success": "Return requested",
|
|
109
|
+
"error": "Return could not be requested",
|
|
110
|
+
"existingTitle": "Returns",
|
|
111
|
+
"emptyReturnable": "None of these positions can be returned.",
|
|
112
|
+
"status": {
|
|
113
|
+
"requested": "Requested",
|
|
114
|
+
"approved": "Approved",
|
|
115
|
+
"received": "Received",
|
|
116
|
+
"completed": "Completed",
|
|
117
|
+
"rejected": "Rejected"
|
|
118
|
+
}
|
|
119
|
+
},
|
|
99
120
|
"detail": {
|
|
100
121
|
"progressTitle": "Order progress",
|
|
101
122
|
"steps": {
|
|
@@ -186,6 +207,7 @@
|
|
|
186
207
|
"iotDevices": "IoT devices",
|
|
187
208
|
"catalogs": "Catalogs",
|
|
188
209
|
"accountSettings": "Master data",
|
|
210
|
+
"organization": "Company",
|
|
189
211
|
"addresses": "Addresses",
|
|
190
212
|
"users": "Users",
|
|
191
213
|
"roles": "Roles",
|
|
@@ -458,5 +480,69 @@
|
|
|
458
480
|
"alwaysActive": "Always add to the active cart",
|
|
459
481
|
"alwaysActiveHint": "Adding articles no longer asks which cart the item should go to.",
|
|
460
482
|
"saved": "Setting saved"
|
|
483
|
+
},
|
|
484
|
+
"organization": {
|
|
485
|
+
"title": "Company",
|
|
486
|
+
"description": "View and edit your company details.",
|
|
487
|
+
"companySection": "Company",
|
|
488
|
+
"edit": "Edit",
|
|
489
|
+
"editTitle": "Edit company details",
|
|
490
|
+
"save": "Save",
|
|
491
|
+
"cancel": "Cancel",
|
|
492
|
+
"saved": "Company details saved",
|
|
493
|
+
"saveError": "Save failed",
|
|
494
|
+
"errorTitle": "Company details unavailable",
|
|
495
|
+
"errorDescription": "The company details could not be loaded.",
|
|
496
|
+
"fields": {
|
|
497
|
+
"name": "Company name",
|
|
498
|
+
"vatId": "VAT ID",
|
|
499
|
+
"status": "Status"
|
|
500
|
+
},
|
|
501
|
+
"status": {
|
|
502
|
+
"active": "Active",
|
|
503
|
+
"blocked": "Blocked"
|
|
504
|
+
},
|
|
505
|
+
"empty": {
|
|
506
|
+
"title": "No company",
|
|
507
|
+
"description": "Your account is not linked to a company."
|
|
508
|
+
}
|
|
509
|
+
},
|
|
510
|
+
"team": {
|
|
511
|
+
"title": "Users",
|
|
512
|
+
"description": "Manage your company's users and their roles.",
|
|
513
|
+
"searchPlaceholder": "Search by name, email or role…",
|
|
514
|
+
"invite": "Invite user",
|
|
515
|
+
"inviteTitle": "Invite user",
|
|
516
|
+
"editTitle": "Change role",
|
|
517
|
+
"primary": "Primary contact",
|
|
518
|
+
"firstName": "First name",
|
|
519
|
+
"lastName": "Last name",
|
|
520
|
+
"save": "Save",
|
|
521
|
+
"cancel": "Cancel",
|
|
522
|
+
"saved": "Saved",
|
|
523
|
+
"saveError": "Save failed",
|
|
524
|
+
"errorTitle": "Users unavailable",
|
|
525
|
+
"errorDescription": "The users could not be loaded.",
|
|
526
|
+
"columns": {
|
|
527
|
+
"name": "Name",
|
|
528
|
+
"email": "Email",
|
|
529
|
+
"role": "Role",
|
|
530
|
+
"status": "Status"
|
|
531
|
+
},
|
|
532
|
+
"roles": {
|
|
533
|
+
"buyer": "Buyer",
|
|
534
|
+
"approver": "Approver",
|
|
535
|
+
"admin": "Admin",
|
|
536
|
+
"requester": "Requester"
|
|
537
|
+
},
|
|
538
|
+
"statuses": {
|
|
539
|
+
"invited": "Invited",
|
|
540
|
+
"active": "Active",
|
|
541
|
+
"blocked": "Blocked"
|
|
542
|
+
},
|
|
543
|
+
"empty": {
|
|
544
|
+
"title": "No users",
|
|
545
|
+
"description": "Invite the first user via “Invite user”."
|
|
546
|
+
}
|
|
461
547
|
}
|
|
462
548
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revenexx/cover",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.8",
|
|
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.12",
|
|
42
42
|
"@revenexx/storage-model-viewer": "^0.3.0",
|
|
43
43
|
"@vueuse/core": "^14.3.0",
|
|
44
44
|
"typesense": "^3.0.5"
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { AccountOrder, AccountOrderListResponse, AccountOrderReturn } from "../../../../../app/interfaces/account/order-list";
|
|
2
|
+
import { enrichMockOrderReturnables } from "../[id].get";
|
|
3
|
+
|
|
4
|
+
interface ReturnRequestBody {
|
|
5
|
+
positions?: { orderItemId: string; quantity: number }[];
|
|
6
|
+
reason?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Request a return for shipped positions of one order. Live: hands the
|
|
11
|
+
* positions to the orders app (which guards each quantity against the still-
|
|
12
|
+
* returnable amount). Mock: appends a demo return so the demo shop surfaces
|
|
13
|
+
* the feature end-to-end. Returns the refreshed order either way.
|
|
14
|
+
*/
|
|
15
|
+
export default defineEventHandler(async (event): Promise<AccountOrder> => {
|
|
16
|
+
const user = await getAuthService(event).me(event);
|
|
17
|
+
if (!user) {
|
|
18
|
+
throw createError({ statusCode: 401, message: "Unauthorized" });
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const id = getRouterParam(event, "id") ?? "";
|
|
22
|
+
const body = await readBody<ReturnRequestBody>(event);
|
|
23
|
+
const positions = (body?.positions ?? []).filter(p => p.orderItemId && Number(p.quantity) > 0);
|
|
24
|
+
if (positions.length === 0) {
|
|
25
|
+
throw createError({ statusCode: 422, message: "No positions to return" });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (resolveOrderServiceKey(event) === "api") {
|
|
29
|
+
try {
|
|
30
|
+
const order = await requestOrderReturn(
|
|
31
|
+
id,
|
|
32
|
+
positions.map(p => ({ orderItemId: p.orderItemId, quantity: Number(p.quantity) })),
|
|
33
|
+
body?.reason,
|
|
34
|
+
);
|
|
35
|
+
if (!order) {
|
|
36
|
+
throw createError({ statusCode: 404, message: "Order not found" });
|
|
37
|
+
}
|
|
38
|
+
return order;
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
if (isError(err)) {
|
|
42
|
+
throw err;
|
|
43
|
+
}
|
|
44
|
+
getLogService().error("Live order return failed", apiErrorContext(err));
|
|
45
|
+
throw createError({ statusCode: 502, message: "Order service unavailable" });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Mock: persist a demo return on the order and echo it back enriched.
|
|
50
|
+
const history = await readCoverMutableJson<AccountOrderListResponse>("account/order-list.json");
|
|
51
|
+
const index = history.orders.findIndex(o => o.id === id);
|
|
52
|
+
if (index < 0) {
|
|
53
|
+
throw createError({ statusCode: 404, message: "Order not found" });
|
|
54
|
+
}
|
|
55
|
+
const order = history.orders[index]!;
|
|
56
|
+
const demoReturn: AccountOrderReturn = {
|
|
57
|
+
id: `ret-${Date.now()}`,
|
|
58
|
+
number: `RMA-${order.id}-${(order.returns?.length ?? 0) + 1}`,
|
|
59
|
+
status: "requested",
|
|
60
|
+
positions: positions.map((p) => {
|
|
61
|
+
const match = order.positions.find(pos => (pos.orderItemId ?? pos.id) === p.orderItemId);
|
|
62
|
+
return { name: match?.name ?? p.orderItemId, quantity: Number(p.quantity) };
|
|
63
|
+
}),
|
|
64
|
+
};
|
|
65
|
+
const updated: AccountOrder = { ...order, returns: [...(order.returns ?? []), demoReturn] };
|
|
66
|
+
history.orders[index] = updated;
|
|
67
|
+
await writeCoverMutableJson("account/order-list.json", history);
|
|
68
|
+
return enrichMockOrderReturnables(updated);
|
|
69
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AccountOrderListResponse } from "../../../../app/interfaces/account/order-list";
|
|
1
|
+
import type { AccountOrder, AccountOrderListResponse } from "../../../../app/interfaces/account/order-list";
|
|
2
2
|
|
|
3
3
|
/** Single order from the account history (live: by display number). */
|
|
4
4
|
export default defineEventHandler(async (event) => {
|
|
@@ -31,5 +31,30 @@ export default defineEventHandler(async (event) => {
|
|
|
31
31
|
if (!order) {
|
|
32
32
|
throw createError({ statusCode: 404, message: "Order not found" });
|
|
33
33
|
}
|
|
34
|
-
return order;
|
|
34
|
+
return enrichMockOrderReturnables(order);
|
|
35
35
|
});
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Mock orders carry no fulfillment quantities — surface the self-service
|
|
39
|
+
* return feature in the demo by treating every position of a shipped/delivered
|
|
40
|
+
* order as fully returnable (minus any already-requested demo return).
|
|
41
|
+
*/
|
|
42
|
+
export function enrichMockOrderReturnables(order: AccountOrder): AccountOrder {
|
|
43
|
+
if (order.status !== "shipped" && order.status !== "delivered") {
|
|
44
|
+
return order;
|
|
45
|
+
}
|
|
46
|
+
const returnedByItem: Record<string, number> = {};
|
|
47
|
+
for (const ret of order.returns ?? []) {
|
|
48
|
+
for (const pos of ret.positions) {
|
|
49
|
+
returnedByItem[pos.name] = (returnedByItem[pos.name] ?? 0) + pos.quantity;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return {
|
|
53
|
+
...order,
|
|
54
|
+
positions: order.positions.map(p => ({
|
|
55
|
+
...p,
|
|
56
|
+
orderItemId: p.orderItemId ?? p.id,
|
|
57
|
+
returnableQuantity: Math.max(0, p.quantity - (returnedByItem[p.name] ?? 0)),
|
|
58
|
+
})),
|
|
59
|
+
};
|
|
60
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { AccountOrganizationResponse } from "../../../app/interfaces/account/organization";
|
|
2
|
+
|
|
3
|
+
export default defineEventHandler(async (event): Promise<AccountOrganizationResponse> => {
|
|
4
|
+
return { organization: await getOrganizationService(event).get(event) };
|
|
5
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { AccountOrganization, AccountOrganizationFormState } from "../../../app/interfaces/account/organization";
|
|
2
|
+
|
|
3
|
+
export default defineEventHandler(async (event): Promise<AccountOrganization> => {
|
|
4
|
+
const body = await readBody<AccountOrganizationFormState>(event);
|
|
5
|
+
return getOrganizationService(event).update(event, {
|
|
6
|
+
name: String(body?.name ?? "").trim(),
|
|
7
|
+
vatId: String(body?.vatId ?? "").trim(),
|
|
8
|
+
});
|
|
9
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AccountTeamMember, AccountTeamRole } from "../../../../app/interfaces/account/team";
|
|
2
|
+
|
|
3
|
+
interface TeamUpdateBody {
|
|
4
|
+
readonly role?: unknown;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
const ROLES: AccountTeamRole[] = ["buyer", "approver", "admin", "requester"];
|
|
8
|
+
|
|
9
|
+
export default defineEventHandler(async (event): Promise<AccountTeamMember> => {
|
|
10
|
+
const id = getRouterParam(event, "id");
|
|
11
|
+
if (!id) {
|
|
12
|
+
throw createError({ statusCode: 400, statusMessage: "Missing member id" });
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const body = await readBody<TeamUpdateBody>(event);
|
|
16
|
+
if (!ROLES.includes(body.role as AccountTeamRole)) {
|
|
17
|
+
throw createError({ statusCode: 422, statusMessage: "Invalid role" });
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return getTeamService(event).update(event, id, { role: body.role as AccountTeamRole });
|
|
21
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AccountTeamMember, AccountTeamMemberFormState, AccountTeamRole } from "../../../app/interfaces/account/team";
|
|
2
|
+
|
|
3
|
+
const ROLES: AccountTeamRole[] = ["buyer", "approver", "admin", "requester"];
|
|
4
|
+
|
|
5
|
+
function toRole(value: unknown): AccountTeamRole {
|
|
6
|
+
return ROLES.includes(value as AccountTeamRole) ? value as AccountTeamRole : "buyer";
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export default defineEventHandler(async (event): Promise<AccountTeamMember> => {
|
|
10
|
+
const body = await readBody<Partial<AccountTeamMemberFormState>>(event);
|
|
11
|
+
const email = String(body?.email ?? "").trim();
|
|
12
|
+
if (!email) {
|
|
13
|
+
throw createError({ statusCode: 422, statusMessage: "email is required" });
|
|
14
|
+
}
|
|
15
|
+
return getTeamService(event).invite(event, {
|
|
16
|
+
email,
|
|
17
|
+
firstName: String(body?.firstName ?? "").trim(),
|
|
18
|
+
lastName: String(body?.lastName ?? "").trim(),
|
|
19
|
+
role: toRole(body?.role),
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
|
|
3
|
+
import type { AccountOrganization, AccountOrganizationFormState } from "../../app/interfaces/account/organization";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Service contract for the buyer's own company (organization) — the account
|
|
7
|
+
* organization page reads and edits it.
|
|
8
|
+
* - "mock" — bundled demo company (account/organization.json)
|
|
9
|
+
* - "api" — the contact's organization in the customers app via the public API
|
|
10
|
+
* Register the active implementation via app.config → organizationService.
|
|
11
|
+
*/
|
|
12
|
+
export interface IOrganizationService {
|
|
13
|
+
/** The signed-in contact's organization, or null when the session carries none. */
|
|
14
|
+
get(event: H3Event): Promise<AccountOrganization | null>;
|
|
15
|
+
update(event: H3Event, input: AccountOrganizationFormState): Promise<AccountOrganization>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
|
|
3
|
+
import type { AccountTeamMember, AccountTeamMemberFormState, AccountTeamRole } from "../../app/interfaces/account/team";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Service contract for the buyer's company team (contacts) — the account
|
|
7
|
+
* team page lists members, invites new ones and changes their role.
|
|
8
|
+
* - "mock" — bundled demo members (kept in-memory for the process lifetime)
|
|
9
|
+
* - "api" — the organization's contacts in the customers app via the public API
|
|
10
|
+
* Register the active implementation via app.config → contactsService.
|
|
11
|
+
*/
|
|
12
|
+
export interface ITeamService {
|
|
13
|
+
/** The signed-in contact's organization members. */
|
|
14
|
+
list(event: H3Event): Promise<AccountTeamMember[]>;
|
|
15
|
+
invite(event: H3Event, input: AccountTeamMemberFormState): Promise<AccountTeamMember>;
|
|
16
|
+
update(event: H3Event, id: string, patch: { role: AccountTeamRole }): Promise<AccountTeamMember>;
|
|
17
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
|
|
3
|
+
import type { AccountOrganization, AccountOrganizationFormState } from "../../app/interfaces/account/organization";
|
|
4
|
+
|
|
5
|
+
import type { IOrganizationService } from "../interfaces/organization";
|
|
6
|
+
|
|
7
|
+
/** Raw organization row from the customers app (snake_case API shape). */
|
|
8
|
+
interface ApiOrgRow {
|
|
9
|
+
id: string;
|
|
10
|
+
name: string | null;
|
|
11
|
+
vat_id: string | null;
|
|
12
|
+
status: string | null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function toAccountOrganization(row: ApiOrgRow): AccountOrganization {
|
|
16
|
+
return {
|
|
17
|
+
id: row.id,
|
|
18
|
+
name: row.name ?? "",
|
|
19
|
+
vatId: row.vat_id ?? "",
|
|
20
|
+
status: row.status === "blocked" ? "blocked" : "active",
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Live company data: the signed-in contact's organization in the customers
|
|
26
|
+
* app. The organization id comes from the session cookie (auth/me link);
|
|
27
|
+
* contacts without an organization (private buyers) have none.
|
|
28
|
+
*/
|
|
29
|
+
export class ApiOrganizationService implements IOrganizationService {
|
|
30
|
+
async get(event: H3Event): Promise<AccountOrganization | null> {
|
|
31
|
+
const { organization_id } = sessionOrderRefs(event);
|
|
32
|
+
if (!organization_id) {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
const row = await useRevenexxSdk().customers.customersOrganizationsGet({
|
|
37
|
+
id: organization_id,
|
|
38
|
+
}) as unknown as ApiOrgRow;
|
|
39
|
+
return toAccountOrganization(row);
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
getLogService().error("API request failed: organization/get", apiErrorContext(err));
|
|
43
|
+
throw createError({ statusCode: 502, statusMessage: "Organization service unavailable" });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async update(event: H3Event, input: AccountOrganizationFormState): Promise<AccountOrganization> {
|
|
48
|
+
const { organization_id } = sessionOrderRefs(event);
|
|
49
|
+
if (!organization_id) {
|
|
50
|
+
throw createError({ statusCode: 401, statusMessage: "No organization in session" });
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
const row = await useRevenexxSdk().customers.customersOrganizationsUpdate({
|
|
54
|
+
id: organization_id,
|
|
55
|
+
name: input.name,
|
|
56
|
+
vatId: input.vatId || undefined,
|
|
57
|
+
}) as unknown as ApiOrgRow;
|
|
58
|
+
return toAccountOrganization(row);
|
|
59
|
+
}
|
|
60
|
+
catch (err) {
|
|
61
|
+
if (err instanceof RevenexxException && (err.code === 400 || err.code === 422)) {
|
|
62
|
+
throw createError({ statusCode: 422, message: err.message });
|
|
63
|
+
}
|
|
64
|
+
getLogService().error("API request failed: organization/update", apiErrorContext(err));
|
|
65
|
+
throw createError({ statusCode: 502, statusMessage: "Organization service unavailable" });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { ContactRole } from "@revenexx/sdk";
|
|
2
|
+
import type { H3Event } from "h3";
|
|
3
|
+
|
|
4
|
+
import type { AccountTeamMember, AccountTeamMemberFormState, AccountTeamRole, AccountTeamStatus } from "../../app/interfaces/account/team";
|
|
5
|
+
|
|
6
|
+
import type { ITeamService } from "../interfaces/team";
|
|
7
|
+
|
|
8
|
+
/** Raw contact row from the customers app (snake_case API shape). */
|
|
9
|
+
interface ApiContactRow {
|
|
10
|
+
id?: string;
|
|
11
|
+
organization_id?: string | null;
|
|
12
|
+
email?: string;
|
|
13
|
+
first_name?: string | null;
|
|
14
|
+
last_name?: string | null;
|
|
15
|
+
role?: string;
|
|
16
|
+
status?: string;
|
|
17
|
+
is_primary?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const ROLES: AccountTeamRole[] = ["buyer", "approver", "admin", "requester"];
|
|
21
|
+
const STATUSES: AccountTeamStatus[] = ["invited", "active", "blocked"];
|
|
22
|
+
|
|
23
|
+
function toRole(value: string | undefined): AccountTeamRole {
|
|
24
|
+
return ROLES.includes(value as AccountTeamRole) ? value as AccountTeamRole : "buyer";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function toStatus(value: string | undefined): AccountTeamStatus {
|
|
28
|
+
return STATUSES.includes(value as AccountTeamStatus) ? value as AccountTeamStatus : "active";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function toAccountTeamMember(row: ApiContactRow): AccountTeamMember {
|
|
32
|
+
return {
|
|
33
|
+
id: row.id ?? "",
|
|
34
|
+
firstName: row.first_name ?? "",
|
|
35
|
+
lastName: row.last_name ?? "",
|
|
36
|
+
email: row.email ?? "",
|
|
37
|
+
role: toRole(row.role),
|
|
38
|
+
status: toStatus(row.status),
|
|
39
|
+
isPrimary: row.is_primary === true,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Live team data: the contacts of the signed-in contact's organization in the
|
|
45
|
+
* customers app. The organization id comes from the session cookie (auth/me
|
|
46
|
+
* link); contacts without an organization (private buyers) get an empty list.
|
|
47
|
+
*/
|
|
48
|
+
export class ApiTeamService implements ITeamService {
|
|
49
|
+
async list(event: H3Event): Promise<AccountTeamMember[]> {
|
|
50
|
+
const { organization_id } = sessionOrderRefs(event);
|
|
51
|
+
if (!organization_id) {
|
|
52
|
+
return [];
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
// Typed list filter (customers.contacts.list declares its query
|
|
56
|
+
// params — @revenexx/sdk >= 0.0.12), so org scoping is server-side.
|
|
57
|
+
const { items } = await useRevenexxSdk().customers.customersContactsList({
|
|
58
|
+
organizationId: organization_id,
|
|
59
|
+
limit: 200,
|
|
60
|
+
}) as unknown as { items: ApiContactRow[] };
|
|
61
|
+
return (items ?? []).map(toAccountTeamMember);
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
getLogService().error("API request failed: team/list", apiErrorContext(err));
|
|
65
|
+
throw createError({ statusCode: 502, statusMessage: "Team service unavailable" });
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async invite(event: H3Event, input: AccountTeamMemberFormState): Promise<AccountTeamMember> {
|
|
70
|
+
const { organization_id } = sessionOrderRefs(event);
|
|
71
|
+
if (!organization_id) {
|
|
72
|
+
throw createError({ statusCode: 401, statusMessage: "No organization in session" });
|
|
73
|
+
}
|
|
74
|
+
try {
|
|
75
|
+
const row = await useRevenexxSdk().customers.customersContactsCreate({
|
|
76
|
+
email: input.email,
|
|
77
|
+
firstName: input.firstName || undefined,
|
|
78
|
+
lastName: input.lastName || undefined,
|
|
79
|
+
role: input.role as ContactRole,
|
|
80
|
+
organizationId: organization_id,
|
|
81
|
+
}) as unknown as ApiContactRow;
|
|
82
|
+
return toAccountTeamMember(row);
|
|
83
|
+
}
|
|
84
|
+
catch (err) {
|
|
85
|
+
if (err instanceof RevenexxException && (err.code === 400 || err.code === 422)) {
|
|
86
|
+
throw createError({ statusCode: 422, message: err.message });
|
|
87
|
+
}
|
|
88
|
+
getLogService().error("API request failed: team/invite", apiErrorContext(err));
|
|
89
|
+
throw createError({ statusCode: 502, statusMessage: "Team service unavailable" });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async update(_event: H3Event, id: string, patch: { role: AccountTeamRole }): Promise<AccountTeamMember> {
|
|
94
|
+
try {
|
|
95
|
+
const row = await useRevenexxSdk().customers.customersContactsUpdate({
|
|
96
|
+
id,
|
|
97
|
+
role: patch.role as ContactRole,
|
|
98
|
+
}) as unknown as ApiContactRow;
|
|
99
|
+
return toAccountTeamMember(row);
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
if (err instanceof RevenexxException && (err.code === 400 || err.code === 422)) {
|
|
103
|
+
throw createError({ statusCode: 422, message: err.message });
|
|
104
|
+
}
|
|
105
|
+
getLogService().error("API request failed: team/update", apiErrorContext(err));
|
|
106
|
+
throw createError({ statusCode: 502, statusMessage: "Team service unavailable" });
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
|
|
3
|
+
import type { AccountOrganization, AccountOrganizationFormState } from "../../app/interfaces/account/organization";
|
|
4
|
+
|
|
5
|
+
import type { IOrganizationService } from "../interfaces/organization";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Demo company: seeded from the bundled organization config, with edits kept
|
|
9
|
+
* in-memory for the process lifetime so the demo "save" round-trips visibly
|
|
10
|
+
* (the registry holds this as a singleton).
|
|
11
|
+
*/
|
|
12
|
+
export class MockOrganizationService implements IOrganizationService {
|
|
13
|
+
private override: Partial<AccountOrganizationFormState> = {};
|
|
14
|
+
|
|
15
|
+
async get(_event: H3Event): Promise<AccountOrganization> {
|
|
16
|
+
const cfg = await readCoverConfigJson<{ name?: string }>("account/organization.json");
|
|
17
|
+
return {
|
|
18
|
+
id: "demo-org",
|
|
19
|
+
name: this.override.name ?? cfg.name ?? "Demo GmbH",
|
|
20
|
+
vatId: this.override.vatId ?? "DE123456789",
|
|
21
|
+
status: "active",
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async update(event: H3Event, input: AccountOrganizationFormState): Promise<AccountOrganization> {
|
|
26
|
+
this.override = { name: input.name, vatId: input.vatId };
|
|
27
|
+
return this.get(event);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { H3Event } from "h3";
|
|
2
|
+
|
|
3
|
+
import type { AccountTeamMember, AccountTeamMemberFormState, AccountTeamRole } from "../../app/interfaces/account/team";
|
|
4
|
+
|
|
5
|
+
import type { ITeamService } from "../interfaces/team";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Demo team: a small set of seeded members kept in-memory for the process
|
|
9
|
+
* lifetime so the demo "invite" / "change role" round-trip visibly (the
|
|
10
|
+
* registry holds this as a singleton).
|
|
11
|
+
*/
|
|
12
|
+
export class MockTeamService implements ITeamService {
|
|
13
|
+
private members: AccountTeamMember[] = [
|
|
14
|
+
{ id: "demo-1", firstName: "Anna", lastName: "Berger", email: "anna.berger@demo-gmbh.de", role: "admin", status: "active", isPrimary: true },
|
|
15
|
+
{ id: "demo-2", firstName: "Tobias", lastName: "Klein", email: "tobias.klein@demo-gmbh.de", role: "approver", status: "active", isPrimary: false },
|
|
16
|
+
{ id: "demo-3", firstName: "Sara", lastName: "Vogel", email: "sara.vogel@demo-gmbh.de", role: "buyer", status: "invited", isPrimary: false },
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
private nextId = 4;
|
|
20
|
+
|
|
21
|
+
async list(_event: H3Event): Promise<AccountTeamMember[]> {
|
|
22
|
+
return this.members;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async invite(_event: H3Event, input: AccountTeamMemberFormState): Promise<AccountTeamMember> {
|
|
26
|
+
const member: AccountTeamMember = {
|
|
27
|
+
id: `demo-${this.nextId++}`,
|
|
28
|
+
firstName: input.firstName,
|
|
29
|
+
lastName: input.lastName,
|
|
30
|
+
email: input.email,
|
|
31
|
+
role: input.role,
|
|
32
|
+
status: "invited",
|
|
33
|
+
isPrimary: false,
|
|
34
|
+
};
|
|
35
|
+
this.members = [...this.members, member];
|
|
36
|
+
return member;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async update(_event: H3Event, id: string, patch: { role: AccountTeamRole }): Promise<AccountTeamMember> {
|
|
40
|
+
const existing = this.members.find(m => m.id === id);
|
|
41
|
+
if (!existing) {
|
|
42
|
+
throw createError({ statusCode: 404, statusMessage: "Member not found" });
|
|
43
|
+
}
|
|
44
|
+
const updated: AccountTeamMember = { ...existing, role: patch.role };
|
|
45
|
+
this.members = this.members.map(m => (m.id === id ? updated : m));
|
|
46
|
+
return updated;
|
|
47
|
+
}
|
|
48
|
+
}
|