Hi Guys, Im trying to setup a database that allows me to send points between users within the database.
I can get it work with set values and deduct points for current user logged in however struggling to add points to the user being sent the points
I haven’t done coding for years so trying to find my feet
The page has a dropdown linked to a dataset and only shows current usernames with one selected by default
I have an input box for user to input points being sent which is used in code below
needless to say current code is not working - any help is welcome lol
import wixUsers from ‘wix-users’ ;
import wixData from ‘wix-data’ ;
let user = wixUsers . currentUser ;
let points = 0
let sentpoints = 0
let userEmail = “user email”
let user1 //to save user1 points
let user2 //to save points being sent to user2
$w . onReady ( function () {
user . getEmail ()
. then ( ( email ) => {
userEmail = email ; //get current user email who is logged in
} );
});
export function button8_click ( event ) {
wixData . get ( “www-points” , userEmail ) // Find current user who is logged in
. then ( ( results ) => {
let item = results ; //see item below
points = item . wwwpoints ; // capture current points
$w ( “#input3” ). value = points ; // show current points on a read only text box
user1 = item ; // store table for use later
console . log ( user1 );
} )
. catch ( ( err ) => {
let errorMsg = err ;
} );
let amount = 0
amount = Number ( $w ( “#input4” ). value ) // capture users input as the amount
if ( amount < 0 ) {
$w ( “#input5” ). value = “Cannot Be Approved” // avoid negative values
}
else {
if (points - amount < 0 ) { // If user does not have enough points
$w ( “#input5” ). value = “Not Enough Points”
}
else {
points = points - amount // deduct points from current user
$w ( “#input3” ). value = points ; //show current points for user
user1 . wwwpoints = points ; // update table with new points
wixData . update ( “www-points” , user1 ); // update database with new points
console . log ( user1 );
wixData . get ( “www-points” , $w ( “#dropdown1” ). value ) //dropdown only showing usernames via dataset to find user points being sent to
. then ( ( results ) => {
let item = results ; //see item below
sentpoints = item . wwwpoints ; //capture current points to use with sent points
user2 = item ; // save table for use later
console . log ( user2 );
} )
. catch ( ( err ) => {
let errorMsg = err ;
} );
sentpoints = sentpoints + amount ; // update sentpoints for user being sent points
user2 . wwwpoints = sentpoints; //update table with new points total for user
wixData . update ( “www-points” , user2 ); // update database with new points
console . log ( user2 );
$w ( “#input5” ). value = “Points Approved” //update textbox to show points worked
}
}
}