Hi,
When using HTTP requests, you should return a response and not a JSON object. For that purpose, you can use the OK response as explained here . Make sure to set the header response and an informative message so that you know if the object was updated or not:
import wixData from 'wix-data';
import {ok} from 'wix-http-functions';
export async function get_updateDonation(request) {
//query a collection to find matching items
//=========================================
let options = {
"headers": {
"Content-Type": "application/json"
}
};
// return ok(options);
if (request.path.length === 0) {
options.body = {
found: false,
message: 'No parameter given'
}
return ok(options);
}
const results = await wixData.query("Donations")
.eq("_id", request.path[0])
.find();
if (results.items.length > 0) {
//update donation
//===============
let toUpdate = {
"_id": request.path[0],
"name": results.items[0].name,
"phone": results.items[0].phone,
"email": results.items[0].email,
"country": results.items[0].country,
"address": results.items[0].address,
"swimmer": request.path[2],
"amount": request.path[4]
};
try {
let updated = await wixData.update("Donations", toUpdate);
options.body = {
updateResult: updated
}
} catch(err) {
options.body = {
updateResult: err
}
}
return ok(options);
}
options.body = {
found: false,
message: 'Item was not found'
}
return ok(options);
}
I hope it’s clearer now.
Best,
Tal.