move submit note to composable

main
TZGyn 3 years ago
parent 7e17a5b562
commit c7d7160390

@ -0,0 +1,22 @@
export const submitNote = async (
note: Note,
query: NoteQuery
): Promise<ApiResponse> => {
let response: ApiResponse = {
status: 200,
message: 'Update',
error: null,
};
await useFetch('/api/note', {
method: 'POST',
query,
body: note,
onResponse({ response }) {
console.log('POST:', response._data.message);
response = response._data;
},
});
return response;
};

@ -67,20 +67,8 @@
const submit = async (note: Note) => { const submit = async (note: Note) => {
isSubmitting.value = true; isSubmitting.value = true;
await useFetch('/api/note', { await submitNote(note, { id: route.params.id });
method: 'POST', isSubmitting.value = false;
query: {
id: route.params.id,
},
body: {
title: note.title,
description: note.description,
},
onResponse({ response }) {
isSubmitting.value = false;
console.log('POST:', response._data.message);
},
});
}; };
const deleteNote = async () => { const deleteNote = async () => {

4
types/global.d.ts vendored

@ -8,6 +8,10 @@ declare global {
description: string; description: string;
} }
interface NoteQuery {
id: number | string | string[];
}
interface ApiResponse { interface ApiResponse {
status: number; status: number;
message: string; message: string;

Loading…
Cancel
Save