mirror of
https://github.com/ThatGuySam/doesitarm.git
synced 2026-05-15 06:35:20 -07:00
Add KindList class
This commit is contained in:
parent
602a78a48a
commit
924aa7c8ab
1 changed files with 62 additions and 0 deletions
62
helpers/api/kind.js
Normal file
62
helpers/api/kind.js
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
import {
|
||||
apiDirectory
|
||||
} from '~/helpers/api/config.js'
|
||||
import {
|
||||
PaginatedList,
|
||||
defaultPerPage
|
||||
} from '~/helpers/api/pagination.js'
|
||||
|
||||
function makeKindEndpoint ({ kindSlug, number = null }) {
|
||||
if ( number ) {
|
||||
return `/kind/${ kindSlug }/${ number }`
|
||||
}
|
||||
|
||||
return `/kind/${ kindSlug }`
|
||||
}
|
||||
|
||||
function makeKindDirPath ( kindSlug ) {
|
||||
return `${ apiDirectory }${ makeKindEndpoint({ kindSlug }) }`
|
||||
}
|
||||
|
||||
function makeKindFilePath ({ kindSlug, number }) {
|
||||
return `${ apiDirectory }${ makeKindEndpoint({ kindSlug, number }) }.json`
|
||||
}
|
||||
|
||||
export class KindList extends PaginatedList {
|
||||
constructor({
|
||||
list,
|
||||
kindSlug,
|
||||
perPage = defaultPerPage
|
||||
}) {
|
||||
super({ list, perPage })
|
||||
|
||||
this.kindSlug = kindSlug
|
||||
}
|
||||
|
||||
get baseRoute () {
|
||||
return makeKindEndpoint({ kindSlug: this.kindSlug })
|
||||
}
|
||||
|
||||
get routes () {
|
||||
return this.pages.map( kindPage => {
|
||||
return makeKindEndpoint({
|
||||
kindSlug: this.kindSlug,
|
||||
number: kindPage.number
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
get basePath () {
|
||||
return makeKindDirPath( this.kindSlug )
|
||||
}
|
||||
|
||||
get apiFiles () {
|
||||
return this.pages.map( kindPage => {
|
||||
return {
|
||||
path: makeKindFilePath({ kindSlug: this.kindSlug, number: kindPage.number }),
|
||||
content: this.list
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue