Skip to content

Commit b5132ba

Browse files
authored
fix: safe parent project check in segments (#2823)
1 parent 7c9a65d commit b5132ba

File tree

1 file changed

+7
-4
lines changed
  • services/libs/data-access-layer/src/segments

1 file changed

+7
-4
lines changed

services/libs/data-access-layer/src/segments/index.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,13 @@ export async function findSegmentById(
6666
} else if (isSegmentSubproject(child)) {
6767
// find project index
6868
const projectIndex = acc.findIndex((project) => project.slug === child.parentSlug)
69-
if (!acc[projectIndex].subprojects) {
70-
acc[projectIndex].subprojects = [child]
71-
} else {
72-
acc[projectIndex].subprojects.push(child)
69+
// process subproject only if its parent project exists
70+
if (projectIndex !== -1) {
71+
if (!acc[projectIndex].subprojects) {
72+
acc[projectIndex].subprojects = [child]
73+
} else {
74+
acc[projectIndex].subprojects.push(child)
75+
}
7376
}
7477
}
7578
return acc

0 commit comments

Comments
 (0)