hello guys am building a restAPI with express, node and firebase cloud function and it's returning the documents from my collection successfully. But my problem is am returning the date each document was created as JSON but am unable to convert the timestamp date to javascript date..... here is my code for clearity:
// Single report route that accepts a report ID and return the report
app.get('/report/:id', async (req, res) => {
try {
let report;
const reportDoc = await admin.firestore().collection('corruptionReports/').doc(req.params.id).get();
if (reportDoc.exists) {
let reportDate = reportDoc.data().createdAt;
report = {
id: reportDoc.id,
createdAt: reportDate.toMillis(),
...reportDoc.data()
}
return res.status(200).json(report)
} else {
return res.status(500).json({
"status": "failed",
"message": "invalid report ID"
})
}
} catch (error) {
return res.status(500).json({
"status": "failed",
"message": "invalid report ID"
})
}
})
with the code above I basically want to return the document with the server TimeStamp in milliseconds.