andela/codepirates-ah-backend

View on GitHub

Showing 67 of 142 total issues

Function up has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  up: (queryInterface, Sequelize) => {
    return queryInterface.createTable('Rates', {
      id: {
        allowNull: false,
        autoIncrement: true,
Severity: Minor
Found in src/migrations/20190814093719-create-rate.js - About 1 hr to fix

    Function clap has 37 lines of code (exceeds 25 allowed). Consider refactoring.
    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);
    Severity: Minor
    Found in src/controllers/likes.controller.js - About 1 hr to fix

      Function bodyHighlightedText has 37 lines of code (exceeds 25 allowed). Consider refactoring.
      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);
      Severity: Minor
      Found in src/controllers/highlight.controller.js - About 1 hr to fix

        Function exports has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        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 },
        Severity: Minor
        Found in src/models/article.js - About 1 hr to fix

          Function exports has 36 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          module.exports = (sequelize, DataTypes) => {
            const Comment = sequelize.define('Comment', {
              userId: DataTypes.INTEGER,
              articleSlug: {
                type: DataTypes.STRING,
          Severity: Minor
          Found in src/models/comment.js - About 1 hr to fix

            Function up has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              up: (queryInterface, Sequelize) => {
                return queryInterface.createTable('Highlights', {
                  id: {
                    allowNull: false,
                    autoIncrement: true,
            Severity: Minor
            Found in src/migrations/20190826113358-create-highlight.js - About 1 hr to fix

              Function listOfFollowers has 33 lines of code (exceeds 25 allowed). Consider refactoring.
              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 },
              Severity: Minor
              Found in src/controllers/follow.controller.js - About 1 hr to fix

                Function getArticleRating has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  static async getArticleRating(req, res) {
                    try {
                      // Initialize rating data
                      const { articleSlug } = req.params;
                      // check if rate is arleady there
                Severity: Minor
                Found in src/controllers/rating.controller.js - About 1 hr to fix

                  Function requestPasswordReset has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                    static async requestPasswordReset(req, res) {
                      // check if email provided exists in db
                      const { email } = req.body;
                      if (!email) {
                        return res.status(400).send({
                  Severity: Minor
                  Found in src/controllers/user.controller.js - About 1 hr to fix

                    Function listOfFollowedUsers has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                    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 },
                    Severity: Minor
                    Found in src/controllers/follow.controller.js - About 1 hr to fix

                      Function checkDuplicate has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                      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 });
                      Severity: Minor
                      Found in src/middlewares/bookmarks.js - About 1 hr to fix

                        Function login has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                        Open

                          static async login(req, res) {
                            data = req.user;
                            const type = data.provider;
                            try {
                              let user;
                        Severity: Minor
                        Found in src/controllers/social.js - About 1 hr to fix

                        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

                          up: (queryInterface, Sequelize) => {
                            return queryInterface.createTable('AppNotifications', {
                              id: {
                                allowNull: false,
                                autoIncrement: true,
                        Severity: Minor
                        Found in src/migrations/20190822010033-create-app-notification.js - About 1 hr to fix

                          Function notifyUsersWhoFavorited has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                          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);
                          
                          
                          Severity: Minor
                          Found in src/services/notification.service.js - About 1 hr to fix

                            Function createArticles has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                            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;
                            Severity: Minor
                            Found in src/controllers/articles.controller.js - About 1 hr to fix

                              Function exports has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                              module.exports = (sequelize, DataTypes) => {
                                const Rate = sequelize.define('Rate', {
                                  userEmail: {
                                    type: DataTypes.STRING,
                                    references: {
                              Severity: Minor
                              Found in src/models/rate.js - About 1 hr to fix

                                Function sendEmail has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                const sendEmail = (email, username, url) => {
                                  sgMail.setApiKey(process.env.SendGridApiKey);
                                
                                  const msg = {
                                    to: `${email}`,
                                Severity: Minor
                                Found in src/services/resetpassword.service.js - About 1 hr to fix

                                  Function sendEmail has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                                  Open

                                  export const sendEmail = (email, username, url) => {
                                    sgMail.setApiKey(process.env.SendGridApiKey);
                                  
                                    const msg = {
                                      to: `${email}`,
                                  Severity: Minor
                                  Found in src/helpers/verification-email.js - About 1 hr to fix

                                    Function up has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                                    Open

                                        up: (queryInterface, Sequelize) => {
                                            return queryInterface.createTable('BookMarks', {
                                                id: {
                                                    allowNull: false,
                                                    autoIncrement: true,
                                    Severity: Minor
                                    Found in src/migrations/create-bookmark.js - About 1 hr to fix

                                      Function updateUser has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                                      Open

                                        static async updateUser(req, res) {
                                          const alteredUser = req.body;
                                          const { email } = req.params;
                                          if (!email) {
                                            return res.status(400).send({
                                      Severity: Minor
                                      Found in src/controllers/user.controller.js - About 1 hr to fix
                                        Severity
                                        Category
                                        Status
                                        Source
                                        Language