If you want to learn, than YouTube is a good idea, and also take a look at all the example-tutorials on my site.
You will also find links to other EXPERTS like QC-Nayeli on my site.
There is so much stuff from which you can learn.
What you could already do by yourself is to prepare the code, that is all i expected from you, like this… (deleting all unnessasery code-parts, and give some structure to it…)
import wixUsers from 'wix-users';
$w.onReady(function () { });
let user = wixUsers.currentUser;
let userId = user.id;
let isLoggedIn = user.loggedIn
user.getEmail()
.then( (email) => {
let userEmail = email;
});
wixData.query("DATABASENAME")
.eq("COLUMN-ID", userEmail)
.find()
.then( (results) => {
if(results.items.length > 0) {
let firstItem = results.items[0]; //see item below
} else {
//....do here your substruction
let myNewPointValue = results.items[0].points-1
console.log(myNewPointValue)
}
} )
.catch( (err) => {
let errorMsg = err;
});
This was it already. Prepared code to work with.
Now putting the 2 parts together and creating of it a function…(CODE-IMPROVEMENT)
import wixUsers from 'wix-users';
import wixData from 'wix-data';
$w.onReady(function () { myFunction() }); // This will start your function ---> "myFunction"
async function myFunction (parameter) {console.log("myFunction-started")
//PART-I ----> GETTING USER-DETAILS WHO IS LOGGED IN.
let user = await wixUsers.currentUser;
let userId = await user.id;
let isLoggedIn = await user.loggedIn
await user.getEmail()
.then(async (email) => {
let userEmail = await email;
// PART-II ---> GETTING DATA-QUERY OF YOUR DATABASE.
wixData.query("DATABASENAME")
.eq("COLUMN-ID", userEmail)
.find()
.then( (results) => {
if(results.items.length > 0) {
let firstItem = results.items[0]; //see item below
} else {
//....do here your substruction
let myNewPointValue = results.items[0].points-1
console.log(myNewPointValue)
}
} )
.catch( (err) => {
let errorMsg = err;
});
});
}
That looks already better right?
Inserted some ASYNC-AWAIT in the first part, because the second part should not start before first part of code is done.
But STOP, wait! You still know what you want to do ???
Yes you want first to get the —> eMail of the logged in User right?
And then ?
Right! Then you filter your DATABASE by this eMail to find the right logged in USER (You could also use the USER-ID for that).
In this example i just will do it with the eMail.
- Got your eMail
- putted in into the filter
- Filtered your database by this founded eMail
- Found the right row in the right column —> Found your ITEM
- Now replace/change vlaue of that founded ITEM.
Replace in the code “COLUMN-ID”, by your own column-ID.
When i take a look at the bad-quality-pic you gave, i can recognize thet the related colum-ID is —> “email” ,right?
.eq("COLUMN-ID", userEmail)
changing to …
.eq("email", userEmail)
Now the code would search in the right column -->“email” for the value ----> “userEmail” and you get a RESULT after the filtering-process is done.
.then( (results) => { ....here all the results of the filter... }
Now try to understand till here. You are still not done with this code. It has still to be EXPANDED.
What does this code already?
Which part of code is still missing?
What has to be implemented into this code to solve your issue completely?
EDIT:
And of course do not forget to change the DATABASE-NAME…
wixData.query("DATABASENAME")
…to…your own one…
wixData.query("upload")
All is done by theoretical thoughts, i did not test it, so it could still be buggy.
But when you understand what you are doing, then you should be able to DEBUG all little errors & code-bugs.