Skip to content

Commit

Permalink
fix: Add job check to get correct linkage (#235)
Browse files Browse the repository at this point in the history
  • Loading branch information
adityachoudhari26 authored Nov 26, 2024
1 parent 9d796d7 commit bff2840
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions packages/api/src/router/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,11 @@ const latestActiveReleaseByResourceAndEnvironmentId = (
);
};

const getNodeDataForResource = async (db: Tx, resourceId: string) => {
const getNodeDataForResource = async (
db: Tx,
resourceId: string,
jobId?: string,
) => {
const hasFilter = isNotNull(schema.environment.resourceFilter);
const resource = await db.query.resource.findFirst({
where: and(eq(schema.resource.id, resourceId), isNotDeleted),
Expand All @@ -428,8 +432,10 @@ const getNodeDataForResource = async (db: Tx, resourceId: string) => {
schema.jobResourceRelationship.resourceIdentifier,
resource.identifier,
);
const matchesJobId =
jobId == null ? undefined : eq(schema.jobResourceRelationship.jobId, jobId);
const parent = await db.query.jobResourceRelationship.findFirst({
where: matchesIdentifier,
where: and(matchesIdentifier, matchesJobId),
});

const { systems } = resource.workspace;
Expand Down Expand Up @@ -519,7 +525,7 @@ const getNodesRecursivelyHelper = async (
);

const childrenPromises = relationships.map((r) =>
getNodeDataForResource(db, r.resource.id),
getNodeDataForResource(db, r.resource.id, r.jobId),
);
const children = await Promise.all(childrenPromises);

Expand Down

0 comments on commit bff2840

Please sign in to comment.