mongoose + tests

This commit is contained in:
Primakov Alexandr Alexandrovich
2024-10-16 11:06:23 +03:00
parent 2cfcd7347b
commit 4b0d9b4dbc
1295 changed files with 4579 additions and 1719 deletions

View File

@@ -1,4 +1,4 @@
const express = require('express');
const express = require('express')
const plantsRouter = express.Router()
@@ -15,28 +15,28 @@ const plants = [
frequency: 3,
startDate: "2024-10-05",
},
];
]
const calculateWateringDates = (startDate, frequency) => {
const dates = [];
const start = new Date(startDate);
const dates = []
const start = new Date(startDate)
for (let i = 0; i < 30; i += frequency) {
const nextWateringDate = new Date(start);
nextWateringDate.setDate(start.getDate() + i);
dates.push(nextWateringDate.toISOString().split('T')[0]);
const nextWateringDate = new Date(start)
nextWateringDate.setDate(start.getDate() + i)
dates.push(nextWateringDate.toISOString().split('T')[0])
}
return dates;
};
return dates
}
const plantsWithDates = plants.map(plant => ({
...plant,
wateringDates: calculateWateringDates(plant.startDate, plant.frequency),
}));
}))
plantsRouter.get('/api/plants', (req, res) => {
res.json(plantsWithDates);
});
res.json(plantsWithDates)
})
module.exports = plantsRouter;
module.exports = plantsRouter