first
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import type { Handler } from 'hono';
|
||||
import type { User } from 'types';
|
||||
import * as errors from '@@/custom-errors';
|
||||
import { officerdb, eq, Users, Passkeys } from 'officerdb';
|
||||
|
||||
export const usersMe: Handler = async function (ctx) {
|
||||
const user = ctx.get('user') as User;
|
||||
const origin = ctx.get('origin') as string;
|
||||
|
||||
const dbUser = await officerdb.query.Users.findFirst({
|
||||
where: eq(Users.id, user.id),
|
||||
columns: { password: false },
|
||||
with: {
|
||||
passkeys: { where: eq(Passkeys.origin, origin || '') },
|
||||
},
|
||||
});
|
||||
|
||||
if (!dbUser) return errors.NOT_FOUND();
|
||||
|
||||
const { passkeys, ...userWithoutPasskeys } = dbUser;
|
||||
const returnUser = { ...userWithoutPasskeys, passkeyCount: passkeys.length };
|
||||
|
||||
return ctx.json(returnUser);
|
||||
};
|
||||
Reference in New Issue
Block a user