Skip to content

Commit 2f516ca

Browse files
committed
listDiagrams should return instantiated objects, not resources
1 parent 2ff26f9 commit 2f516ca

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

lib.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -535,14 +535,23 @@ CoggleApi.prototype = {
535535
* }
536536
*/
537537
listDiagrams: function listDiagrams(options, callback){
538+
var self = this;
539+
function wrappedCB(err, diagram_resources){
540+
if(err)
541+
return callback(err);
542+
var diagrams = diagram_resources.map(function(resource){
543+
return new CoggleApiDiagram(self, resource);
544+
});
545+
return callback(err, diagrams);
546+
}
538547
if(options.organisation){
539548
if(typeof options.organisation !== 'string')
540549
throw new Error("options.organisation must be a string or undefined");
541550
if(!/^[a-z]+[a-z0-9-]{2,}$/.test(options.organisation))
542551
throw new Error("invalid organisation name");
543-
this.get('/api/1/organisations/' + options.organisation + '/diagrams', '', callback);
552+
this.get('/api/1/organisations/' + options.organisation + '/diagrams', '', wrappedCB);
544553
}else{
545-
this.get('/api/1/diagrams', '', callback);
554+
this.get('/api/1/diagrams', '', wrappedCB);
546555
}
547556
},
548557

test/test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function testListDiagrams(coggle, check_for_coggle){
4646

4747
var found_created_diagram = false;
4848
for(var i = 0; i < diagrams.length; i++){
49-
if(diagrams[i].id == check_for_coggle.id){
49+
if(diagrams[i].id == check_for_coggle.id && diagrams[i].title == check_for_coggle.title){
5050
found_created_diagram = true;
5151
break;
5252
}

0 commit comments

Comments
 (0)