All files CommentsRepository.js

100% Statements 15/15
50% Branches 4/8
100% Functions 8/8
100% Lines 15/15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45          2x 2x 2x 1x 1x     2x       2x       1x 1x       2x 2x         1x 1x         3x       5x      
import request from 'request-promise';
import dispatcher from 'definity-dispatcher';
 
class CommentsRepository {
  save(commentsId, comment) {
    var uri = 'http://localhost:8080/api/comment-groups/' + commentsId + '/comments';
    var method = 'POST';
    if (comment._id) {
      uri = uri + '/' + comment._id;
      method = 'PUT';
    }
 
    var option = {uri:uri, method: method, body: comment, json: true, headers: {
      'Content-Type': 'application/json; charset=utf-8'}
    };
 
    request(option);
  }
 
  remove(commentsId, id) {
    var uri = 'http://localhost:8080/api/comment-groups/' + commentsId + '/comments/' + id;
    request({uri:uri, method: 'DELETE'}).then((response) => {});
  }
 
  load(commentsId, skip = 0, limit = 5) {
    this._load(commentsId, skip, limit).then((response) => {
        dispatcher.dispatch('COMMENTS', response);
    });
  }
 
  loadComments(commentsId, skip = 0, limit = 5) {
    this._load(commentsId, skip, limit).then((response) => {
        dispatcher.dispatch('LOAD_COMMENTS', response);
    });
  }
 
  _load(commentsId, skip = 0, limit = 5) {
    return request({uri:'http://localhost:8080/api/comment-groups/' + commentsId + '?skip=' + skip + '&limit=' + limit + '&sort=desc', json: true});
  }
}
 
const commentsRepository = new CommentsRepository();
 
export default commentsRepository;