I’m using this cloud function to set new parameters in DB
Moralis.Cloud.afterSave("minted", async (request) => {
const logger = Moralis.Cloud.getLogger();
logger.info("running afterSave -> minted")
const query = new Moralis.Query("minted", {useMasterKey: true});
query.equalTo("tokenId", request.object.get('tokenId'), { useMasterKey: true });
const item = await query.first({useMasterKey: true});
const itemObj = JSON.parse(JSON.stringify(item))
if (item && typeof itemObj.attempt === "undefined") {
const httpResponse = await Moralis.Cloud.httpRequest({
"url": `${itemObj.uri}`,
"headers": {
'method': 'GET',
'accept': 'application/json'
}
})
const result = httpResponse.data;
request.object.set('item', item, {useMasterKey: true});
item.set('guessed', false);
item.set('attempt', 0); //Number.isInteger(item.attempt) ? item.attempt + 1 : 0
if (result) {
item.set('img', result.image);
item.set('wordbroken', result.words);
item.set('prize', result.prize);
item.set('attempt_price', result.attemptCost);
}
await item.save(null, {useMasterKey: true});
}
});
It works fine, but I cannot set the CLP of the Role class to anything less than Public write, which makes no sense.
It’s because the item.save() function has no access and doesn’t work with { useMasterKey: true } to override the CLP.
Am I using the wrong approach?