1- const crud = require ( '@cocreate/crud-client' )
1+ const CRUD = require ( '@cocreate/crud-client' )
22const socketClient = require ( '@cocreate/socket-client' )
33let socket = new socketClient ( "ws" ) ;
44
5+ let crud
6+ if ( CRUD && CRUD . default )
7+ crud = CRUD . default
8+ else
9+ crud = CRUD
10+
511crud . setSocket ( socket ) ;
612
713var api = ( ( ) => {
@@ -28,18 +34,20 @@ var api = ( ()=> {
2834
2935 let org = await crud . readDocument ( {
3036 collection : "organizations" ,
31- document_id : config [ "organization_id" ] ,
3237 apiKey : config [ "apiKey" ] ,
33- organization_id : config [ "organization_id" ]
38+ organization_id : config [ "organization_id" ] ,
39+ data : {
40+ _id : config [ "organization_id" ]
41+ }
42+
3443 } ) ;
3544
36- try {
37- org = org [ "data" ] ;
38- } catch ( e ) {
45+ if ( ! org || ! org . data && ! org . data [ 0 ] ) {
3946 console . log ( component , " Error GET ORG in : " , e ) ;
4047 return false ;
4148 }
42- return org ;
49+
50+ return org . data [ 0 ] ;
4351 } ,
4452
4553 getOrgInRoutesbyHostname : async ( config , hostname ) => {
@@ -58,7 +66,7 @@ var api = ( ()=> {
5866 host : socket_config . host
5967 } )
6068
61- let data2 = await crud . readDocuments ( {
69+ let data2 = await crud . readDocument ( {
6270 collection : "organizations" ,
6371 filter : {
6472 query : [ {
@@ -67,7 +75,6 @@ var api = ( ()=> {
6775 value : [ hostname ]
6876 } ] ,
6977 } ,
70- is_collection : false ,
7178 apiKey : config [ "config" ] [ "apiKey" ] ,
7279 organization_id : config [ "config" ] [ "organization_id" ]
7380 } ) ;
@@ -95,9 +102,11 @@ var api = ( ()=> {
95102
96103 let myOrg = await crud . readDocument ( {
97104 collection : "organizations" ,
98- document_id : org [ "_id" ] ,
99105 apiKey : org [ "apiKey" ] ,
100- organization_id : org [ "_id" ]
106+ organization_id : org [ "_id" ] ,
107+ data : {
108+ _id : org [ "_id" ]
109+ }
101110 } ) ;
102111 let result = { 'row' :myOrg , 'socket_config' :socket_config } ;
103112 return result ;
0 commit comments