Here is my code :
// Backend: backend/Quote-module.jsw
import {created, serverError} from ‘wix-http-functions’ ;
import wixData from ‘wix-data’ ;
export function post_storerecords(request) { // POST = Method
let options = {
“headers” : {
“Content-Type” : “application/json”
}
};
return request.body.json()
.then(body => {
let recordInsert = {
“firstName” : body.firstName,
“lastName” : body.lastName,
“email” : body.source,
“phone” : body.phone,
“totalEmployees” : body.totalEmployees,
“miniPerMonthPerEmployeeWithoutTax” : body.miniPerMonthPerEmployeeWithoutTax,
“miniPerMonthPerEmployeeWithTax” : body.miniPerMonthPerEmployeeWithTax,
“miniAllEmployeesPerYearWithTax” : body.miniAllEmployeesPerYearWithTax,
“midiPerMonthPerEmployeeWithoutTax” : body.midiPerMonthPerEmployeeWithoutTax,
“midiPerMonthPerEmployeeWithTax” : body.midiPerMonthPerEmployeeWithTax,
“midiAllEmployeesPerYearWithTax” : body.midiAllEmployeesPerYearWithTax,
“maxiPerMonthPerEmployeeWithoutTax” : body.maxiPerMonthPerEmployeeWithoutTax,
“maxiPerMonthPerEmployeeWithTax” : body.maxiPerMonthPerEmployeeWithTax,
“maxiAllEmployeesPerYearWithTax” : body.maxiAllEmployeesPerYearWithTax,
“ultimatePerMonthPerEmployeeWithoutTax” : body.ultimatePerMonthPerEmployeeWithoutTax,
“ultimatePerMonthPerEmployeeWithTax” : body.ultimatePerMonthPerEmployeeWithTax,
“ultimateAllEmployeesPerYearWithTax” : body.ultimateAllEmployeesPerYearWithTax,
};
// insert the item in a collection
return wixData.insert( “GetaQuote” , JSON.parse(body));
} )
.then( (results) => {
options.body = {
“inserted” : results
};
return created(options);
} )
// error handling
. catch ( (error) => {
options.body = {
“error” : error
};
return serverError(options);
} );
}