🚧 wip: user devices endpoint

This commit is contained in:
Fred KISSIE
2026-02-06 05:37:44 +01:00
parent 67b63d3084
commit 9f2fd34e99
10 changed files with 374 additions and 74 deletions

View File

@@ -105,11 +105,7 @@ const listClientsSchema = z.object({
.catch(1)
.default(1),
query: z.string().optional(),
sort_by: z
.enum(["megabytesIn", "megabytesOut"])
.optional()
.catch(undefined),
filter: z.enum(["user", "machine"]).optional()
sort_by: z.enum(["megabytesIn", "megabytesOut"]).optional().catch(undefined)
});
function queryClientsBase() {
@@ -134,15 +130,7 @@ function queryClientsBase() {
approvalState: clients.approvalState,
olmArchived: olms.archived,
archived: clients.archived,
blocked: clients.blocked,
deviceModel: currentFingerprint.deviceModel,
fingerprintPlatform: currentFingerprint.platform,
fingerprintOsVersion: currentFingerprint.osVersion,
fingerprintKernelVersion: currentFingerprint.kernelVersion,
fingerprintArch: currentFingerprint.arch,
fingerprintSerialNumber: currentFingerprint.serialNumber,
fingerprintUsername: currentFingerprint.username,
fingerprintHostname: currentFingerprint.hostname
blocked: clients.blocked
})
.from(clients)
.leftJoin(orgs, eq(clients.orgId, orgs.orgId))
@@ -208,7 +196,7 @@ export async function listClients(
)
);
}
const { page, pageSize, query, filter } = parsedQuery.data;
const { page, pageSize, query } = parsedQuery.data;
const parsedParams = listClientsParamsSchema.safeParse(req.params);
if (!parsedParams.success) {
@@ -262,15 +250,10 @@ export async function listClients(
// Get client count with filter
const conditions = [
inArray(clients.clientId, accessibleClientIds),
eq(clients.orgId, orgId)
eq(clients.orgId, orgId),
isNull(clients.userId)
];
if (filter === "user") {
conditions.push(isNotNull(clients.userId));
} else if (filter === "machine") {
conditions.push(isNull(clients.userId));
}
const countQuery = db.$count(
queryClientsBase().where(and(...conditions))
);
@@ -312,11 +295,8 @@ export async function listClients(
// Merge clients with their site associations and replace name with device name
const clientsWithSites = clientsList.map((client) => {
const model = client.deviceModel || null;
const newName = getUserDeviceName(model, client.name);
return {
...client,
name: newName,
sites: sitesByClient[client.clientId] || []
};
});