feat(client api): keep track of last connected
This commit is contained in:
parent
1d5e1bda85
commit
69e4c2592b
1 changed files with 8 additions and 3 deletions
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue