Skip to content

Commit 466188e

Browse files
committed
fix(app): show device list of only employees
1 parent 5524446 commit 466188e

File tree

1 file changed

+11
-11
lines changed
  • apps/app/src/app/(app)/[orgId]/people/devices/data

1 file changed

+11
-11
lines changed

apps/app/src/app/(app)/[orgId]/people/devices/data/index.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,21 +19,21 @@ export const getEmployeeDevices: () => Promise<Host[] | null> = async () => {
1919
return null;
2020
}
2121

22-
const organization = await db.organization.findUnique({
22+
// Find all members belonging to the organization.
23+
const employees = await db.member.findMany({
2324
where: {
24-
id: organizationId,
25+
organizationId,
2526
},
2627
});
2728

28-
if (!organization) {
29-
return null;
30-
}
31-
32-
const labelId = organization.fleetDmLabelId;
33-
34-
// Get all hosts to get their ids.
35-
const employeeDevices = await fleet.get(`/labels/${labelId}/hosts`);
36-
const allIds = employeeDevices.data.hosts.map((host: { id: number }) => host.id);
29+
const labelIdsResponses = await Promise.all(
30+
employees
31+
.filter((employee) => employee.fleetDmLabelId)
32+
.map((employee) => fleet.get(`/labels/${employee.fleetDmLabelId}/hosts`)),
33+
);
34+
const allIds = labelIdsResponses.flatMap((response) =>
35+
response.data.hosts.map((host: { id: number }) => host.id),
36+
);
3737

3838
// Get all devices by id. in parallel
3939
const devices = await Promise.all(allIds.map((id: number) => fleet.get(`/hosts/${id}`)));

0 commit comments

Comments
 (0)