feat: initiated public profile

Signed-off-by: Adithya Krishna <aadithya794@gmail.com>
This commit is contained in:
Adithya Krishna
2024-05-01 16:16:55 +05:30
parent 15dee5ef35
commit 69c175d38e
9 changed files with 263 additions and 6 deletions

View File

@ -5,9 +5,10 @@ import { AppError, AppErrorCode } from '../../errors/app-error';
export type UpdatePublicProfileOptions = {
userId: number;
url: string;
bio?: string;
};
export const updatePublicProfile = async ({ userId, url }: UpdatePublicProfileOptions) => {
export const updatePublicProfile = async ({ userId, url, bio }: UpdatePublicProfileOptions) => {
const isUrlTaken = await prisma.user.findFirst({
select: {
id: true,
@ -37,10 +38,10 @@ export const updatePublicProfile = async ({ userId, url }: UpdatePublicProfileOp
userProfile: {
upsert: {
create: {
bio: '',
bio: bio,
},
update: {
bio: '',
bio: bio,
},
},
},

View File

@ -88,7 +88,7 @@ export const profileRouter = router({
.input(ZUpdatePublicProfileMutationSchema)
.mutation(async ({ input, ctx }) => {
try {
const { url } = input;
const { url, bio } = input;
if (IS_BILLING_ENABLED() && url.length <= 6) {
const subscriptions = await getSubscriptionsByUserId({
@ -108,6 +108,7 @@ export const profileRouter = router({
const user = await updatePublicProfile({
userId: ctx.user.id,
url,
bio,
});
return { success: true, url: user.url };

View File

@ -25,6 +25,13 @@ export const ZUpdatePublicProfileMutationSchema = z.object({
.regex(/^[a-z0-9-]+$/, {
message: 'Username can only container alphanumeric characters and dashes.',
}),
bio: z
.string()
.trim()
.max(256, {
message: 'Bio cannot be longer than 256 characters.',
})
.optional(),
});
export const ZUpdatePasswordMutationSchema = z.object({