540co/ads-bpa

View on GitHub
server/routes/searches.js

Summary

Maintainability
C
1 day
Test Coverage

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

        function(callback){
          Searches.getList(db.connection, response.meta.limit, response.meta.offset, function (data) {
            response.data = data;
            callback();
          });
Severity: Major
Found in server/routes/searches.js and 1 other location - About 1 hr to fix
server/routes/reactions.js on lines 52..57

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 64.

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 4 locations. Consider refactoring.
Open

  if (!req.query.limit) {response.meta.limit = 25;} else {response.meta.limit = parseInt(req.query.limit);}
Severity: Major
Found in server/routes/searches.js and 3 other locations - About 1 hr to fix
server/routes/reactions.js on lines 20..20
server/routes/reactions.js on lines 30..34
server/routes/searches.js on lines 85..89

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 63.

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 4 locations. Consider refactoring.
Open

  if (!req.query.offset) {
    response.meta.offset = 0;
  } else {
    response.meta.offset = parseInt(req.query.offset);
  }
Severity: Major
Found in server/routes/searches.js and 3 other locations - About 1 hr to fix
server/routes/reactions.js on lines 20..20
server/routes/reactions.js on lines 30..34
server/routes/searches.js on lines 75..75

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 63.

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 16 locations. Consider refactoring.
Open

        if (!req.body.search) {
          err = new Error();
          err.status = 400;
          err.error = "A search attribute was not found in the body";
          err.message = "A search key/value must be passed in body (ex. {'search':'ibuprofen'})";
Severity: Major
Found in server/routes/searches.js and 15 other locations - About 55 mins to fix
server/routes/reactions.js on lines 77..133
server/routes/reactions.js on lines 85..132
server/routes/reactions.js on lines 99..128
server/routes/reactions.js on lines 106..125
server/routes/reactions.js on lines 152..213
server/routes/reactions.js on lines 233..244
server/routes/reactions.js on lines 259..332
server/routes/reactions.js on lines 270..331
server/routes/reactions.js on lines 279..329
server/routes/reactions.js on lines 300..325
server/routes/reactions.js on lines 307..323
server/routes/reactions.js on lines 353..364
server/routes/searches.js on lines 16..56
server/routes/searches.js on lines 24..55
server/routes/searches.js on lines 91..120

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 54.

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 16 locations. Consider refactoring.
Open

    if(req.headers['content-type'].indexOf("application/json") < 0) {
      err = new Error();
      err.status = 400;
      err.error = "Invalid content type";
      err.message = "Valid content type is 'application/json'";
Severity: Major
Found in server/routes/searches.js and 15 other locations - About 55 mins to fix
server/routes/reactions.js on lines 77..133
server/routes/reactions.js on lines 85..132
server/routes/reactions.js on lines 99..128
server/routes/reactions.js on lines 106..125
server/routes/reactions.js on lines 152..213
server/routes/reactions.js on lines 233..244
server/routes/reactions.js on lines 259..332
server/routes/reactions.js on lines 270..331
server/routes/reactions.js on lines 279..329
server/routes/reactions.js on lines 300..325
server/routes/reactions.js on lines 307..323
server/routes/reactions.js on lines 353..364
server/routes/searches.js on lines 24..55
server/routes/searches.js on lines 32..53
server/routes/searches.js on lines 91..120

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 54.

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 16 locations. Consider refactoring.
Open

  if(response.meta.offset < 0) {
    err = new Error();
    err.status = 404;
    err.error = "No searches can be found";
    err.message = "Bad offset query parameter - offset must be > 0";
Severity: Major
Found in server/routes/searches.js and 15 other locations - About 55 mins to fix
server/routes/reactions.js on lines 77..133
server/routes/reactions.js on lines 85..132
server/routes/reactions.js on lines 99..128
server/routes/reactions.js on lines 106..125
server/routes/reactions.js on lines 152..213
server/routes/reactions.js on lines 233..244
server/routes/reactions.js on lines 259..332
server/routes/reactions.js on lines 270..331
server/routes/reactions.js on lines 279..329
server/routes/reactions.js on lines 300..325
server/routes/reactions.js on lines 307..323
server/routes/reactions.js on lines 353..364
server/routes/searches.js on lines 16..56
server/routes/searches.js on lines 24..55
server/routes/searches.js on lines 32..53

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 54.

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 4 locations. Consider refactoring.
Open

          searches.incrementCount(db.connection, function (result) {
            response.data = result;
            response.calculateExecutionTime();
            res.json(response);
          });
Severity: Major
Found in server/routes/searches.js and 3 other locations - About 55 mins to fix
server/routes/reactions.js on lines 120..124
server/routes/reactions.js on lines 195..199
server/routes/reactions.js on lines 317..321

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 54.

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 4 locations. Consider refactoring.
Open

  if (req.headers['content-type']) {
    if(req.headers['content-type'].indexOf("application/json") < 0) {
      err = new Error();
      err.status = 400;
      err.error = "Invalid content type";
Severity: Major
Found in server/routes/searches.js and 3 other locations - About 55 mins to fix
server/routes/reactions.js on lines 76..140
server/routes/reactions.js on lines 151..220
server/routes/reactions.js on lines 258..340

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 54.

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 16 locations. Consider refactoring.
Open

      if (req.headers['content-type'].indexOf("application/json") < 0) {
        err = new Error();
        err.status = 400;
        err.error = "Invalid content type";
        err.message = "Valid content type is 'application/json'";
Severity: Major
Found in server/routes/searches.js and 15 other locations - About 55 mins to fix
server/routes/reactions.js on lines 77..133
server/routes/reactions.js on lines 85..132
server/routes/reactions.js on lines 99..128
server/routes/reactions.js on lines 106..125
server/routes/reactions.js on lines 152..213
server/routes/reactions.js on lines 233..244
server/routes/reactions.js on lines 259..332
server/routes/reactions.js on lines 270..331
server/routes/reactions.js on lines 279..329
server/routes/reactions.js on lines 300..325
server/routes/reactions.js on lines 307..323
server/routes/reactions.js on lines 353..364
server/routes/searches.js on lines 16..56
server/routes/searches.js on lines 32..53
server/routes/searches.js on lines 91..120

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 54.

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 2 locations. Consider refactoring.
Open

        function(callback){
          Searches.getCount(db.connection, function (count) {
            response.meta.total_count = count;
            callback();
          });
Severity: Minor
Found in server/routes/searches.js and 1 other location - About 35 mins to fix
server/routes/reactions.js on lines 46..51

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 47.

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