-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
758 additions
and
406 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,37 @@ | ||
{ | ||
"parserOptions": { | ||
"ecmaVersion": 2018, | ||
"sourceType": "module" | ||
}, | ||
"root": true, | ||
"extends": "airbnb-base", | ||
"env": { | ||
"node": true, | ||
"es6": true, | ||
"mocha": true | ||
}, | ||
"rules": { | ||
"one-var": 0, | ||
"one-var-declaration-per-line": 0, | ||
"new-cap": 0, | ||
"consistent-return": 0, | ||
"no-param-reassign": 0, | ||
"comma-dangle": 0, | ||
"curly": ["error", "multi-line"], | ||
"import/no-unresolved": [2, { "commonjs": true }], | ||
"no-shadow": ["error", { "allow": ["req", "res", "err"] }], | ||
"valid-jsdoc": ["error", { | ||
"requireReturn": true, | ||
"requireReturnType": true, | ||
"requireParamDescription": false, | ||
"requireReturnDescription": true | ||
}], | ||
"require-jsdoc": ["error", { | ||
"require": { | ||
"FunctionDeclaration": true, | ||
"MethodDefinition": true, | ||
"ClassDeclaration": true | ||
} | ||
}] | ||
} | ||
"parserOptions": { | ||
"ecmaVersion": 2018, | ||
"sourceType": "module" | ||
}, | ||
"root": true, | ||
"extends": "airbnb-base", | ||
"env": { | ||
"node": true, | ||
"es6": true, | ||
"mocha": true | ||
}, | ||
"rules": { | ||
"one-var": 0, | ||
"one-var-declaration-per-line": 0, | ||
"new-cap": 0, | ||
"consistent-return": 0, | ||
"no-param-reassign": 0, | ||
"comma-dangle": 0, | ||
"curly": ["error", "multi-line"], | ||
"import/no-unresolved": [2, { "commonjs": true }], | ||
"no-shadow": ["error", { "allow": ["req", "res", "err"] }], | ||
"valid-jsdoc": ["error", { | ||
"requireReturn": true, | ||
"requireReturnType": true, | ||
"requireParamDescription": false, | ||
"requireReturnDescription": true | ||
}], | ||
"require-jsdoc": ["error", { | ||
"require": { | ||
"FunctionDeclaration": true, | ||
"MethodDefinition": true, | ||
"ClassDeclaration": true | ||
} | ||
}] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
import { Article } from '../models'; | ||
|
||
export default async (req, res, next) => { | ||
const { id } = req.user; | ||
const { articleId } = req.params; | ||
try { | ||
const articleExist = await Article.findOne({ where: { id: articleId } }); | ||
if (articleExist) { | ||
if (articleExist.dataValues.userId === id) { | ||
return res.status(403).json({ | ||
success: false, | ||
errors: ['Permission denied, user cannot rate their own article'] | ||
}); | ||
} return next(); | ||
} | ||
return res.status(404).json({ | ||
success: false, | ||
errors: ['This article does not exist'] | ||
}); | ||
} catch (error) { | ||
return res.status(500).json({ | ||
success: false, | ||
errors: ['Error rating article'] | ||
}); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.