feat: update user functionality

This commit is contained in:
pit
2023-09-29 17:26:37 +01:00
parent f1bc772985
commit c2cda0f06e
5 changed files with 120 additions and 11 deletions

View File

@ -0,0 +1,33 @@
import { TRPCError } from '@trpc/server';
import { isAdmin } from '@documenso/lib/next-auth/guards/is-admin';
import { updateUser } from '@documenso/lib/server-only/admin/update-user';
import { authenticatedProcedure, router } from '../trpc';
import { ZUpdateProfileMutationByAdminSchema } from './schema';
export const adminRouter = router({
updateUser: authenticatedProcedure
.input(ZUpdateProfileMutationByAdminSchema)
.mutation(async ({ input, ctx }) => {
const isUserAdmin = isAdmin(ctx.user);
if (!isUserAdmin) {
throw new TRPCError({
code: 'UNAUTHORIZED',
message: 'Not authorized to perform this action.',
});
}
const { id, name, email, roles } = input;
try {
return await updateUser({ id, name, email, roles });
} catch (err) {
throw new TRPCError({
code: 'BAD_REQUEST',
message: 'We were unable to retrieve the specified account. Please try again.',
});
}
}),
});