Created
July 7, 2016 06:53
-
-
Save josegl/e611d4742302cf0d2ffa9ff42182aee4 to your computer and use it in GitHub Desktop.
client route example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.get('/', (req, res) => { | |
if(req.user){ | |
if req.user.active){ | |
if(req.query.id){ | |
findById(req.query.id).then(fClient => { | |
if(fClient){ | |
res.json(fClient); | |
} else { | |
res.json({}); | |
} | |
}); | |
} | |
if(req.query.ids){ | |
const query = composeQuery(req.query.ids); | |
find(query).then(fClients => { | |
if(fClients){ | |
res.json(fClients); | |
} else { | |
res.json({}); | |
} | |
}); | |
} | |
if(req.query.phones){ | |
const {phones, dealer_id } = req.query; | |
runGenerator(findClientsWithPhones, phones, dealer_id, req, res); | |
} | |
if(req.query.phones && req.query.emails){ | |
//Do something with both ('or' query, 'and' query, something little bit more complex?) | |
//Should I put something like req.query.queryType = or, and ? If so, I will need even more ifs. | |
// Each time I need a different data set, I will need to add a new if branch | |
// pros: I have a fixed data sets I can serve. | |
// cons: I think that this doesn't scale as it should. | |
} | |
} else { | |
res.status(401).send({error: 'Your account is not active. Contact with your admin'}); | |
} | |
} else { | |
res.status(401).send({error: 'Unauthorized'}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment