Public
Script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { tasks as tasks2 } from "https://esm.town/v/ju2l0r/tasks";
export async function getTasks(data) {
const { search, completed, offset } = data ?? {};
let filteredTasks = search
? tasks2.filter((task) =>
task.title.toLowerCase().includes(search.toLowerCase())
)
: tasks2;
if (completed !== null && completed !== undefined) {
filteredTasks = filteredTasks.filter((task) =>
task.completed === completed
);
}
filteredTasks = filteredTasks.sort((a, b) =>
(new Date(b.created_at)).valueOf() - (new Date(a.created_at)).valueOf()
);
return {
tasks: filteredTasks.slice(offset ?? 0, (offset ?? 0) + 30),
total: filteredTasks.length,
};
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
October 23, 2023