api (rest) endpoints. closes #11

This commit is contained in:
Michael Dausmann
2023-09-09 00:01:16 +10:00
parent ffa8db7bd9
commit caf65a48c1
7 changed files with 98 additions and 40 deletions

23
server/api/note.ts Normal file
View File

@@ -0,0 +1,23 @@
import { H3Event, getQuery } from 'h3';
import { defineProtectedEventHandler } from '../defineProtectedEventHandler';
import NotesService from '~/lib/services/notes.service';
// Example API Route with query params ... /api/note?note_id=41
export default defineProtectedEventHandler(async (event: H3Event) => {
const queryParams = getQuery(event)
let note_id: string = '';
if(queryParams.note_id){
if (Array.isArray( queryParams.note_id)) {
note_id = queryParams.note_id[0];
} else {
note_id = queryParams.note_id.toString();
}
}
const notesService = new NotesService();
const note = await notesService.getNoteById(+note_id);
return {
note,
}
})