Files
documenso/packages/lib/server-only/user/update-public-profile.ts
Adithya Krishna 69c175d38e feat: initiated public profile
Signed-off-by: Adithya Krishna <aadithya794@gmail.com>
2024-05-01 16:16:55 +05:30

51 lines
930 B
TypeScript

import { prisma } from '@documenso/prisma';
import { AppError, AppErrorCode } from '../../errors/app-error';
export type UpdatePublicProfileOptions = {
userId: number;
url: string;
bio?: string;
};
export const updatePublicProfile = async ({ userId, url, bio }: UpdatePublicProfileOptions) => {
const isUrlTaken = await prisma.user.findFirst({
select: {
id: true,
},
where: {
id: {
not: userId,
},
url,
},
});
if (isUrlTaken) {
throw new AppError(
AppErrorCode.PROFILE_URL_TAKEN,
'Profile username is taken',
'The profile username is already taken',
);
}
return await prisma.user.update({
where: {
id: userId,
},
data: {
url,
userProfile: {
upsert: {
create: {
bio: bio,
},
update: {
bio: bio,
},
},
},
},
});
};