refactor: move entries sorters into EntriesService
This commit is contained in:
parent
254c5be8f5
commit
21f0f04e2a
2 changed files with 1 additions and 11 deletions
|
|
@ -1,9 +0,0 @@
|
|||
const sortByDate = (entries) => {
|
||||
return entries.sort((a, b) => new Date(b.last_modified) - new Date(a.last_modified))
|
||||
}
|
||||
|
||||
const sortByTitle = (entries) => {
|
||||
return entries.sort((a, b) => a.title.localeCompare(b.title))
|
||||
}
|
||||
|
||||
export { sortByDate, sortByTitle }
|
||||
|
|
@ -1,4 +1,3 @@
|
|||
import { sortByDate, sortByTitle } from "../lib/sorters.js"
|
||||
import { GET_ALL_ENTRIES, GET_ENTRY, GET_ENTRIES_FOR_TAG } from "../sql/entries.js"
|
||||
|
||||
export default class EntriesService {
|
||||
|
|
@ -20,7 +19,7 @@ export default class EntriesService {
|
|||
|
||||
return {
|
||||
count: entries.length,
|
||||
entries: sort === "date" ? sortByDate(entries) : sortByTitle(entries),
|
||||
entries: sort === "date" ? this._sortByDate(entries) : this._sortByTitle(entries, "title"),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue