refactor: return data as data field
This commit is contained in:
parent
dbd63cfc42
commit
5d70e9a23f
2 changed files with 21 additions and 21 deletions
|
|
@ -21,7 +21,7 @@ export default class EntriesService {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
count: sliced.length,
|
count: sliced.length,
|
||||||
entries: sliced,
|
data: sliced,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -29,7 +29,7 @@ export default class EntriesService {
|
||||||
const entries = this.database.prepare(GET_ENTRIES_FOR_TAG).all(tag)
|
const entries = this.database.prepare(GET_ENTRIES_FOR_TAG).all(tag)
|
||||||
return {
|
return {
|
||||||
count: entries.length,
|
count: entries.length,
|
||||||
entries:
|
data:
|
||||||
sort === "date"
|
sort === "date"
|
||||||
? this._sortByDate(entries)
|
? this._sortByDate(entries)
|
||||||
: this._sortByTitle(entries, "entry_title"),
|
: this._sortByTitle(entries, "entry_title"),
|
||||||
|
|
|
||||||
|
|
@ -1,27 +1,27 @@
|
||||||
import { GET_ALL_TAGS, GET_TAGS_FOR_ENTRY } from "../sql/tags.js"
|
import { GET_ALL_TAGS, GET_TAGS_FOR_ENTRY } from "../sql/tags.js"
|
||||||
|
|
||||||
export default class TagsService {
|
export default class TagsService {
|
||||||
database
|
database
|
||||||
|
|
||||||
constructor(database) {
|
constructor(database) {
|
||||||
this.database = database
|
this.database = database
|
||||||
}
|
}
|
||||||
|
|
||||||
getAllTags = () => {
|
getAllTags = () => {
|
||||||
const tags = this.database.prepare(GET_ALL_TAGS).all()
|
const tags = this.database.prepare(GET_ALL_TAGS).all()
|
||||||
const sorted = this._sortTags(tags, "name")
|
const sorted = this._sortTags(tags, "name")
|
||||||
const list = sorted.flatMap((tag) => tag.name)
|
const list = sorted.flatMap((tag) => tag.name)
|
||||||
return { count: tags.length, tags: list }
|
return { count: tags.length, data: list }
|
||||||
}
|
}
|
||||||
|
|
||||||
getTagsForEntry = (entryTitle) => {
|
getTagsForEntry = (entryTitle) => {
|
||||||
const tags = this.database.prepare(GET_TAGS_FOR_ENTRY).all(entryTitle)
|
const tags = this.database.prepare(GET_TAGS_FOR_ENTRY).all(entryTitle)
|
||||||
const sorted = this._sortTags(tags, "tag_name")
|
const sorted = this._sortTags(tags, "tag_name")
|
||||||
const list = sorted.flatMap((tag) => tag.tag_name)
|
const list = sorted.flatMap((tag) => tag.tag_name)
|
||||||
return { count: tags.length, tags: list }
|
return { count: tags.length, data: list }
|
||||||
}
|
}
|
||||||
|
|
||||||
_sortTags = (tags, fieldName) => {
|
_sortTags = (tags, fieldName) => {
|
||||||
return tags.sort((a, b) => a[fieldName].localeCompare(b[fieldName]))
|
return tags.sort((a, b) => a[fieldName].localeCompare(b[fieldName]))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue