Hi there!
I'm creating a wixData.query based on a string called as stringValue and the stringValue is the partner of the title. After I want to sort the results based on the 'value' field in the database. My code looks like this:
wixData.query("Products") .contains("title", request.path[0]) .or( wixData.query("Products") .eq("partner", request.path[0]) ) .ascending("value") .find()
Why does this give no results?
Thanks in advance!
It's not a router, it is a http function. Here my full code:
export function get_searchProductsByKeyword(request) { let options = { "headers": { "Content-Type": "application/json", "Access-Control-Allow-Origin": origin } }; if (request.path[1] === "ascending") { return wixData.query("Products") .contains("title", request.path[0]) .or( wixData.query("Products") .eq("partner", request.path[0]) ) .ascending("value") .find() .then( (results) => { // matching items were found if(results.items.length > 0) { options.body = { "items": results.items }; return ok(options); } // no matching items found options.body = { "error": `'${request.path[0]} ${request.path[1]}' was not found` }; return notFound(options); } ) // something went wrong .catch( (error) => { options.body = { "error": error }; return serverError(options); } ); } else { return wixData.query("Products") .contains("title", request.path[0]) .or( wixData.query("Products") .eq("partner", request.path[0]) ) .descending("value") .find() .then( (results) => { // matching items were found if(results.items.length > 0) { options.body = { "items": results.items }; return ok(options); } // no matching items found options.body = { "error": `'${request.path[0]} ${request.path[1]}' was not found` }; return notFound(options); } ) // something went wrong .catch( (error) => { options.body = { "error": error }; return serverError(options); } ); } }
Hi Quin 🖐
Can you please share the complete code? Does this code reside inside the routers.js file on the backend?
const query = wixData.query("Products").ascending("value"); const pathValue = request.path[0]; return query.contains('title', pathValue).or(query.eq('partner', pathValue)).find()