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

153
Views
Cómo expandir de manera sensata y eficiente una función sin repeticiones interminables

Estoy tratando de expandir esta función para cubrir a todos nuestros diez empleados, pero me doy cuenta de que lo estoy haciendo estúpidamente. Curiosamente (¡para mí!), el código me permite copiar y pegar consultas adicionales solo una vez, es decir, para Dave, pero si vuelvo a copiar el bloque de código, aparece "TypeError: Cannot set property 'lazy_count' of undefined". Simplemente me faltan las habilidades de programación para manejar esto correctamente con consultas mínimas de db. Cualquier ayuda muy apreciada.

 var clockedIn = false; db.query('SELECT FIRST 1 * FROM ATTENDEVENTS WHERE OPID = 6 ORDER BY DATETIME DESC', function(err, ci_row) { if (err) throw err; if (ci_row.length === 1 && ci_row[0].EVENTTYPE === 0) clockedIn = true; if (!clockedIn) { db.query('SELECT opid, name FROM OPS WHERE OPID = 6', function(err, rows) { if (rows.length === 0) { console.log('error 1') } db.query('SELECT FIRST 1 OPID FROM ATTENDEVENTS WHERE OPID = 6 ORDER BY DATETIME DESC', function(err, rows) { if (err) throw err; if (rows.length === 1 && rows[0].EVENTTYPE == 0) { console.log('error 2') } else { db.query('SELECT FIRST 1 ATTENDEVENTID FROM ATTENDEVENTS ORDER BY DATETIME DESC', function(err, rows) { lastID = 0; if (rows.length === 1) { lastID = rows[0].ATTENDEVENTID; } console.log('George is not clocked in') }); } }); }); } if (clockedIn) { console.log('George is clocked in') } }) var bclockedIn = false; db.query('SELECT FIRST 1 * FROM ATTENDEVENTS WHERE OPID = 3 ORDER BY DATETIME DESC', function(err, dave_row) { if (err) throw err; if (dave_row.length === 1 && dave_row[0].EVENTTYPE === 0) bclockedIn = true; if (!bclockedIn) { db.query('SELECT opid, name FROM OPS WHERE OPID = 3', function(err, daverows) { if (daverows.length === 0) { console.log('error 1') } db.query('SELECT FIRST 1 OPID FROM ATTENDEVENTS WHERE OPID = 3 ORDER BY DATETIME DESC', function(err, daverows) { if (err) throw err; if (daverows.length === 1 && daverows[0].EVENTTYPE == 0) { console.log('error 2') } else { db.query('SELECT FIRST 1 ATTENDEVENTID FROM ATTENDEVENTS ORDER BY DATETIME DESC', function(err, daverows) { lastID = 0; if (daverows.length === 1) { lastID = daverows[0].ATTENDEVENTID; } console.log('Dave is not clocked in') }); } }); }); } if (bclockedIn) { console.log('Dave is clocked in') } })
about 4 years ago · Juan Pablo Isaza
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!