After clicking submit button, it will check if the record is exist on the database, if exist it will return true, the problem here is I dont know how to return true
//button click
if(_data.hasExistingEvent(_data.getFormData())){ ==> this will check if true or false
///if true
}else{
}
I don't have problem on my query but I just want that if the form exist on the database it will return true and if not it will return false
....
hasExistingEvent: (data) => {
var { assignedTo, startDate } = data
var s = moment(startDate, 'DD/MM/YYYY hh:mm A').toDate()
var newDate = moment(s).format("YYYY-MM-DD HH:mm")
return new Promise((resolve, reject) => {
....("SELECT assignedTo, startDate FROM Event WHERE assignedTo LIKE '%" + assignedTo + "%' AND startDate BETWEEN '" + moment(newDate).startOf(`day`).format() + "' AND '" + moment(newDate).endOf(`day`).format() + "'", 100, function(a){
var valid = false;
return valid = resolve(a.length == 0) // here
})
})
},
Here you are returning a variable assignation with the = operator. Returning valid = resolve(a.length == 0) does not make any sense since you are assigning the result of resolve(a.length == 0) to the variable valid.
If you want to check for equality, use === or ==.
The first possibility here is to do:
var valid = false;
return valid === resolve(a.length == 0)
Or, for a more concise code, just get rid of the valid variable and return:
return !resolve(a.length ==0)