@@ -4,106 +4,106 @@ let socket = new socketClient("ws");
44
55crud . setSocket ( socket ) ;
66
7- var api = ( ( ) => {
8- return {
9- send_response : ( wsManager , socket , obj , send_response ) => {
10- wsManager . send ( socket , send_response , obj )
11- } ,
12-
13- handleError : ( wsManager , socket , action , error , component ) => {
14- const response = {
15- 'object' : 'error' ,
16- 'data' :error || error . response || error . response . data || error . response . body || error . message || error ,
17- } ;
18- wsManager . send ( socket , component , { action, response } )
19- } ,
20-
21- getOrg : async ( config , component ) => {
22-
23- socket . create ( {
24- namespace : config [ "organization_id" ] ,
25- room : null ,
26- host : config [ "host" ]
27- } )
28-
29- let org = await crud . readDocument ( {
30- collection : "organizations" ,
31- key : config [ "key" ] ,
32- organization_id : config [ "organization_id" ] ,
33- document : {
34- _id : config [ "organization_id" ]
35- }
36-
37- } ) ;
38-
39- if ( ! org || ! org . document && ! org . document [ 0 ] ) {
40- console . log ( component , " Error GET ORG in : " , e ) ;
41- return false ;
42- }
43-
44- return org . document [ 0 ] ;
45- } ,
46-
47- getOrgInRoutesbyHostname : async ( config , hostname ) => {
48- var socket_config = {
49- "config" : {
50- "key" : config [ "config" ] [ "key" ] ,
51- "organization_id" : config [ "config" ] [ "organization_id" ] ,
52- } ,
53- "prefix" : "ws" ,
54- "host" : "server.cocreate.app:8088"
55- } ;
56-
57- socket . create ( {
58- namespace : socket_config . config . organization_id ,
59- room : null ,
60- host : socket_config . host
61- } )
62-
63- let data2 = await crud . readDocument ( {
64- collection : "organizations" ,
65- filter : {
66- query : [ {
67- name : 'domains ' ,
68- operator : "$in" ,
69- value : [ hostname ]
70- } ] ,
71- } ,
72- key : config [ "config" ] [ "key" ] ,
73- organization_id : config [ "config" ] [ "organization_id" ]
74- } ) ;
75-
76- var org = data2 . document [ 0 ]
77-
78- var socket_config = {
79- "config" : {
80- "key" : org [ "key" ] ,
81- "organization_id" : org [ "_id" ] . toString ( ) ,
82- } ,
83- "prefix" : "ws" ,
84- "host" : "server.cocreate.app:8088"
85- }
86-
87- //other connection
88- socket . create ( {
89- namespace : socket_config . config . organization_id ,
90- room : null ,
91- host : socket_config . host
92- } )
93-
94- let myOrg = await crud . readDocument ( {
95- collection : "organizations" ,
96- key : org [ "key" ] ,
97- organization_id : org [ "_id" ] ,
98- document : {
99- _id : org [ "_id" ]
100- }
101- } ) ;
102- let result = { 'row' :myOrg , 'socket_config' :socket_config } ;
103- return result ;
104- }
105-
106- }
7+ var api = ( ( ) => {
8+ return {
9+ send_response : ( wsManager , socket , obj , send_response ) => {
10+ wsManager . send ( socket , send_response , obj )
11+ } ,
12+
13+ handleError : ( wsManager , socket , action , error , component ) => {
14+ const response = {
15+ 'object' : 'error' ,
16+ 'data' : error || error . response || error . response . data || error . response . body || error . message || error ,
17+ } ;
18+ wsManager . send ( socket , component , { action, response } )
19+ } ,
20+
21+ getOrg : async ( config , component ) => {
22+
23+ socket . create ( {
24+ namespace : config [ "organization_id" ] ,
25+ room : null ,
26+ host : config [ "host" ]
27+ } )
28+
29+ let org = await crud . readDocument ( {
30+ collection : "organizations" ,
31+ key : config [ "key" ] ,
32+ organization_id : config [ "organization_id" ] ,
33+ document : {
34+ _id : config [ "organization_id" ]
35+ }
36+
37+ } ) ;
38+
39+ if ( ! org || ! org . document && ! org . document [ 0 ] ) {
40+ console . log ( component , " Error GET ORG in : " , e ) ;
41+ return false ;
42+ }
43+
44+ return org . document [ 0 ] ;
45+ } ,
46+
47+ getOrgInRoutesbyHostname : async ( config , hostname ) => {
48+ var socket_config = {
49+ "config" : {
50+ "key" : config [ "config" ] [ "key" ] ,
51+ "organization_id" : config [ "config" ] [ "organization_id" ] ,
52+ } ,
53+ "prefix" : "ws" ,
54+ "host" : "server.cocreate.app:8088"
55+ } ;
56+
57+ socket . create ( {
58+ namespace : socket_config . config . organization_id ,
59+ room : null ,
60+ host : socket_config . host
61+ } )
62+
63+ let data2 = await crud . readDocument ( {
64+ collection : "organizations" ,
65+ filter : {
66+ query : [ {
67+ name : 'hosts ' ,
68+ operator : "$in" ,
69+ value : [ hostname ]
70+ } ] ,
71+ } ,
72+ key : config [ "config" ] [ "key" ] ,
73+ organization_id : config [ "config" ] [ "organization_id" ]
74+ } ) ;
75+
76+ var org = data2 . document [ 0 ]
77+
78+ var socket_config = {
79+ "config" : {
80+ "key" : org [ "key" ] ,
81+ "organization_id" : org [ "_id" ] . toString ( ) ,
82+ } ,
83+ "prefix" : "ws" ,
84+ "host" : "server.cocreate.app:8088"
85+ }
86+
87+ //other connection
88+ socket . create ( {
89+ namespace : socket_config . config . organization_id ,
90+ room : null ,
91+ host : socket_config . host
92+ } )
93+
94+ let myOrg = await crud . readDocument ( {
95+ collection : "organizations" ,
96+ key : org [ "key" ] ,
97+ organization_id : org [ "_id" ] ,
98+ document : {
99+ _id : org [ "_id" ]
100+ }
101+ } ) ;
102+ let result = { 'row' : myOrg , 'socket_config' : socket_config } ;
103+ return result ;
104+ }
105+
106+ }
107107} ) ( ) ;
108108
109109module . exports = api ;
0 commit comments