You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.1 KiB

import DirectusAbstractStore from './DirectusAbstract.js'
/**
* Posts from Directus
*
*
*/
class PostStore extends DirectusAbstractStore {
/**
*
*
* @param {string} endpoint
*
*/
constructor() {
super('posts')
}
/**
* getting posts
*
* @param {page}
* @param {limit}
* @return {object}
*/
find(page = 1, limit = 20) {
return this.items.readOne({
fields: [
'title',
'slug',
'user_created.first_name',
'user_created.last_name',
'user_created.avatar.id',
'teaser_content',
'teaser_media.id',
'teaser_media.description',
],
filter: {
slug : slug,
status : 'published',
published_at : {
'_nnull': true
}
},
limit : limit,
offset : ((page - 1) * limit),
sort : '-published_at'
})
}
/**
* getting single post
*
* @param {string} slug
* @return {object}
*/
findOneBySlug(slug) {
return this.items.readOne({
fields: [
'title',
'slug',
'meta',
'user_created.first_name',
'user_created.last_name',
'user_created.avatar.id',
'header_media.id',
'header_media.description',
'content_blocks.blocks_id.title',
'content_blocks.blocks_id.content',
'content_blocks.blocks_id.styles',
'content_blocks.blocks_id.media.directus_files_id.id',
'content_blocks.blocks_id.media.directus_files_id.description'
],
filter: {
slug : slug,
status : 'published',
published_at : {
'_nnull': true
}
}
})
}
}
export default PostStore