Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const find = (db, collectionName, conditions) => {
- const collection = db.collection(collectionName)
- const cursor = collection.find(conditions)
- const documents = []
- return new Promise((resolve, reject) => {
- cursor.forEach(
- (doc) => documents.push(doc),
- () => resolve(documents)
- )
- })
- }
- app.get('/operacoes', async (req, res) => {
- let conditions = {}
- let titulo = "Gerais"
- const { filtro } = req.query
- if (filtro) {
- switch (filtro) {
- case 'entradas':
- titulo = " de Entrada"
- conditions = {
- valor: { $gte: 0 }
- }
- break
- case 'saidas':
- titulo = " de Saída"
- conditions = {
- valor: { $lt: 0 }
- }
- break
- default:
- break
- }
- }
- const operacoes = await find(app.db, 'operacoes', conditions)
- res.render('operacoes', { titulo: titulo, operacoes })
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement