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
// I use passport as auth so req.user is set by it. | |
// Is this code feasible enough when the user has many farms with different crops, i.e when the user data grows | |
// As of now the code taken up to 1412 ms to complete | |
const { Farm } = require('../models/farm'); | |
getHistory = function(req, res, next) { | |
Farm.find().distinct('cropId', { userId: req.user._id }, (err, cropIds) => { | |
if (err) return res.send({ success: false, err }); | |
let i = 0; | |
let data = []; |