Advertisement
Guest User

Untitled

a guest
Jul 25th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. const find = (db, collectionName, conditions) => {
  2. const collection = db.collection(collectionName)
  3. const cursor = collection.find(conditions)
  4. const documents = []
  5.  
  6. return new Promise((resolve, reject) => {
  7. cursor.forEach(
  8. (doc) => documents.push(doc),
  9. () => resolve(documents)
  10. )
  11. })
  12. }
  13.  
  14. app.get('/operacoes', async (req, res) => {
  15. let conditions = {}
  16. let titulo = "Gerais"
  17. const { filtro } = req.query
  18. if (filtro) {
  19. switch (filtro) {
  20. case 'entradas':
  21. titulo = " de Entrada"
  22. conditions = {
  23. valor: { $gte: 0 }
  24. }
  25. break
  26. case 'saidas':
  27. titulo = " de Saída"
  28. conditions = {
  29. valor: { $lt: 0 }
  30. }
  31. break
  32. default:
  33. break
  34. }
  35. }
  36. const operacoes = await find(app.db, 'operacoes', conditions)
  37. res.render('operacoes', { titulo: titulo, operacoes })
  38. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement