Commit b238c31a authored by Jarrod's avatar Jarrod 💬

Lint

parent 462c4509
Pipeline #1271 passed with stages
in 38 seconds
/* global BlogCategory */
module.exports = {
friendlyName: `Get all categories`,
description: ``,
......
/* global BlogPost */
/* global BlogCategory */
module.exports = {
friendlyName: 'Blog Category Index',
description: 'Get a list of blog posts in the given category.',
......@@ -6,7 +9,7 @@ module.exports = {
slug: {
type: 'string',
required: true
},
}
// page: {
// type: 'number',
......@@ -20,7 +23,7 @@ module.exports = {
fn: async function (inputs) {
const category = await BlogCategory
.findOne({ slug: inputs.slug })
.findOne({ slug: inputs.slug })
if (!category) {
return this.res.notFound('Category not found')
......
/* global BlogPost */
module.exports = {
friendlyName: 'Get Article',
description: 'Get a blog post / article.',
......@@ -26,8 +28,8 @@ module.exports = {
}
const post = await BlogPost.findOne(where)
.select(['id', 'slug', 'title', 'excerpt', 'body', 'featureImage', 'createdAt'])
.populate('category')
.select(['id', 'slug', 'title', 'excerpt', 'body', 'featureImage', 'createdAt'])
.populate('category')
if (!post) {
return this.res.notFound('Post not found')
......@@ -37,10 +39,10 @@ module.exports = {
published: true,
id: { '!=': post.id }
})
.select(['id', 'slug', 'title', 'excerpt', 'featureImage', 'createdAt'])
.populate('category')
.sort('createdAt DESC')
.limit(3)
.select(['id', 'slug', 'title', 'excerpt', 'featureImage', 'createdAt'])
.populate('category')
.sort('createdAt DESC')
.limit(3)
// All done.
return {
......
/* global BlogPost */
/* global BlogCategory */
module.exports = {
friendlyName: 'Blog Index',
description: 'Get a list of blog categories and recent articles.',
......
......@@ -3,6 +3,7 @@
*
* A category
*/
const _ = require('lodash')
module.exports = {
attributes: {
......@@ -31,4 +32,4 @@ module.exports = {
customToJSON () {
return _.pick(this, ['id', 'name', 'slug', 'posts'])
}
};
}
/* global BlogCategory */
/**
* BlogPost.js
*
......@@ -52,7 +54,7 @@ module.exports = {
author: {
model: 'user'
},
}
},
beforeCreate: ensureCategory,
......@@ -66,22 +68,22 @@ module.exports = {
}
}
}
};
}
/*
* Ensures that all blog posts should always belong to a category
*/
async function ensureCategory (values, next) {
if (!values.category) {
let category = await BlogCategory.findOne({ where: { slug: 'uncategorized' } });
let category = await BlogCategory.findOne({ where: { slug: 'uncategorized' } })
if (!category) {
category = await BlogCategory.create({
name: 'Uncategorized',
slug: 'uncategorized'
}).fetch();
}).fetch()
}
values.category = category.id;
values.category = category.id
}
next()
}
\ No newline at end of file
}
......@@ -5,8 +5,9 @@
"description": "Ahoy blog",
"main": "lib/index.js",
"scripts": {
"lint": "standard",
"test": "jest --verbose --coverage"
"lint": "standard lib/**/*.js",
"test": "npm run lint && jest --verbose --coverage",
"test:dev": "jest --watch"
},
"sails": {
"isHook": true,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment