I’m using this cloud function to change users’ role.
Moralis.Cloud.define("changeRole", async (request) => {
//get Role
const query = new Moralis.Query(Moralis.Role);
const roleResults = await query.find({useMasterKey:true});
//get User
const userQuery = new Moralis.Query(Moralis.User);
query.equalTo("ethAddress", request.params.newUser);
const userResult = await query.first({useMasterKey:true});
for(let i=0; i<roleResults.length; i++){
if(roleResults[i].get('name')===request.params.roleName){
roleResults[i].getUsers().add(userResult)
}
roleResults.save()
{
return request.params.roleName;
});
Now I’m getting this:
Invalid function: “changeRole”
moralis.js:26242 POST https://v8nqcujntcni.usemoralis.com:2053/server/functions/changeRole 400