Hi All,
I have setup a remote update to a DB in Wix and it works great.
I have two minor issues:
- Each remote update is inserting a new line to the DB, while I only need an updated single entry.
- if I am sending a list of parameters, if any parameter is missing (intentionally) I get an empty value (again as in section 1, in another entry)
Is there a way to only have a single entry in the DB, and be able to update it with some (and not all) parameters while keeping the existing ones as is?
the current http-functions.js file:
import {ok, created, badRequest, notFound, serverError, response} from ‘wix-http-functions’;
import wixData from ‘wix-data’;
export function post_tabledata(request) {
let options = {
“headers”: {
“Content-Type”: “application/json”
}
};
return request.body.json()
.then( (body) => {
return createLine(body, options);
})
. catch ( (error) => {
options.body = {
“error”: error
};
return serverError(options);
});
}
function createLine(body, options) {
let dataInsert = {
“c1FirstLine”: body.c1FirstLine, //Challenge 1 First Line
“c2FirstLine”: body.c2FirstLine, //Challenge 2 First Line
“c3FirstLine”: body.c3FirstLine, //Challenge 3 First Line
“c1SecondLine”: body.c1SecondLine, //Challenge 1 Second Line
“c2SecondLine”: body.c2SecondLine, //Challenge 2 Second Line
“c3SecondLine”: body.c3SecondLine, //Challenge 3 Second Line
“c1ThirdLine”: body.c1ThirdLine, //Challenge 1 Third Line
“c2ThirdLine”: body.c2ThirdLine, //Challenge 2 Third Line
“c3ThirdLine”: body.c3ThirdLine, //Challenge 3 Third Line
“button1”: body.button1, //Challenge 1 button to OfficeGuy payment page
“button2”: body.button2, //Challenge 2 button to OfficeGuy payment page
“button3”: body.button3 //Challenge 3 button to OfficeGuy payment page
};
return wixData.insert(‘ChallengeDates’, dataInsert)
.then( (result) => {
let item = result;
options.body = {
“status”: 200,
“response”: item
};
return created(options);
});
}
Thanks a lot!
Lior