Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 4x 4x 4x 3x 2x 2x 2x 1x 1x | import StatisticsController from "../../controllers/statistics-controllers/StatisticsController.js";
import asyncRouteHandler from "../../utilities/asyncRouteHandler.js";
import { getCurrentDate } from "../../utilities/dateMaker.js";
import ErrorGenerator from "../../utilities/ErrorGenerator.js";
export default asyncRouteHandler(
async function statistics_setMonthTarget_get(req, res, next) {
const { year, monthIndex, newTarget } = req.body;
const currentDate = getCurrentDate();
if (!isNaN(+year) && !isNaN(+monthIndex)) {
// if the given month is future or current month
if (currentDate.year <= +year && (currentDate.monthIndex <= +monthIndex || currentDate.year < +year)) {
if (!isNaN(+newTarget)) {
const response = await StatisticsController.setMonthTarget({ year, monthIndex, newTarget });
res.status(response === undefined ? 400 : 200).json(response);
} else E{
next(new ErrorGenerator("Invalid Target", 400));
}
} else {
next(new ErrorGenerator("Can't set a target for a passed month", 400));
}
} else {
next(new ErrorGenerator("Invalid Date", 400));
}
}
)
|