11const crud = require ( '@cocreate/crud-client' )
2- const CoCreateSocketClient = require ( '@cocreate/socket-client' )
3- let socket = new CoCreateSocketClient ( "ws" ) ;
2+ const socketClient = require ( '@cocreate/socket-client' )
3+ let socket = new socketClient ( "ws" ) ;
44
55crud . setSocket ( socket ) ;
66
77var api = ( ( ) => {
88 return {
9- send_response : ( wsManager , socket , obj , send_response ) => {
10- console . log ( " Response TO-> " + send_response )
9+ send_response : ( wsManager , socket , obj , send_response ) => {
10+ console . log ( send_response , " Response Sent" )
1111 wsManager . send ( socket , send_response , obj )
1212 } ,
1313
14- handleError : ( wsManager , socket , type , error , module_id ) => {
15- const response = {
16- 'object' : 'error' ,
17- 'data' :error || error . response || error . response . data || error . response . body || error . message || error ,
18- } ;
19- wsManager . send ( socket , module_id , { type, response } )
20- //send_response(wsManager, socket, { type, response }, module_id);
14+ handleError : ( wsManager , socket , type , error , module_id ) => {
15+ const response = {
16+ 'object' : 'error' ,
17+ 'data' :error || error . response || error . response . data || error . response . body || error . message || error ,
18+ } ;
19+ wsManager . send ( socket , module_id , { type, response } )
2120 } ,
22- getOrg : async ( config , module ) => {
23- console . log ( " config WS utils==== " , config )
21+
22+ getOrg : async ( config , module ) => {
2423
2524 socket . create ( {
2625 namespace : config [ "organization_id" ] ,
2726 room : null ,
28- host : "server.cocreate.app:8088"
27+ host : config [ "host" ]
2928 } )
30- const event = "getOrg" ;
31-
32-
33- console . log ( "Org_id => " , config [ "organization_id" ] )
34-
35- let org_row = await crud . readDocument ( {
29+
30+ let org = await crud . readDocument ( {
3631 collection : "organizations" ,
3732 name :"name" ,
3833 document_id : config [ "organization_id" ] ,
39- event,
4034 apiKey : config [ "apiKey" ] ,
41- organization_id : '5de0387b12e200ea63204d6c'
35+ organization_id : config [ "organization_id" ]
4236 } ) ;
4337
4438 try {
45- org_row = org_row [ "data" ] ;
46- } catch ( e ) {
47- console . log ( module , " Error GET ORG in : " , e ) ;
39+ org = org [ "data" ] ;
40+ } catch ( e ) {
41+ console . log ( module , " Error GET ORG in : " , e ) ;
4842 return false ;
49- }
50- return org_row ;
43+ }
44+ return org ;
5145 } ,
46+
5247 getOrgInRoutesbyHostname : async ( config , hostname ) => {
5348 var socket_config = {
5449 "config" : {
@@ -59,29 +54,25 @@ var api = ( ()=> {
5954 "host" : "server.cocreate.app:8088"
6055 } ;
6156
62- socket . create ( {
63- namespace : socket_config . config . organization_Id ,
64- room : null ,
65- host : socket_config . host
66- } )
57+ socket . create ( {
58+ namespace : socket_config . config . organization_Id ,
59+ room : null ,
60+ host : socket_config . host
61+ } )
6762
68-
69- let data2 = await crud . readDocumentList ( {
70- collection : "organizations" ,
71- operator : {
72- filters : [ {
73- name : 'domains' ,
74- operator : "$in" ,
75- value : [ hostname ]
76- } ] ,
77- // orders: [],
78- // startIndex: 0,
79- // search: { type: 'or', value: []}
80- } ,
81- is_collection : false ,
82- apiKey : config [ "config" ] [ "apiKey" ] ,
83- organization_id : config [ "config" ] [ "organization_id" ]
84- } ) ;
63+ let data2 = await crud . readDocumentList ( {
64+ collection : "organizations" ,
65+ operator : {
66+ filters : [ {
67+ name : 'domains' ,
68+ operator : "$in" ,
69+ value : [ hostname ]
70+ } ] ,
71+ } ,
72+ is_collection : false ,
73+ apiKey : config [ "config" ] [ "apiKey" ] ,
74+ organization_id : config [ "config" ] [ "organization_id" ]
75+ } ) ;
8576
8677 //let data2 = await crud.listenAsync(eventGetOrg);
8778 console . log ( "data2 ===" , data2 )
@@ -91,31 +82,31 @@ var api = ( ()=> {
9182 var socket_config = {
9283 "config" : {
9384 "apiKey" : org [ "apiKey" ] ,
94- // "securityKey": org["securityKey"],
9585 "organization_Id" : org [ "_id" ] . toString ( ) ,
9686 } ,
9787 "prefix" : "ws" ,
9888 "host" : "server.cocreate.app:8088"
9989 }
10090 //other connection
10191 socket . create ( {
102- namespace : socket_config . config . organization_Id ,
92+ namespace : socket_config . config . organization_Id ,
10393 room : null ,
10494 host : socket_config . host
10595 } )
96+
10697 // socket.setGlobalScope(socket_config.config.organization_id)
107- let myOrg = await crud . readDocumentList ( {
108- collection : "organizations" ,
109- operator : {
110- filters : [ {
111- name : '_id' ,
112- operator : "$eq" ,
113- value : [ org [ "_id" ] . toString ( ) ]
114- } ] ,
115- orders : [ ] ,
116- startIndex : 0 ,
117- search : { type : 'or' , value : [ ] }
118- } ,
98+ let myOrg = await crud . readDocumentList ( {
99+ collection : "organizations" ,
100+ operator : {
101+ filters : [ {
102+ name : '_id' ,
103+ operator : "$eq" ,
104+ value : [ org [ "_id" ] . toString ( ) ]
105+ } ] ,
106+ orders : [ ] ,
107+ startIndex : 0 ,
108+ search : { type : 'or' , value : [ ] }
109+ } ,
119110 is_collection : false ,
120111 apiKey : org [ "apiKey" ] ,
121112 organization_id : org [ "_id" ]
@@ -124,7 +115,7 @@ var api = ( ()=> {
124115 return result ;
125116 }
126117
127- } //
118+ }
128119} ) ( ) ;
129120
130121module . exports = api ;
0 commit comments