Files
documenso/packages/lib/server-only/user/update-public-profile.ts
Adithya Krishna 90b9b58afe feat: update ui
Signed-off-by: Adithya Krishna <adithya@documenso.com>
2024-02-24 22:38:53 +05:30

36 lines
862 B
TypeScript

import { prisma } from '@documenso/prisma';
import type { User, UserProfile } from '@documenso/prisma/client';
import { getUserById } from './get-user-by-id';
export type UpdatePublicProfileOptions = {
id: User['id'];
profileURL: UserProfile['profileURL'];
};
export const updatePublicProfile = async ({ id, profileURL }: UpdatePublicProfileOptions) => {
const user = await getUserById({ id });
// Existence check
await prisma.userProfile.findFirstOrThrow({
where: {
profileURL: user.profileURL ?? undefined,
},
});
return await prisma.$transaction(async (tx) => {
await tx.userProfile.create({
data: {
profileURL,
},
});
await tx.userProfile.update({
where: {
profileURL: user.profileURL ?? undefined,
},
data: {
profileURL: profileURL,
},
});
});
};