Skip to content

Commit 71708b1

Browse files
committed
Entity name shown instead of Unknown
1 parent f0560cf commit 71708b1

File tree

6 files changed

+37
-9
lines changed

6 files changed

+37
-9
lines changed

src/routes/(protected)/dynamic-entities/system/+page.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
99
// Helper function to extract entity name from the entity object
1010
function getEntityName(entity: any): string {
11-
return entity.entityName || "Unknown";
11+
// The entity name is the schema key (Piano, Guitar, etc.)
12+
return getSchemaKey(entity) || "Unknown";
1213
}
1314
1415
// Helper function to extract the schema key (FooBar, Guitar, Piano, etc.)

src/routes/(protected)/dynamic-entities/system/[id]/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
2929
const schema = getSchema(entity);
3030
const schemaKey = getSchemaKey(entity);
31-
const entityName = entity.entityName || "Unknown";
31+
const entityName = schemaKey || "Unknown";
3232
const properties = schema?.properties || {};
3333
const requiredFields = schema?.required || [];
3434
const description = schema?.description || "No description available";

src/routes/(protected)/dynamic-entities/system/[id]/crud/+page.server.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,12 @@ export const load: PageServerLoad = async ({ params, locals }) => {
4242
}
4343

4444
// Fetch data records for this entity
45-
// Extract entity name to fetch data records
46-
const entityName = entity.entityName;
45+
// Extract entity name from the schema key (Piano, Guitar, etc.)
46+
const metadataFields = ["userId", "dynamicEntityId", "hasPersonalEntity"];
47+
const keys = Object.keys(entity).filter(
48+
(key) => !metadataFields.includes(key),
49+
);
50+
const entityName = keys[0] || null;
4751
let dataRecords = [];
4852

4953
if (entityName) {

src/routes/(protected)/dynamic-entities/system/[id]/crud/+page.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
let { data }: { data: PageData } = $props();
66
77
const entity = data.entity;
8-
const entityName = entity.entityName || "Unknown";
98
109
// Helper function to extract the schema key
1110
function getSchemaKey(entity: any): string {
@@ -28,6 +27,8 @@
2827
}
2928
3029
const schema = getSchema(entity);
30+
const schemaKey = getSchemaKey(entity);
31+
const entityName = schemaKey || "Unknown";
3132
const properties = schema?.properties || {};
3233
const requiredFields = schema?.required || [];
3334

src/routes/api/dynamic-entities/[id]/data/+server.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,26 @@ import { createLogger } from "$lib/utils/logger";
77
const logger = createLogger("DynamicEntityDataAPI");
88

99
// Helper function to get entity name from entity ID
10-
async function getEntityName(entityId: string, accessToken: string): Promise<string | null> {
10+
async function getEntityName(
11+
entityId: string,
12+
accessToken: string,
13+
): Promise<string | null> {
1114
try {
1215
const entitiesResponse = await obp_requests.get(
1316
"/obp/v4.0.0/management/system-dynamic-entities",
1417
accessToken,
1518
);
1619
const entities = entitiesResponse.dynamic_entities || [];
1720
const entity = entities.find((e: any) => e.dynamicEntityId === entityId);
18-
return entity?.entityName || null;
21+
22+
if (!entity) return null;
23+
24+
// The entity name is the schema key (Piano, Guitar, etc.)
25+
const metadataFields = ["userId", "dynamicEntityId", "hasPersonalEntity"];
26+
const keys = Object.keys(entity).filter(
27+
(key) => !metadataFields.includes(key),
28+
);
29+
return keys[0] || null;
1930
} catch (err) {
2031
logger.error("Error fetching entity name:", err);
2132
return null;

src/routes/api/dynamic-entities/[id]/data/[recordId]/+server.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,26 @@ import { createLogger } from "$lib/utils/logger";
77
const logger = createLogger("DynamicEntityRecordAPI");
88

99
// Helper function to get entity name from entity ID
10-
async function getEntityName(entityId: string, accessToken: string): Promise<string | null> {
10+
async function getEntityName(
11+
entityId: string,
12+
accessToken: string,
13+
): Promise<string | null> {
1114
try {
1215
const entitiesResponse = await obp_requests.get(
1316
"/obp/v4.0.0/management/system-dynamic-entities",
1417
accessToken,
1518
);
1619
const entities = entitiesResponse.dynamic_entities || [];
1720
const entity = entities.find((e: any) => e.dynamicEntityId === entityId);
18-
return entity?.entityName || null;
21+
22+
if (!entity) return null;
23+
24+
// The entity name is the schema key (Piano, Guitar, etc.)
25+
const metadataFields = ["userId", "dynamicEntityId", "hasPersonalEntity"];
26+
const keys = Object.keys(entity).filter(
27+
(key) => !metadataFields.includes(key),
28+
);
29+
return keys[0] || null;
1930
} catch (err) {
2031
logger.error("Error fetching entity name:", err);
2132
return null;

0 commit comments

Comments
 (0)