2025-07-14 17:16:51 +01:00
|
|
|
import { sortByDate, sortByTitle } from "../lib/sorters.js"
|
|
|
|
|
import { GET_ALL_ENTRIES, GET_ENTRY } from "../sql/entries.js"
|
|
|
|
|
|
2025-02-09 18:26:53 +00:00
|
|
|
export class EntriesService {
|
2025-07-14 17:16:51 +01:00
|
|
|
database
|
|
|
|
|
|
|
|
|
|
constructor(database) {
|
|
|
|
|
this.database = database
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getEntry = (title) => {
|
|
|
|
|
return this.database.prepare(GET_ENTRY).get(title)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getAllEntries = (sort, limit) => {
|
|
|
|
|
const entries = this.database
|
|
|
|
|
.prepare(GET_ALL_ENTRIES)
|
|
|
|
|
.all()
|
|
|
|
|
.slice(0, Number(limit) || -1)
|
|
|
|
|
|
|
|
|
|
if (sort === "date") {
|
|
|
|
|
return sortByDate(entries)
|
|
|
|
|
}
|
2025-02-09 18:26:53 +00:00
|
|
|
|
2025-07-14 17:16:51 +01:00
|
|
|
return sortByTitle(entries)
|
|
|
|
|
}
|
2025-02-09 18:26:53 +00:00
|
|
|
}
|