updating price update logic

This commit is contained in:
sairaj mote 2024-01-12 01:14:35 +05:30
parent df8cb9c189
commit 794ba968c6
3 changed files with 6 additions and 13 deletions

View File

@ -168,22 +168,15 @@ function loadHistoricToDb() {
inr: parseFloat(parseFloat(close2).toFixed(2)),
});
}
// update many
await PriceHistory.deleteMany({ asset: 'btc' });
await PriceHistory.insertMany(priceHistoryData);
})
.catch((err) => {
console.log(err);
})
}
// run loadHistoricToDb() only once when the server starts and no data is present in the database
PriceHistory.countDocuments()
.then((count) => {
if (count === 0) {
loadHistoricToDb();
}
})
.catch((err) => {
console.log(err);
})
loadHistoricToDb();
app.get("/price-history", async (req, res) => {
try {
@ -240,7 +233,7 @@ app.post("/price-history", async (req, res) => {
app.listen(PORT, HOST, () => {
console.log(`Listening on ${HOST}:${PORT}`);
});
cron.schedule('0 12 * * *', async () => {
cron.schedule('0 */4 * * *', async () => {
try {
// will return a csv file
const [usd, inr] = await Promise.all([

2
index.min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -2,7 +2,7 @@ GET http://localhost:3000/
###
GET http://localhost:3000/price-history?limit=10
GET http://localhost:3000/price-history?from=2024-01-12
###
POST http://localhost:3000/price-history