N-FIN-5: shorten server action response

This commit is contained in:
Markus Thielker 2024-03-10 12:38:06 +01:00
parent 978ba4bf58
commit 0ece1aacb4
No known key found for this signature in database

View file

@ -12,15 +12,17 @@ export default async function entityCreateUpdate({
}: z.infer<typeof entityFormSchema>): Promise<ActionResponse> {
'use server';
// check that user is logged in
const user = await getUser();
if (!user) {
return {
type: 'error',
message: 'You must be logged in to create an entity.',
message: 'You must be logged in to create/update an entity.',
redirect: URL_SIGN_IN,
};
}
// create/update entity
try {
if (id) {
await prismaClient.entity.update({
@ -45,12 +47,13 @@ export default async function entityCreateUpdate({
} catch (e) {
return {
type: 'error',
message: 'Invalid entity data',
message: 'Failed creating/updating entity',
};
}
// return success
return {
type: 'success',
message: `Created an entity with name: ${name} and type: ${type}`,
message: `${type} '${name}' created`,
};
}