const modifyTimestamp = async (request, response) => {
try {
const { user: userid } = request;
if (!ObjectId.isValid(userid)) throw new Error('invalid objectid');
const now = moment().format();
const date = new Date(now);
const result = await Allocation.findOne({ $and: [{ user: userid, start_date: { $lt: date }, end_date: { $gt: date } }] })
.populate('user', 'name')
.populate('garden');
if (!result) throw new Error('invalid request');
result.timestamp = moment(result.end_date).format('x');
response.status(200).send(result);
} catch (error) {
response.status(400).send(error);
}
};
I've encountered an issue where the timestamp is not added to the returned object from the MongoDB query. Even when trying to log the timestamp value, it doesn't appear. It seems like JavaScript is disregarding my assignment. I experimented with changing from const to let but that didn't solve the problem.