Skip to content

Commit

Permalink
🎨 Set server actions name to default
Browse files Browse the repository at this point in the history
  • Loading branch information
pitzzahh authored Nov 26, 2023
1 parent 9453727 commit e2d209a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
17 changes: 7 additions & 10 deletions src/routes/movie/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@ import { host } from '$lib';
export const load = (() => {
return {
form: superValidate(addSchema, {
id: "addSchema"
id: 'addSchema'
})
};
}) satisfies PageServerLoad;


export const actions: Actions = {
addMovie: async (event) => {
default: async (event) => {
const form = await superValidate(event, addSchema, {
id: "addSchema"
id: 'addSchema'
});

if (!form.valid) {
Expand All @@ -27,18 +26,17 @@ export const actions: Actions = {
});
}

const genres: string[] = form.data.genres.split(' ')
.map((genre) => genre)
const genres: string[] = form.data.genres.split(' ').map((genre) => genre);

let data: MovieDTO = {
title: form.data.title,
genres,
year: Number(form.data.year),
rating: Number(form.data.rating),
watched: form.data.watched
}
};

console.log(`Movie to be added:${JSON.stringify(data)}`)
console.log(`Movie to be added:${JSON.stringify(data)}`);

try {
const response: Response = await fetch(`${host}/api/movies`, {
Expand All @@ -58,7 +56,6 @@ export const actions: Actions = {
message: res.message,
errorMessage: res.errorMessage
};

} catch (error: any) {
return {
form,
Expand All @@ -68,4 +65,4 @@ export const actions: Actions = {
};
}
}
};
};
2 changes: 1 addition & 1 deletion src/routes/movie/[id]/+page.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const load = (async (event: RequestEvent) => {
}) satisfies PageServerLoad;

export const actions: Actions = {
modifyMovie: async (event) => {
default: async (event) => {
const form = await superValidate(event, modifySchema, {
id: 'modifySchema'
});
Expand Down

0 comments on commit e2d209a

Please sign in to comment.