import DirectusAbstractStore from './directusAbstract.js' /** * Posts from posts * * @author Björn Hase * @license http://opensource.org/licenses/MIT The MIT License * @link https://gitea.node001.net/HerrHase/super-fastify-directus.git * */ class PostStore extends DirectusAbstractStore { /** * set name of endpoint * * * @param {string} endpoint * */ constructor() { super('posts') } /** * getting posts * * @param {page} * @param {limit} * @return {object} */ find(page = 1, limit = 20) { return this.items.readByQuery({ fields: [ 'title', 'slug', 'status', 'user_created.first_name', 'user_created.last_name', 'user_created.avatar.id', 'teaser_content', 'teaser_media.id', 'teaser_media.description', ], filter: { 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.readByQuery({ 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