mirror of
https://github.com/documenso/documenso.git
synced 2025-11-09 20:12:31 +10:00
47 lines
1002 B
TypeScript
47 lines
1002 B
TypeScript
import { prisma } from '@documenso/prisma';
|
|
import { UserSecurityAuditLogType } from '@documenso/prisma/client';
|
|
|
|
import type { RequestMetadata } from '../../universal/extract-request-metadata';
|
|
|
|
export type UpdateProfileOptions = {
|
|
userId: number;
|
|
name: string;
|
|
signature: string;
|
|
requestMetadata?: RequestMetadata;
|
|
};
|
|
|
|
export const updateProfile = async ({
|
|
userId,
|
|
name,
|
|
signature,
|
|
requestMetadata,
|
|
}: UpdateProfileOptions) => {
|
|
// Existence check
|
|
await prisma.user.findFirstOrThrow({
|
|
where: {
|
|
id: userId,
|
|
},
|
|
});
|
|
|
|
return await prisma.$transaction(async (tx) => {
|
|
await tx.userSecurityAuditLog.create({
|
|
data: {
|
|
userId,
|
|
type: UserSecurityAuditLogType.ACCOUNT_PROFILE_UPDATE,
|
|
userAgent: requestMetadata?.userAgent,
|
|
ipAddress: requestMetadata?.ipAddress,
|
|
},
|
|
});
|
|
|
|
return await tx.user.update({
|
|
where: {
|
|
id: userId,
|
|
},
|
|
data: {
|
|
name,
|
|
signature,
|
|
},
|
|
});
|
|
});
|
|
};
|