This repository has been archived on 2026-01-31. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
nextjs-serve-actions/app/components/Settings/Profiles/actions/UpdateProfileAction.ts
2024-05-23 16:55:29 +02:00

32 lines
593 B
TypeScript

'use server';
import { z } from 'zod';
import prisma from '../../../../../prisma/prisma';
interface ProfileActionProps {
id: string;
name: string;
error?: string;
}
export async function UpdateProfileAction({ id, name }: ProfileActionProps) {
const validatedBody = z.string().safeParse(name);
if (!validatedBody.success) {
throw new Error('Bad request');
}
try {
await prisma.profile.update({
where: {
id
},
data: {
name: validatedBody.data
}
});
} catch (error) {
throw new Error(`Failed to update profile`);
}
}