-
Notifications
You must be signed in to change notification settings - Fork 15
/
cloudcode.js
35 lines (28 loc) · 936 Bytes
/
cloudcode.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Moralis.Cloud.define("updateMyList", async (request) => {
const addrs = request.params.addrs;
const newFav = request.params.newFav;
const user = Moralis.Object.extend("_User");
const query = new Moralis.Query(user);
query.equalTo("ethAddress", addrs);
const data = await query.first({ useMasterKey: true });
if (data.attributes.myList) {
const { myList } = data.attributes;
myList.push(newFav);
data.set("myList", myList);
} else {
data.set("myList", [newFav]);
}
await data.save(null, { useMasterKey: true });
});
Moralis.Cloud.define("getMyList", async (request) => {
const addrs = request.params.addrs;
const user = Moralis.Object.extend("_User");
const query = new Moralis.Query(user);
query.equalTo("ethAddress", addrs);
const data = await query.first({ useMasterKey: true });
if (data.attributes.myList) {
return data.attributes.myList;
} else {
return [];
}
});