feat: make the time of the master to be taken from the body

This commit is contained in:
Ильназ 2025-03-17 21:05:48 +03:00
parent 78b72b0edc
commit 775f24cffa

View File

@ -3,20 +3,22 @@ const { MasterModel } = require("./model/master");
const mongoose = require("mongoose"); const mongoose = require("mongoose");
const { OrderModel } = require("./model/order"); const { OrderModel } = require("./model/order");
router.get("/masters", async (req, res, next) => { router.post("/masters/list", async (req, res, next) => {
try { try {
const masters = await MasterModel.find({}); const { startDate, endDate } = req.body;
// Создаем объекты для начала и конца текущего дня if (!startDate || !endDate) {
const today = new Date(); throw new Error("Missing startDate or endDate");
today.setHours(0, 0, 0, 0); }
const tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate() + 1); const start = new Date(startDate);
const end = new Date(endDate);
const masters = await MasterModel.find({});
const orders = await OrderModel.find({ const orders = await OrderModel.find({
startWashTime: { startWashTime: {
$gte: today, $gte: start,
$lt: tomorrow, $lt: end,
}, },
}); });