feat(client api): keep track of last connected

This commit is contained in:
DecDuck
2024-11-06 09:17:03 +11:00
parent 1d5e1bda85
commit 69e4c2592b

View File

@ -5,7 +5,7 @@ import prisma from "../db/database";
export type EventHandlerFunction<T> = ( export type EventHandlerFunction<T> = (
h3: H3Event<EventHandlerRequest>, h3: H3Event<EventHandlerRequest>,
utils: ClientUtils, utils: ClientUtils
) => Promise<T> | T; ) => Promise<T> | T;
type ClientUtils = { type ClientUtils = {
@ -82,7 +82,7 @@ export function defineClientEventHandler<T>(handler: EventHandlerFunction<T>) {
}); });
if (!client) if (!client)
throw new Error( throw new Error(
"client util fetch client broke - this should NOT happen", "client util fetch client broke - this should NOT happen"
); );
return client; return client;
} }
@ -97,7 +97,7 @@ export function defineClientEventHandler<T>(handler: EventHandlerFunction<T>) {
if (!client) if (!client)
throw new Error( throw new Error(
"client util fetch client broke - this should NOT happen", "client util fetch client broke - this should NOT happen"
); );
return client.user; return client.user;
@ -109,6 +109,11 @@ export function defineClientEventHandler<T>(handler: EventHandlerFunction<T>) {
fetchUser, fetchUser,
}; };
prisma.client.update({
where: { id: clientId },
data: { lastConnected: new Date() },
});
return await handler(h3, utils); return await handler(h3, utils);
}); });
} }