mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
50 lines
897 B
TypeScript
50 lines
897 B
TypeScript
import { prisma } from '@documenso/prisma';
|
|
|
|
import { AppError, AppErrorCode } from '../../errors/app-error';
|
|
|
|
export type UpdatePublicProfileOptions = {
|
|
userId: number;
|
|
url: string;
|
|
};
|
|
|
|
export const updatePublicProfile = async ({ userId, url }: 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 URL is taken',
|
|
'The profile URL is already taken',
|
|
);
|
|
}
|
|
|
|
return await prisma.user.update({
|
|
where: {
|
|
id: userId,
|
|
},
|
|
data: {
|
|
url,
|
|
userProfile: {
|
|
upsert: {
|
|
create: {
|
|
bio: '',
|
|
},
|
|
update: {
|
|
bio: '',
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
};
|