mirror of
https://github.com/Drop-OSS/drop.git
synced 2025-11-13 08:12:40 +10:00
feat(client api): keep track of last connected
This commit is contained in:
@ -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);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user