construct: function(self, options) {
self.apos.tasks.add(self.__meta.name, 'insert-blog-articles', function(apos, argv, callback) {
console.info(`Running ${self.__meta.name}:insert-blog-articles`)
if(!argv.create) throw new Error('Please pass a number of articles to create using --create=n')
const req = self.apos.tasks.getReq()
const numberToCreate = Array.from(Array(argv.create).keys())
numberToCreate.forEach(item => {
let blogPost = self.newInstance()
blogPost = Object.assign({}, blogPost, {
title: 'Post about cats!',
image: 'https://www.vetbabble.com/wp-content/uploads/2016/11/hiding-cat.jpg',
published: true,
testData: true
})
self.insert(req, blogPost)
.then(result => { console.info('Inserted doc!', result) })
})
})
self.apos.tasks.add(self.__meta.name, 'show-hide-articles', function(apos, argv, callback) {
console.info('Running task show-hide-articles', argv)
const set = argv.show ? { published: true } : { published: false }
self.apos.docs.db.update(
{ type: 'apostrophe-blog', testData: true },
{ $set: set },
{ multi: true }
)
.then(result => {
argv.show && console.info('Docs updated, now showing posts')
!argv.show && console.info('Docs updated, now hiding posts')
})
.catch(error => { console.warn('Error updating docs', error) })
})
}