Files
sign/packages/lib/server-only/user/update-profile.ts

47 lines
1002 B
TypeScript
Raw Normal View History

2023-06-09 18:21:18 +10:00
import { prisma } from '@documenso/prisma';
2024-01-30 17:31:27 +11:00
import { UserSecurityAuditLogType } from '@documenso/prisma/client';
import type { RequestMetadata } from '../../universal/extract-request-metadata';
2023-06-09 18:21:18 +10:00
export type UpdateProfileOptions = {
userId: number;
name: string;
signature: string;
2024-01-30 17:31:27 +11:00
requestMetadata?: RequestMetadata;
2023-06-09 18:21:18 +10:00
};
2024-01-30 17:31:27 +11:00
export const updateProfile = async ({
userId,
name,
signature,
requestMetadata,
}: UpdateProfileOptions) => {
2023-06-09 18:21:18 +10:00
// Existence check
await prisma.user.findFirstOrThrow({
where: {
id: userId,
},
});
2024-01-30 17:31:27 +11:00
return await prisma.$transaction(async (tx) => {
await tx.userSecurityAuditLog.create({
data: {
userId,
type: UserSecurityAuditLogType.ACCOUNT_PROFILE_UPDATE,
userAgent: requestMetadata?.userAgent,
ipAddress: requestMetadata?.ipAddress,
},
});
2023-06-09 18:21:18 +10:00
2024-01-30 17:31:27 +11:00
return await tx.user.update({
where: {
id: userId,
},
data: {
name,
signature,
},
});
});
2023-06-09 18:21:18 +10:00
};