From e0618e431fcea0ece7e94db21e9103375bd65370 Mon Sep 17 00:00:00 2001 From: ilnaz <237x237@gmail.com> Date: Sun, 19 Jan 2025 11:29:11 +0300 Subject: [PATCH] feat: add get date orders --- server/routers/dry-wash/arm-orders.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/server/routers/dry-wash/arm-orders.js b/server/routers/dry-wash/arm-orders.js index 97397b1..ec8a0a4 100644 --- a/server/routers/dry-wash/arm-orders.js +++ b/server/routers/dry-wash/arm-orders.js @@ -2,7 +2,19 @@ const router = require('express').Router() const { OrderModel } = require('./model/order') router.post('/orders', async (req, res, next) => { - const orders = await OrderModel.find({}) + const {startDate, endDate} = req.body + + if (!startDate || !endDate) { + throw new Error('startDate and endDate are required') + } + + const orders = await OrderModel.find({ + $or: [ + {startWashTime: { $gte: new Date(startDate), $lte: new Date(endDate) }}, + {endWashTime: { $gte: new Date(startDate), $lte: new Date(endDate) }}, + ] + }) + res.status(200).send({ success: true, body: orders }) })