Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

62
Views
Javascript return true if the record is exist on the database

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
        })
    })
},
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

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)
about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!