When I leave the cloud function of getInventory only it is working fine, but when I had the other 2 before save it is saying invalid function getInventory
my cloud function:
Moralis.Cloud.define("getInventory", async (request) => {
const query = new Moralis.Query("EthNFTOwners");
query.equalTo("contract_type", "ERC721");
query.containedIn("owner_of", request.user.attributes.accounts);
const queryResults = await query.find();
const results = [];
for (let i = 0; i < queryResults.length; ++i) {
results.push({
"id" : queryResults[i].attributes.objectId,
"tokenId" : queryResults[i].attributes.token_id,
"tokenAddress" : queryResults[i].attributes.token_address,
"symbol" : queryResults[i].attributes.symbol,
"tokenUri" : queryResults[i].attributes.token_uri
});
}
return results;
});
Moralis.Cloud.beforeSave("ItemsForSale", async (request) => {
const query = new Moralis.Query("EthNFTOwners");
query.equalTo("token_address", request.object.get('tokenAddress'));
query.equalTo("token_id", request.object.get('tokenId');
const object = await query.first();
if(object){
const owner = object.attributes.owner_of;
const userQuery = new Moralis.Query(Moralis.User);
userQuery.equalTo("accounts", owner);
const userObject = await userQuery.first({useMasterKey:true});
if(userObject){
request.object.set('user', userObject);
}
request.object.set('token', object);
}
});
Moralis.Cloud.beforeSave("SoldItems", async (request) => {
const query = new Moralis.Query("ItemsForSale");
query.equalTo("uid", request.object.get('uid'));
const item = await query.first();
if(item){
request.object.set('item', item);
item.set('isSold', true);
await item.save();
const userQuery = new Moralis.Query(Moralis.user);
userQuery.equalTo("accounts", request.object.get('buyer'));
const userObject = await userQuery.first({useMasterKey:true});
if(userObject){
request.object.set('user', userObject);
}
}
});
my main.js:
loadUserInventory = async () => {
const ownedItems = await Moralis.Cloud.run("getInventory");
console.log("INVENTORY", ownedItems);
ownedItems.forEach(item =>{
getAndRenderItemData(item,renderUserItem);
})
}