pinclub/pinclub

View on GitHub
api/v1/topic_collect.js

Summary

Maintainability
D
2 days
Test Coverage

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

function collect(req, res, next) {
  var topic_id = req.body.topic_id;

  if (!validator.isMongoId(topic_id)) {
    res.status(400);
Severity: Minor
Found in api/v1/topic_collect.js - About 1 hr to fix

    Function de_collect has 32 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    function de_collect(req, res, next) {
      var topic_id = req.body.topic_id;
    
      if (!validator.isMongoId(topic_id)) {
        res.status(400);
    Severity: Minor
    Found in api/v1/topic_collect.js - About 1 hr to fix

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

      function list(req, res, next) {
        var loginname = req.params.loginname;
        var ep        = new EventProxy();
      
        ep.fail(next);
      Severity: Minor
      Found in api/v1/topic_collect.js - About 1 hr to fix

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

            ep.all('collected_topics', function (collected_topics) {
        
              var ids = collected_topics.map(function (doc) {
                return String(doc.topic_id);
              });
        Severity: Major
        Found in api/v1/topic_collect.js and 1 other location - About 5 hrs to fix
        api/v2/board.js on lines 297..310

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

        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

            ep.all('topics', function (topics) {
              topics = topics.map(function (topic) {
                topic.author = _.pick(topic.author, ['loginname', 'avatar_url']);
                return _.pick(topic, ['id', 'author', 'tab', 'content', 'title', 'last_reply_at',
                  'good', 'top', 'reply_count', 'visit_count', 'create_at', 'author']);
        Severity: Major
        Found in api/v1/topic_collect.js and 1 other location - About 3 hrs to fix
        api/v2/board.js on lines 312..320

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

        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

              UserProxy.getUserById(req.user.id, function (err, user) {
                if (err) {
                  return next(err);
                }
                user.collect_topic_count -= 1;
        Severity: Major
        Found in api/v1/topic_collect.js and 1 other location - About 1 hr to fix
        api/v1/topic_collect.js on lines 84..90

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

        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

              UserProxy.getUserById(req.user.id, function (err, user) {
                if (err) {
                  return next(err);
                }
                user.collect_topic_count += 1;
        Severity: Major
        Found in api/v1/topic_collect.js and 1 other location - About 1 hr to fix
        api/v1/topic_collect.js on lines 124..130

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

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

          if (!validator.isMongoId(topic_id)) {
            res.status(400);
            return res.send({success: false, error_msg: '不是有效的话题id'});
          }
        Severity: Major
        Found in api/v1/topic_collect.js and 9 other locations - About 45 mins to fix
        api/v1/reply.js on lines 24..27
        api/v1/reply.js on lines 84..87
        api/v1/topic.js on lines 114..117
        api/v1/topic_collect.js on lines 55..58
        api/v2/board.js on lines 63..66
        api/v2/board.js on lines 170..173
        api/v2/board.js on lines 230..233
        api/v2/image.js on lines 446..449
        api/v2/topic.js on lines 193..196

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

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

          if (!validator.isMongoId(topic_id)) {
            res.status(400);
            return res.send({success: false, error_msg: '不是有效的话题id'});
          }
        Severity: Major
        Found in api/v1/topic_collect.js and 9 other locations - About 45 mins to fix
        api/v1/reply.js on lines 24..27
        api/v1/reply.js on lines 84..87
        api/v1/topic.js on lines 114..117
        api/v1/topic_collect.js on lines 103..106
        api/v2/board.js on lines 63..66
        api/v2/board.js on lines 170..173
        api/v2/board.js on lines 230..233
        api/v2/image.js on lines 446..449
        api/v2/topic.js on lines 193..196

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

        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