21 lines
763 B
TypeScript
21 lines
763 B
TypeScript
import { IdentityContext } from '@app/server/identity';
|
|
import { prisma } from '@app/server/prisma/client';
|
|
import { QueryUserOneArgs, User } from '@generated/types';
|
|
import { toUserSchema } from './mappers/userMapper';
|
|
|
|
export async function UserOneResolver(
|
|
_: any,
|
|
{ input }: QueryUserOneArgs,
|
|
{ identity }: IdentityContext
|
|
): Promise<User> {
|
|
if (input.id == null && input.username == null) throw new Error('Invalid user input.');
|
|
if (input.id != null && input.username != null) throw new Error('Invalid user input.');
|
|
|
|
const model = await prisma.user.findUniqueOrThrow({
|
|
where: {
|
|
id: input.id != null ? input.id : undefined,
|
|
username: input.username != null ? input.username : undefined
|
|
}
|
|
});
|
|
return toUserSchema(model);
|
|
}
|