mirror of
https://codeberg.org/MarkusThielker/finances.git
synced 2025-04-12 05:08:43 +00:00
N-FIN-5: shorten server action response
This commit is contained in:
parent
978ba4bf58
commit
0ece1aacb4
1 changed files with 6 additions and 3 deletions
|
@ -12,15 +12,17 @@ export default async function entityCreateUpdate({
|
||||||
}: z.infer<typeof entityFormSchema>): Promise<ActionResponse> {
|
}: z.infer<typeof entityFormSchema>): Promise<ActionResponse> {
|
||||||
'use server';
|
'use server';
|
||||||
|
|
||||||
|
// check that user is logged in
|
||||||
const user = await getUser();
|
const user = await getUser();
|
||||||
if (!user) {
|
if (!user) {
|
||||||
return {
|
return {
|
||||||
type: 'error',
|
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,
|
redirect: URL_SIGN_IN,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// create/update entity
|
||||||
try {
|
try {
|
||||||
if (id) {
|
if (id) {
|
||||||
await prismaClient.entity.update({
|
await prismaClient.entity.update({
|
||||||
|
@ -45,12 +47,13 @@ export default async function entityCreateUpdate({
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return {
|
return {
|
||||||
type: 'error',
|
type: 'error',
|
||||||
message: 'Invalid entity data',
|
message: 'Failed creating/updating entity',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// return success
|
||||||
return {
|
return {
|
||||||
type: 'success',
|
type: 'success',
|
||||||
message: `Created an entity with name: ${name} and type: ${type}`,
|
message: `${type} '${name}' created`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue