File tree Expand file tree Collapse file tree 1 file changed +11
-11
lines changed
apps/app/src/app/(app)/[orgId]/people/devices/data Expand file tree Collapse file tree 1 file changed +11
-11
lines changed Original file line number Diff line number Diff 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 } ` ) ) ) ;
You can’t perform that action at this time.
0 commit comments