Skip to content

Commit 108e718

Browse files
oskarbrueningclaude
andcommitted
fix: filter timeslot assigned resources to ACTIVE only
The previous change passed the resource allocation status through to the AssignedResource model. That status was meant to be used as a filter, not exposed. Only allocations with status "ACTIVE" are truly assigned; others (e.g. "REMOVAL") should be dropped. Filter inheritedResourceAllocations to ACTIVE in the converter and remove the status field from the AssignedResource model. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 9d6a9c4 commit 108e718

3 files changed

Lines changed: 34 additions & 16 deletions

File tree

src/internal/timeslots/timeslot-converter.ts

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,22 +59,26 @@ export function fromTimeslotNode(
5959
};
6060
}
6161

62+
/** Only allocations with this status are considered assigned. */
63+
const ACTIVE_ALLOCATION_STATUS = "ACTIVE";
64+
6265
function mapAssignedResources(
6366
allocations: TimeslotResourceAllocationNode[] | null | undefined,
6467
): AssignedResource[] {
6568
if (!Array.isArray(allocations) || allocations.length === 0) {
6669
return [];
6770
}
6871

69-
return allocations.map((allocation) => {
70-
const pool = allocation.resourcePool;
71-
return {
72-
name: pool?.name || "",
73-
capacity: pool?.capacity ?? 0,
74-
category: pool?.category || "",
75-
quantity: allocation.quantity ?? 0,
76-
status: allocation.status || "",
77-
accountUserId: pool?.accountUser?.id ?? null,
78-
};
79-
});
72+
return allocations
73+
.filter((allocation) => allocation.status === ACTIVE_ALLOCATION_STATUS)
74+
.map((allocation) => {
75+
const pool = allocation.resourcePool;
76+
return {
77+
name: pool?.name || "",
78+
capacity: pool?.capacity ?? 0,
79+
category: pool?.category || "",
80+
quantity: allocation.quantity ?? 0,
81+
accountUserId: pool?.accountUser?.id ?? null,
82+
};
83+
});
8084
}

src/models/timeslot.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ export interface AssignedResource {
4242
category: string;
4343
/** Allocated quantity. */
4444
quantity: number;
45-
/** Allocation status (e.g. `"ACTIVE"`). */
46-
status: string;
4745
/** Backing account user id, or null. */
4846
accountUserId: string | null;
4947
}

test/timeslots/timeslot-converter.test.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ describe("fromTimeslotNode", () => {
5353
capacity: 5,
5454
category: "guide",
5555
quantity: 1,
56-
status: "ACTIVE",
5756
accountUserId: "u1",
5857
},
5958
],
@@ -90,7 +89,7 @@ describe("fromTimeslotNode", () => {
9089
minuteLength: null,
9190
status: null,
9291
date: null,
93-
inheritedResourceAllocations: [{ quantity: null, status: null, resourcePool: null }],
92+
inheritedResourceAllocations: [{ quantity: null, status: "ACTIVE", resourcePool: null }],
9493
} as unknown as TimeslotNode;
9594

9695
expect(fromTimeslotNode(node, "act-1")).toEqual({
@@ -107,7 +106,7 @@ describe("fromTimeslotNode", () => {
107106
date: "",
108107
startTime: null,
109108
assignedResources: [
110-
{ name: "", capacity: 0, category: "", quantity: 0, status: "", accountUserId: null },
109+
{ name: "", capacity: 0, category: "", quantity: 0, accountUserId: null },
111110
],
112111
});
113112
});
@@ -116,6 +115,23 @@ describe("fromTimeslotNode", () => {
116115
const node = { ...fullNode, inheritedResourceAllocations: null } as unknown as TimeslotNode;
117116
expect(fromTimeslotNode(node, "act-1").assignedResources).toEqual([]);
118117
});
118+
119+
it("filters out allocations whose status is not ACTIVE", () => {
120+
const node = {
121+
...fullNode,
122+
inheritedResourceAllocations: [
123+
...(fullNode.inheritedResourceAllocations ?? []),
124+
{
125+
quantity: 1,
126+
status: "REMOVAL",
127+
resourcePool: { name: "Bob", category: "guide", capacity: 5, accountUser: { id: "u2" } },
128+
},
129+
],
130+
} as unknown as TimeslotNode;
131+
const { assignedResources } = fromTimeslotNode(node, "act-1");
132+
expect(assignedResources).toHaveLength(1);
133+
expect(assignedResources[0].name).toBe("Ada");
134+
});
119135
});
120136

121137
describe("fromTimeslotNodes", () => {

0 commit comments

Comments
 (0)