documenso/packages/lib/server-only/admin/update-user.ts

29 lines
537 B
TypeScript
Raw Normal View History

2023-09-29 16:12:02 +00:00
import { prisma } from '@documenso/prisma';
import type { Role } from '@documenso/prisma/client';
2023-09-29 16:12:02 +00:00
export type UpdateUserOptions = {
2023-09-29 16:26:37 +00:00
id: number;
2023-10-02 10:38:04 +00:00
name: string | null | undefined;
email: string | undefined;
roles: Role[] | undefined;
2023-09-29 16:12:02 +00:00
};
2023-09-29 16:26:37 +00:00
export const updateUser = async ({ id, name, email, roles }: UpdateUserOptions) => {
2023-09-29 16:12:02 +00:00
await prisma.user.findFirstOrThrow({
where: {
2023-09-29 16:26:37 +00:00
id,
2023-09-29 16:12:02 +00:00
},
});
2023-10-11 09:32:33 +00:00
return await prisma.user.update({
2023-09-29 16:12:02 +00:00
where: {
2023-09-29 16:26:37 +00:00
id,
2023-09-29 16:12:02 +00:00
},
data: {
name,
email,
roles,
},
});
};