cloudfunction:
Moralis.Cloud.define("WordRegistration", async (request) => {
const Words = Moralis.Object.extend("Words");
const query = new Moralis.Query(Words);
query.equalTo("name", request.params.word);
const wordToChange = await query.first();
if (wordToChange) {
let number = wordToChange.get("number");
wordToChange.set("number", number + 1);
await wordToChange.save(null, { useMasterKey: true });
}
else {
let wordToAdd = new Words();
wordToAdd.set("name", params["word"]);
wordToAdd.set("number", 1);
await wordToAdd.save(null, { useMasterKey: true });
}
});
call function:
async function wordRegistration() {
const urlData = new URLSearchParams(window.location.search);
let urlParams = {};
urlData.forEach((p, key) => { urlParams[key] = p; });
if (!isUndefined(urlParams["word"])) {
userWord = urlParams["word"];
const params = {"word": userWord};
console.log(params);
const wordRegistr = await Moralis.Cloud.run("WordRegistration", params);
console.log(wordRegistr);
};
}
where I have a mistake?