-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathnote.ts
More file actions
22 lines (19 loc) · 656 Bytes
/
note.ts
File metadata and controls
22 lines (19 loc) · 656 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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 note = await NotesService.getNoteById(+note_id);
return {
note
};
});