grafo-client
Version:
Grafo Client API Library
1 lines • 1.83 kB
JavaScript
;var Comment=require("./models/comment_old"),request=require("request");const queryString=require("query-string");var ConfHelper=require("./conf/conf_helper");function ConversationApi(e,o,r,n){this.glbSockets=e,this.config=o,this.confHelper=new ConfHelper(o),this.sessionCookie=r,this.logger=n}module.exports=ConversationApi,ConversationApi.prototype.addComment=function(e,o,r){var n=this;return new Promise((t,s)=>{var i=new Comment("add",r);i.setOwningDocument(e),i.setParent(o);var g=i.getCommunicationFormat("add");n.logger.debug(g),n.glbSockets.messengerSocket.send(JSON.stringify(g)),t()})},ConversationApi.prototype.getConversationsByNode=function(e,o,r){var n=this,t=null,s=null;return new Promise(function(i,g){var a={Cookie:n.sessionCookie};"concept"==o.nodeType?s=o.id:"attribute"==o.nodeType&&(t=o.groupId,s=o.id);var u={url:n.confHelper.getBaseRestUrl()+"/conversations/"+e+"/"+t+"/"+s+"/"+r,method:"GET",headers:a};request(u,function(e,o,r){if(e||200!=o.statusCode)n.logger.error(e),g(new Error("Problem in fetching Conversations for "+e));else{var t=JSON.parse(o.body);n.logger.debug("Conversations fetched"),n.logger.debug(t),i(t)}})})},ConversationApi.prototype.listComments=function(e){var o=this;return o.logger.debug("Conversation Api: List all 07_comments"),new Promise(function(r,n){var t={Cookie:o.sessionCookie},s={url:o.confHelper.getBaseRestUrl()+"/api/v1/documents/"+e.docId+"/concept/"+e.nodeId+"/07_comments?"+queryString.stringify(e.getQueryMap()),method:"GET",headers:t};o.logger.debug("commOPtions******"),o.logger.debug(s),request(s,function(e,t,s){if(e)o.logger.error(e),n(new Error("Problem in fetching 07_comments list"));else if(200===t.statusCode){var i=JSON.parse(t.body);r(i)}else{var g="HTTP error code: "+t.statusCode+", Message: "+t.body;o.logger.error(g),n(new Error(g))}})})};