import { ensureIdentity } from '@app/server/helpers'; import { IdentityContext } from '@app/server/identity'; import { prisma, uuid } from '@app/server/prisma/client'; import { MutationUserUpdateArgs, User } from '@generated/types'; import { toUserSchema } from './mappers/userMapper'; import { call } from '@app/common'; export async function UserUpdateResolver( _: any, { input }: MutationUserUpdateArgs, { identity }: IdentityContext ): Promise { ensureIdentity(identity); if (input.id != identity.id) throw new Error('Operation is not permitted.'); //todo: add admin access if (input.description != null && input.description.length > 700) throw new Error('Description is too long.'); const description = call((): string | null | undefined => { if (input.description != null && input.description.length !== 0) return input.description; if (input.description != null && input.description.length === 0) return null; return undefined; }); const updated = await prisma.user.update({ where: { id: input.id }, data: { description } }); return toUserSchema(updated); }