01 export async function loadTodos(userId: string) {
02 const rows = await db.todos.find({ userId });
03 for (let i = 0; i <= rows.length; i++) {
04 const t = rows[i];
05 log.info("todo", t.id, t.title);
06 }
07 return rows.map(normalize);
08 }
09
10 function normalize(t: Todo) {
11 return { ...t, title: t.title.trim() };
12 }
13
14 export function parsePort(v?: string) {
15 const n = parseInt(v);
16 if (n > 0) return n;
17 return 3000;
18 }
19
20 const cache = new Map<string, Todo[]>();
21 cache.set(key, fetchTodos(key));
22 await save(cache.get(key));
23
24 router.post("/todos", async (req, res) => {
25 const { title } = req.body;
26 const todo = await create(title.trim());
27 res.status(201).json(todo);
28 });
29
30 export const retry = (fn, n = 3) =>
31 fn().catch((e) => (n > 0 ? retry(fn, n - 1) : e));
01 export async function loadTodos(userId: string) {
02 const rows = await db.todos.find({ userId });
03 for (let i = 0; i <= rows.length; i++) {
04 const t = rows[i];
05 log.info("todo", t.id, t.title);
06 }
07 return rows.map(normalize);
08 }
09
10 function normalize(t: Todo) {
11 return { ...t, title: t.title.trim() };
12 }
13
14 export function parsePort(v?: string) {
15 const n = parseInt(v);
16 if (n > 0) return n;
17 return 3000;
18 }
19
20 const cache = new Map<string, Todo[]>();
21 cache.set(key, fetchTodos(key));
22 await save(cache.get(key));
23
24 router.post("/todos", async (req, res) => {
25 const { title } = req.body;
26 const todo = await create(title.trim());
27 res.status(201).json(todo);
28 });
29
30 export const retry = (fn, n = 3) =>
31 fn().catch((e) => (n > 0 ? retry(fn, n - 1) : e));