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