Random tasks, more info
This commit is contained in:
parent
9187461ed4
commit
f93ad89194
7 changed files with 288 additions and 100 deletions
21
pb_hooks/main.pb.js
Normal file
21
pb_hooks/main.pb.js
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
routerAdd("GET", "/api/extras/random/:parent", (c) => {
|
||||
const result = new DynamicModel({
|
||||
"id": "",
|
||||
"name": "",
|
||||
});
|
||||
|
||||
const query = `WITH RECURSIVE descendants(id) AS (
|
||||
VALUES({:parent}) UNION ALL
|
||||
SELECT l.id FROM lists l JOIN descendants d ON d.id = l.parent
|
||||
) SELECT t.id, t.name FROM tasks t JOIN descendants d ON t.list = d.id WHERE t.schedule <= DATE('now') ORDER BY RANDOM() LIMIT 1`;
|
||||
const queryNull = `SELECT id, name FROM tasks WHERE schedule <= DATE('now') ORDER BY RANDOM() LIMIT 1`;
|
||||
const parent = c.pathParam("parent");
|
||||
|
||||
$app.dao().db()
|
||||
.newQuery(parent === "null" ? queryNull : query)
|
||||
.bind({ parent })
|
||||
.one(result)
|
||||
|
||||
return c.json(200, result)
|
||||
})
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue