Hi, in Video 8 of âI cloned Raribleâ a cloudfile with some server code is defined. I am using âmoralis-admin-cli watch-cloud-fileâ to upload the cloudFile with the code whenever I make changes. And it works fine for the code below. In my browser I get back the âqueryResultsâ, BUT: For some reason if I enable the code below that is commented out now (and comment out the line âreturn queryResults;â), then I always get back from server the error that the function âgetUserItemsâ is not defined as a cloud function. If I redo the described changes it works fine again. Do you know what is wrong with my code below?
Moralis.Cloud.define("getUserItems", async (request) => {
const query = new Moralis.Query("EthNFTOwnersPending");
query.equalTo("contract_type", "ERC721");
query.containedIn("owner_of", request.user.attributes.accounts);
const queryResults = await query.find();
return queryResults;
//const results = [];
//for (let i = 0; i < queryResults.length; ++i) {
//results.push((
// "id": queryResults[i].id,
// "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;
});
So, if I use the following code instead, I get the error:
moralis.js:21595 POST https://luoljbifa2qa.moralis.io:2053/server/functions/getUserItems 400 (Bad Request)
dispatch @ moralis.js:21595
ajax @ moralis.js:21602
(anonymous) @ moralis.js:21706
Promise.then (async)
request @ moralis.js:21700
run @ moralis.js:427
run @ moralis.js:353
loadUserItems @ main.js:183
init @ main.js:25
async function (async)
init @ main.js:13
(anonymous) @ main.js:236
moralis.js:23696 Uncaught (in promise) Error: Invalid function: âgetUserItemsâ
at handleError (moralis.js:21728)
at async loadUserItems (main.js:183)
Here is the code that does not work and results in the error.
Moralis.Cloud.define("getUserItems", async (request) => {
const query = new Moralis.Query("EthNFTOwnersPending");
query.equalTo("contract_type", "ERC721");
query.containedIn("owner_of", request.user.attributes.accounts);
const queryResults = await query.find();
//return queryResults;
const results = [];
for (let i = 0; i < queryResults.length; ++i) {
results.push((
"id": queryResults[i].id,
"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;
});