Showing 67 of 142 total issues
Function up
has 38 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('Rates', {
id: {
allowNull: false,
autoIncrement: true,
Function clap
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static async clap(req, res) {
try {
if (req.body.author === req.body.userId) {
util.setError(401, 'You can not clap to your own post');
return util.send(res);
Function bodyHighlightedText
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static async bodyHighlightedText(req, res) {
try {
const [{ id: userId }, { slug }, { startIndex, endIndex }] = [req.auth, req.params, req.query];
const start = Number(startIndex);
const end = Number(endIndex);
Function exports
has 37 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
module.exports = (sequelize, DataTypes) => {
const Article = sequelize.define('Article', {
slug: { type: DataTypes.STRING, allowNull: false },
title: { type: DataTypes.STRING, allowNull: false },
description: { type: DataTypes.TEXT, allowNull: false },
Function exports
has 36 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
module.exports = (sequelize, DataTypes) => {
const Comment = sequelize.define('Comment', {
userId: DataTypes.INTEGER,
articleSlug: {
type: DataTypes.STRING,
Function up
has 35 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('Highlights', {
id: {
allowNull: false,
autoIncrement: true,
Function listOfFollowers
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static async listOfFollowers(req, res, next) {
try {
const followedUser = await models.user.findOne({ where: { email: req.auth.email } });
const myFollowers = await models.Follow.findAll({
where: { followedUserId: followedUser.id },
Function getArticleRating
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static async getArticleRating(req, res) {
try {
// Initialize rating data
const { articleSlug } = req.params;
// check if rate is arleady there
Function requestPasswordReset
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static async requestPasswordReset(req, res) {
// check if email provided exists in db
const { email } = req.body;
if (!email) {
return res.status(400).send({
Function listOfFollowedUsers
has 33 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static async listOfFollowedUsers(req, res, next) {
try {
const follower = await models.user.findOne({ where: { email: req.auth.email } });
const usersIfollow = await models.Follow.findAll({
where: { followerId: follower.id },
Function checkDuplicate
has 32 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static async checkDuplicate(req, res, next) {
const { articleId, name } = req.body;
const existing = await checkItem({ userId: req.auth.id, articleId });
const existingName = await checkItem({ name });
const bookmark = await checkItem({ userId: req.auth.id, name, articleId });
Function login
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
Open
static async login(req, res) {
data = req.user;
const type = data.provider;
try {
let user;
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function up
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('AppNotifications', {
id: {
allowNull: false,
autoIncrement: true,
Function notifyUsersWhoFavorited
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static async notifyUsersWhoFavorited(req, res, articleId, slug) {
try {
// returns an array of userIDs have favorited the article commented on
const arrayOfUserIDs = await models.Favorites.findAll({ where: { articleId } }).map(item => item.dataValues.userId);
Function createArticles
has 31 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static async createArticles(req, res) {
const userId = req.auth.id;
const findUser = await Userservice.getOneUser(userId);
// const images = await cloudinaryHelper.generateCloudinaryUrl(req.files);
const { images } = req.body;
Function exports
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
module.exports = (sequelize, DataTypes) => {
const Rate = sequelize.define('Rate', {
userEmail: {
type: DataTypes.STRING,
references: {
Function sendEmail
has 29 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
const sendEmail = (email, username, url) => {
sgMail.setApiKey(process.env.SendGridApiKey);
const msg = {
to: `${email}`,
Function sendEmail
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
export const sendEmail = (email, username, url) => {
sgMail.setApiKey(process.env.SendGridApiKey);
const msg = {
to: `${email}`,
Function up
has 28 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
up: (queryInterface, Sequelize) => {
return queryInterface.createTable('BookMarks', {
id: {
allowNull: false,
autoIncrement: true,
Function updateUser
has 27 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
static async updateUser(req, res) {
const alteredUser = req.body;
const { email } = req.params;
if (!email) {
return res.status(400).send({