@shantanukumar847 There you go:
import {created, serverError} from 'wix-http-functions';
import wixData from 'wix-data';
export function post_addUserLeaderboard(request) {
console.log("hey");
let options = {
"headers": {
"Content-Type": "application/json"
}
};
// get the request body
return request.body.json()
.then( (body) => {
console.log(body);
// insert the item in a collection
let leaderboardEntry = {
"title": body.title,
"score": body.score
}
return wixData.insert("fastLifeLeaderboard", leaderboardEntry);
} )
.then( (results) => {
options.body = {
"inserted": results
};
return created(options);
} )
// something went wrong
.catch( (error) => {
options.body = {
"error": error
};
return serverError(options);
} );
}