Skip to content

Instantly share code, notes, and snippets.

@dougluce
Last active October 25, 2015 06:50
Show Gist options
  • Save dougluce/05146dc189ec6636a477 to your computer and use it in GitHub Desktop.
Save dougluce/05146dc189ec6636a477 to your computer and use it in GitHub Desktop.
if req.params.code
err, result <- dbconn.query QUERY
org = result.rows[0].id
else
org = 1
... use org somewhere ...
checkcode = (req, cb) ->
if req.params.code
err, result <- dbconn.query QUERY
cb result.rows[0].id
else
cb 1
mainfunc = req ->
org <- checkcode
... use org somewhere ...
@homam
Copy link

homam commented Oct 25, 2015

you need to handle the error too:

checkcode = (req, cb) ->
  if req.params.code
    err, result <- dbconn.query QUERY
    return cb err if !!err
    cb null, result.rows[0].id
  else
    cb null, 1

err, org <- checknode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment