What I’m trying to achieve is to increase the download counter of an object whenever a person presses the download button. I’m doing this as the database is set to be updated by the author only. Is my code wrong or we can’t save the database from the backend.
Any help is appreciated. Thank you.
Backend code:
import wixData from ‘wix-data’;
.
.
export function setDownloadCounter (downloadCounter, dynamicDataset, setField){
//to add one to the original value
let count = parseInt(downloadCounter.text, 10) + 1;
dynamicDataset.setFieldValue(setField, count);
dynamicDataset.save();
return count;
}
Front end code:
import { setDownloadCounter } from ‘backend/counters.jsw’
.
.
setDownloadCounter ($w(‘#downloadCounter’), $w(“#dynamicDataset”), “downloadCounter”)
.then ((count) => {
$w(‘#downloadCounter’).text = count.toString();
});