I am using wix code API to update the value in the database.
I am using modules / server-side to make the actual updates.
The code works properly when I am in Preview mode, it updates the Sandbox DB. But when I publish the site and go to the published page, the update to live DB doesn’t happen even though call to the backend module function seems to happen.
private.jsw
export function updateDownloadCount(itemId) {
let options = {
“suppressAuth”: true
};
var items;
let collectionName = “Downloadables”;
wixData.get(collectionName, itemId, options)
.then((results) => {
let item = results;
item[“downloadCount”] = (results[“downloadCount”] || 0) + 1;
return wixData.update(collectionName, item)
.then((updateResults) => {
let item2 = updateResults;
console.log("update results ", item2);
})
.catch((err) => {
let errorMsg = err;
});
})
.catch((err) => {
let errorMsg = err;
return errorMsg
});
return true;
}
frontend
export function button2_click(event, $w) {
updateDownloadCount(event.context.itemId).then(function(result) {
console.log(“result”, result);
})
.catch(error => {
console.log(“error is”, error);
});
}