nitrotasks/nitro-server

View on GitHub
lib/controllers/tasks.js

Summary

Maintainability
F
3 days
Test Coverage

File tasks.js has 440 lines of code (exceeds 250 allowed). Consider refactoring.
Open

const passport = require('passport')
const logger = require('../logger.js')
const User = require('../models/user')
const List = require('../models/list')
const Task = require('../models/task')
Severity: Minor
Found in lib/controllers/tasks.js - About 6 hrs to fix

    Function updateSingle has 39 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

              const updateSingle = function(model) {
                return new Promise(function(resolve, reject) {
                  const newData = req.body.tasks[model.id]
                  if (
                    model.updatedAt.getTime() - UPDATE_THRESHOLD <
    Severity: Minor
    Found in lib/controllers/tasks.js - About 1 hr to fix

      Avoid deeply nested control flow statements.
      Open

                      if (req.body.order.indexOf(key) === -1) {
                        shouldUpdate = false
                      }
      Severity: Major
      Found in lib/controllers/tasks.js - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            if (key === 'name') {
                              payload[key] = (newData[key] || '').substring(0, 255) // STRING
                            } else if (key === 'notes') {
                              payload[key] = (newData[key] || '').substring(0, 51200) // 50KB
                            } else if (key === 'priority') {
        Severity: Major
        Found in lib/controllers/tasks.js - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                        if (shouldUpdate) {
                          payload.order = req.body.order
                        }
          Severity: Major
          Found in lib/controllers/tasks.js - About 45 mins to fix

            Similar blocks of code found in 7 locations. Consider refactoring.
            Open

                      retrieved
                        .update({
                          order: newOrder
                        })
                        .then(function() {
            Severity: Major
            Found in lib/controllers/tasks.js and 6 other locations - About 1 hr to fix
            lib/controllers/tasks.js on lines 118..133
            lib/controllers/tasks.js on lines 76..151
            lib/controllers/tasks.js on lines 166..235
            lib/controllers/tasks.js on lines 311..339
            lib/controllers/tasks.js on lines 243..366
            lib/controllers/tasks.js on lines 373..453

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 73.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 7 locations. Consider refactoring.
            Open

                      Promise.all(promises)
                        .then(function(data) {
                          // set the update so the client can pick up on changes on this list
                          retrieved.changed('updatedAt', true)
                          retrieved
            Severity: Major
            Found in lib/controllers/tasks.js and 6 other locations - About 1 hr to fix
            lib/controllers/tasks.js on lines 118..133
            lib/controllers/tasks.js on lines 76..151
            lib/controllers/tasks.js on lines 166..235
            lib/controllers/tasks.js on lines 243..366
            lib/controllers/tasks.js on lines 400..426
            lib/controllers/tasks.js on lines 373..453

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 73.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 7 locations. Consider refactoring.
            Open

                      list
                        .update(payload)
                        .then(function(list) {
                          res.send(list)
                        })
            Severity: Major
            Found in lib/controllers/tasks.js and 6 other locations - About 1 hr to fix
            lib/controllers/tasks.js on lines 76..151
            lib/controllers/tasks.js on lines 166..235
            lib/controllers/tasks.js on lines 311..339
            lib/controllers/tasks.js on lines 243..366
            lib/controllers/tasks.js on lines 400..426
            lib/controllers/tasks.js on lines 373..453

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 73.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 7 locations. Consider refactoring.
            Open

              List.findById(req.params.listid, query)
                .then(function(list) {
                  if (list) {
                    // todo: proper validation?
                    const adding = req.body.tasks.map(function(item) {
            Severity: Major
            Found in lib/controllers/tasks.js and 6 other locations - About 1 hr to fix
            lib/controllers/tasks.js on lines 118..133
            lib/controllers/tasks.js on lines 76..151
            lib/controllers/tasks.js on lines 311..339
            lib/controllers/tasks.js on lines 243..366
            lib/controllers/tasks.js on lines 400..426
            lib/controllers/tasks.js on lines 373..453

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 73.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 7 locations. Consider refactoring.
            Open

              List.findById(req.params.listid, query)
                .then(function(list) {
                  if (list) {
                    if (
                      list.updatedAt.getTime() - UPDATE_THRESHOLD <
            Severity: Major
            Found in lib/controllers/tasks.js and 6 other locations - About 1 hr to fix
            lib/controllers/tasks.js on lines 118..133
            lib/controllers/tasks.js on lines 166..235
            lib/controllers/tasks.js on lines 311..339
            lib/controllers/tasks.js on lines 243..366
            lib/controllers/tasks.js on lines 400..426
            lib/controllers/tasks.js on lines 373..453

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 73.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 7 locations. Consider refactoring.
            Open

                List.findById(req.params.listid, {
                  include: [
                    {
                      model: User,
                      attributes: ['id'],
            Severity: Major
            Found in lib/controllers/tasks.js and 6 other locations - About 1 hr to fix
            lib/controllers/tasks.js on lines 118..133
            lib/controllers/tasks.js on lines 76..151
            lib/controllers/tasks.js on lines 166..235
            lib/controllers/tasks.js on lines 311..339
            lib/controllers/tasks.js on lines 400..426
            lib/controllers/tasks.js on lines 373..453

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 73.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 7 locations. Consider refactoring.
            Open

                List.findById(req.params.listid, {
                  attributes: ['id', 'order'],
                  include: [
                    {
                      model: User,
            Severity: Major
            Found in lib/controllers/tasks.js and 6 other locations - About 1 hr to fix
            lib/controllers/tasks.js on lines 118..133
            lib/controllers/tasks.js on lines 76..151
            lib/controllers/tasks.js on lines 166..235
            lib/controllers/tasks.js on lines 311..339
            lib/controllers/tasks.js on lines 243..366
            lib/controllers/tasks.js on lines 400..426

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 73.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

                      if (retrieved) {
                        retrieved.tasks.forEach(function(item) {
                          const index = specifically.indexOf(item.id)
                          if (index > -1) {
                            specifically.splice(index, 1)
            Severity: Major
            Found in lib/controllers/tasks.js and 1 other location - About 1 hr to fix
            lib/controllers/tasks.js on lines 429..436

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 72.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Identical blocks of code found in 2 locations. Consider refactoring.
            Open

                      if (retrieved) {
                        retrieved.tasks.forEach(function(item) {
                          const index = specifically.indexOf(item.id)
                          if (index > -1) {
                            specifically.splice(index, 1)
            Severity: Major
            Found in lib/controllers/tasks.js and 1 other location - About 1 hr to fix
            lib/controllers/tasks.js on lines 342..349

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 72.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

              tasksDetails(true, req.query, req.user, req.params.listid)
                .then(data => {
                  res.send(data)
                })
                .catch(err => {
            Severity: Major
            Found in lib/controllers/tasks.js and 2 other locations - About 1 hr to fix
            lib/controllers/archivedtasks.js on lines 30..44
            lib/controllers/tasks.js on lines 18..35

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 71.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 3 locations. Consider refactoring.
            Open

              tasksDetails(false, req.query, req.user, req.params.listid)
                .then(data => {
                  if (typeof req.query.tasks !== 'undefined') {
                    return res.send(data.tasks)
                  }
            Severity: Major
            Found in lib/controllers/tasks.js and 2 other locations - About 1 hr to fix
            lib/controllers/archivedtasks.js on lines 30..44
            lib/controllers/tasks.js on lines 38..52

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 71.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            There are no issues that match your filters.

            Category
            Status