From 9a0669df13ee9d05b907c15211e94f1762006053 Mon Sep 17 00:00:00 2001
From: ilnaz <237x237@gmail.com>
Date: Mon, 3 Mar 2025 20:08:28 +0300
Subject: [PATCH] feat: add find by id

---
 server/routers/dry-wash/order.js | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/server/routers/dry-wash/order.js b/server/routers/dry-wash/order.js
index 8244900..7485b75 100644
--- a/server/routers/dry-wash/order.js
+++ b/server/routers/dry-wash/order.js
@@ -156,17 +156,21 @@ router.post('/create', async (req, res, next) => {
 
 router.get('/:id', async (req, res, next) => {
     const { id } = req.params
+
     if (!mongoose.Types.ObjectId.isValid(id)) {
         throw new Error(VALIDATION_MESSAGES.orderId.invalid)
     }
 
     try {
         const order = await OrderModel.findById(id)
+
         if (!order) {
             throw new Error(VALIDATION_MESSAGES.order.notFound)
         }
 
-        res.status(200).send({ success: true, body: order })
+        const data = await OrderCarImgModel.findOne({ orderId: order.id }) || {}
+
+        res.status(200).send({ success: true, body: {...order,...data} })
     } catch (error) {
         next(error)
     }
@@ -277,7 +281,6 @@ const upload = multer({
 const { v4: uuidv4 } = require("uuid")
 const axios = require('axios')
 
-const GIGA_CHAT_ACCESS_TOKEN = 'MTQwMmNmZjgtZjA5OC00OGMxLWI0OTUtNWU3ZTU4YzMzZjdjOmU5OGFiYmNiLThmMDItNGVmOC1hNjhhLTA4Y2QxYjVmOGRmMA=='
 const GIGA_CHAT_OAUTH = 'https://ngw.devices.sberbank.ru:9443/api/v2/oauth'
 const GIGA_CHAT_API = 'https://gigachat.devices.sberbank.ru/api/v1'
 
@@ -416,7 +419,7 @@ router.post('/:id/upload-car-img', upload.single('file'), async (req, res) => {
             image: convertFileToBase64(req.file),
             imageRating: value,
             imageDescription: description,
-            orderId,
+            orderId: order.id,
             created: new Date().toISOString(),
         })
 
@@ -439,4 +442,4 @@ router.use((err, req, res, next) => {
     throw new Error(err.message)
 })
 
-module.exports = router
\ No newline at end of file
+module.exports = router