Skip to content

Commit 492a2b1

Browse files
committed
fix: ♻️ Code refactored
1 parent aa76b60 commit 492a2b1

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/helper/find-embeded-object.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { EntryEmbedable, EmbeddedObject } from '../Models/embedded-object';
22
import { RenderOption, RenderObject, RenderContentType } from '../options/index';
3-
import { AssetAttributes, EntryAttributes, Metadata } from '../Models/metadata-model';
3+
import { EntryAttributes, Metadata } from '../Models/metadata-model';
44
import { defaultOptions } from '../options/default-options';
55

66
// This function will find Embedded object present in string
@@ -26,16 +26,19 @@ export function findEmbeddedAsset(uid: string, embeddedAssets: EmbeddedObject[]
2626

2727
export function findEmbeddedObjects(object: Metadata, entry: EntryEmbedable): (EmbeddedObject)[] {
2828
if (object && object !== undefined && entry && entry !== undefined) {
29-
if (object.itemType === 'entry') {
30-
const embeddedEntry = object.attributes as EntryAttributes;
31-
return findEmbeddedEntry(
32-
object.itemUid,
33-
object.contentTypeUid,
34-
Object.values(entry._embedded_items || []).reduce((accumulator, value) => accumulator.concat(value), []),
35-
);
36-
} else {
37-
const embeddedAsset = object.attributes as AssetAttributes;
38-
return findEmbeddedAsset(object.itemUid, Object.values(entry._embedded_items|| []).reduce((accumulator, value) => accumulator.concat(value), []),);
29+
if (entry._embedded_items !== undefined) {
30+
const entryEmbedable = entry
31+
if (object.itemType === 'entry') {
32+
return findEmbeddedEntry(
33+
object.itemUid,
34+
object.contentTypeUid,
35+
Object.values(entryEmbedable._embedded_items || []).reduce((accumulator, value) => accumulator.concat(value), []),
36+
);
37+
} else {
38+
return findEmbeddedAsset(
39+
object.itemUid,
40+
Object.values(entryEmbedable._embedded_items|| []).reduce((accumulator, value) => accumulator.concat(value), []),);
41+
}
3942
}
4043
}
4144
return [];

0 commit comments

Comments
 (0)