Good day!
Why is the beforeSave being triggered twice whenever a transaction is made?
Moralis.Cloud.beforeSave("ItemsSold", async (request) => {
const query = new Moralis.Query("ItemsForSale");
query.equalTo("itemId", request.object.get('itemId'));
const item = await query.first();
if (item) {
request.object.set('item', item);
let x = Number(item.get("soldNFTs")) + Number(request.object.get('amount'))
item.set('soldNFTs', x.toString());
if (x.toString() === item.get("amount"))
item.set('sold', true);
await item.save();
}
});