Hello. I have made a function in the backend which searches something in a collection and if it finds it, it returns another column of that row, just like this:
//BACKEND:
// Filename: backend/buscarSoci.jsw (web modules need to have a .jsw extension)
import wixData from 'wix-data';
export function buscaSociDni (dni){
wixData.query('Socios')
.contains('soc_dni', dni)
.find()
.then((results)=>{
if(results.items.length>0){
return results.items[0].soc_id
}
else{return 1}
})
.catch((error)=>{
return error
})
}
//FRONTEND:
import {buscaSociDni} from 'backend/buscarSoci.jsw'
$w.onReady(function () {
let dni = 'whatever DNI';
buscaSociDni(dni)
.then((results)=>{
console.log(results)
}
)
.catch((error)=>{
console.log(error.message)
})
});
If I do the query in the frontend, all works fine, but when I do it in the backend, the console shows undefined even though I set the variable dni to contain one which is in the collection.
Thanks in advance.