Skip to content

Commit 4e2b817

Browse files
committed
fix: update crud functions to receive an array of objects as the response
1 parent 91a389a commit 4e2b817

File tree

2 files changed

+23
-21
lines changed

2 files changed

+23
-21
lines changed

demo/index.html

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,10 @@ <h1>Form Demo</h1>
4242
</form>
4343

4444
<h1>Result</h1>
45-
46-
<script>
47-
var CoCreateConfig = {
48-
apiKey: 'c2b08663-06e3-440c-ef6f-13978b42883a',
49-
organization_id: '5de0387b12e200ea63204d6c'
50-
}
51-
52-
</script>
53-
45+
5446
<!--CoCreateJS CDN-->
55-
<script src="https://cdn.cocreate.app/api/latest/CoCreate-api.min.js"></script>
47+
<!-- <script src="https://cdn.cocreate.app/api/latest/CoCreate-api.min.js"></script> -->
48+
<script src="../dist/CoCreate-api.js"></script>
5649

5750
</body>
5851
</html>

src/server.js

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1-
const crud = require('@cocreate/crud-client')
1+
const CRUD = require('@cocreate/crud-client')
22
const socketClient = require('@cocreate/socket-client')
33
let socket = new socketClient("ws");
44

5+
let crud
6+
if(CRUD && CRUD.default)
7+
crud = CRUD.default
8+
else
9+
crud = CRUD
10+
511
crud.setSocket(socket);
612

713
var 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

Comments
 (0)