blob: 129b60ad91d43d92d58cd4a0922664021af607d0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
import { api } from './_api';
import type { RequestHandler } from '@sveltejs/kit';
export const get: RequestHandler = async ({ request, locals }) => {
// locals.userid comes from src/hooks.js
const response = await api(request, `todos/${locals.userid}`);
if (response.status === 404) {
// user hasn't created a todo list.
// start with an empty array
return {
body: {
todos: []
}
};
}
if (response.ok) {
return {
body: {
todos: await response.json()
}
};
}
return {
status: response.status
};
};
export const post: RequestHandler = async ({ request, locals }) => {
const form = await request.formData();
return api(request, `todos/${locals.userid}`, {
text: form.get('text')
});
};
export const patch: RequestHandler = async ({ request, locals }) => {
const form = await request.formData();
return api(request, `todos/${locals.userid}/${form.get('uid')}`, {
text: form.has('text') ? form.get('text') : undefined,
done: form.has('done') ? !!form.get('done') : undefined
});
};
export const del: RequestHandler = async ({ request, locals }) => {
const form = await request.formData();
return api(request, `todos/${locals.userid}/${form.get('uid')}`);
};
|