Repository: Space2Study-UA-1355-01/BackEnd-01
Pull request #13: #254 Implemented user photo upload with Cloudinary integration
Author: login: yrudikov
Created: 2025-04-24T11:52:23Z | Merged: 2025-04-28T20:37:21Z

Added support for uploading and saving user profile photos using Cloudinary.

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **New Features**
  - Introduced a secure photo upload API endpoint supporting JPEG and PNG images up to 10MB.
- **Documentation**
  - Added comprehensive API documentation detailing upload requests, responses, and error cases.
- **Chores**
  - Updated dependencies and refactored middleware to enhance file upload handling and configuration flexibility.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->


Diff:
diff --git a/docs/uploadPhoto.yaml b/docs/uploadPhoto.yaml
new file mode 100644
index 0000000..ef16087
--- /dev/null
+++ b/docs/uploadPhoto.yaml
@@ -0,0 +1,59 @@
+paths:
+  /upload:
+    post:
+      security:
+        - bearerAuth: [ ]
+      tags:
+        - Upload
+      summary: Upload a user photo
+      description: Uploads an image to Cloudinary and returns the public ID and secure URL of the uploaded file.
+      requestBody:
+        required: true
+        content:
+          multipart/form-data:
+            schema:
+              type: object
+              properties:
+                image:
+                  type: string
+                  format: binary
+                  description: |
+                    The image file to be uploaded.
+                    - Allowed formats: JPEG, PNG, JPG
+                    - Maximum file size: 10MB
+      responses:
+        '200':
+          description: Image uploaded successfully
+          content:
+            application/json:
+              schema:
+                type: object
+                properties:
+                  public_id:
+                    type: string
+                    example: "sp_project/images/avatar_123"
+                    description: Public Cloudinary ID for the uploaded image
+                  url:
+                    type: string
+                    example: "https://res.cloudinary.com/example/image/upload/v1740000000/sp_project/images/avatar_123.jpg"
+                    description: Direct HTTPS link to the uploaded image
+        '400':
+          description: No image file provided
+          content:
+            application/json:
+              schema:
+                type: object
+                properties:
+                  error:
+                    type: string
+                    example: "No file provided"
+        '500':
+          description: Internal server error during upload
+          content:
+            application/json:
+              schema:
+                type: object
+                properties:
+                  error:
+                    type: string
+                    example: "Failed to upload image"
diff --git a/package-lock.json b/package-lock.json
index 7e14159..efe2f8b 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -11,6 +11,7 @@
       "dependencies": {
         "axios": "^1.8.4",
         "bcrypt": "^5.0.1",
+        "cloudinary": "^2.6.0",
         "cookie-parser": "^1.4.6",
         "cors": "^2.8.5",
         "cron": "^2.1.0",
@@ -3833,6 +3834,18 @@
         "url": "https://github.com/chalk/wrap-ansi?sponsor=1"
       }
     },
+    "node_modules/cloudinary": {
+      "version": "2.6.0",
+      "resolved": "https://registry.npmjs.org/cloudinary/-/cloudinary-2.6.0.tgz",
+      "integrity": "sha512-FIlny9RR5LPgkMioG4V7yUpC6ASyIFQMWfx4TgOi/xBeLxJTegbyQc3itiXL0b0lDlSaL0KyT2THEw6osrKqpQ==",
+      "dependencies": {
+        "lodash": "^4.17.21",
+        "q": "^1.5.1"
+      },
+      "engines": {
+        "node": ">=9"
+      }
+    },
     "node_modules/co": {
       "version": "4.6.0",
       "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz",
@@ -8743,6 +8756,16 @@
         "node": ">=6"
       }
     },
+    "node_modules/q": {
+      "version": "1.5.1",
+      "resolved": "https://registry.npmjs.org/q/-/q-1.5.1.tgz",
+      "integrity": "sha512-kV/CThkXo6xyFEZUugw/+pIOywXcDbFYgSct5cT3gqlbkBE1SJdwy6UQoZvodiWF/ckQLZyDE/Bu1M6gVu5lVw==",
+      "deprecated": "You or someone you depend on is using Q, the JavaScript Promise library that gave JavaScript developers strong feelings about promises. They can almost certainly migrate to the native JavaScript promise now. Thank you literally everyone for joining me in this bet against the odds. Be excellent to each other.\n\n(For a CapTP with native promises, see @endo/eventual-send and @endo/captp)",
+      "engines": {
+        "node": ">=0.6.0",
+        "teleport": ">=0.2.0"
+      }
+    },
     "node_modules/qs": {
       "version": "6.11.2",
       "resolved": "https://registry.npmjs.org/qs/-/qs-6.11.2.tgz",
diff --git a/package.json b/package.json
index f2e6289..6998a86 100644
--- a/package.json
+++ b/package.json
@@ -27,6 +27,7 @@
   "dependencies": {
     "axios": "^1.8.4",
     "bcrypt": "^5.0.1",
+    "cloudinary": "^2.6.0",
     "cookie-parser": "^1.4.6",
     "cors": "^2.8.5",
     "cron": "^2.1.0",
diff --git a/src/configs/cloudinary.js b/src/configs/cloudinary.js
new file mode 100644
index 0000000..d423a53
--- /dev/null
+++ b/src/configs/cloudinary.js
@@ -0,0 +1,10 @@
+const { v2: cloudinary } = require('cloudinary')
+
+cloudinary.config({
+  cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
+  api_key: process.env.CLOUDINARY_API_KEY,
+  api_secret: process.env.CLOUDINARY_API_SECRET,
+  secure: true
+})
+
+module.exports = cloudinary
diff --git a/src/controllers/uploadPhoto.js b/src/controllers/uploadPhoto.js
new file mode 100644
index 0000000..2064332
--- /dev/null
+++ b/src/controllers/uploadPhoto.js
@@ -0,0 +1,50 @@
+const cloudinary = require('../configs/cloudinary')
+const User = require('~/models/user')
+
+const uploadImage = async (buffer, userId) => {
+  const folderPath = `sp_project/users/${userId}`
+
+  return new Promise((resolve, reject) => {
+    const stream = cloudinary.uploader.upload_stream(
+      {
+        use_filename: true,
+        unique_filename: true,
+        overwrite: true,
+        folder: `${folderPath}`,
+        transformation: [
+          { width: 600, crop: 'limit' },
+          { fetch_format: 'auto', quality: 'auto' }
+        ]
+      },
+      (error, result) => {
+        if (error) return reject(error)
+        resolve(result)
+      }
+    )
+
+    stream.end(buffer)
+  })
+}
+
+const uploadController = async (req, res) => {
+  try {
+    if (!req.file) {
+      return res.status(400).json({ code: 'No file provided' })
+    }
+
+    const userId = req.user.id
+    const result = await uploadImage(req.file.buffer, userId)
+    await User.findByIdAndUpdate(userId, { photo: result.public_id })
+
+    res.status(200).json({
+      message: 'Image uploaded successfully',
+      url: result.secure_url,
+      public_id: result.public_id
+    })
+  } catch (error) {
+    console.error('Upload error:', error)
+    res.status(500).json({ code: 'Failed to upload image' })
+  }
+}
+
+module.exports = { uploadController }
diff --git a/src/initialization/swaggerSettings.js b/src/initialization/swaggerSettings.js
index 6a3a487..58952ac 100644
--- a/src/initialization/swaggerSettings.js
+++ b/src/initialization/swaggerSettings.js
@@ -1,23 +1,29 @@
-const swaggerJsDoc = require('swagger-jsdoc')
-
-const swaggerOptions = {
-  definition: {
-    openapi: '3.0.0',
-    info: {
-      title: 'Express API for space2study',
-      version: '1',
-      description: ''
-    },
-    servers: [
-      {
-        url: process.env.SERVER_URL
-      }
-    ],
-    components: {
-      securitySchemes: {}
-    }
-  },
-  apis: ['./docs/*.yaml']
-}
-
-module.exports = swaggerJsDoc(swaggerOptions)
\ No newline at end of file
+const swaggerJsDoc = require('swagger-jsdoc')
+
+const swaggerOptions = {
+  definition: {
+    openapi: '3.0.0',
+    info: {
+      title: 'Express API for space2study',
+      version: '1',
+      description: ''
+    },
+    servers: [
+      {
+        url: process.env.SERVER_URL
+      }
+    ],
+    components: {
+      securitySchemes: {
+        bearerAuth: {
+          type: 'http',
+          scheme: 'bearer',
+          bearerFormat: 'JWT'
+        }
+      }
+    }
+  },
+  apis: ['./docs/*.yaml']
+}
+
+module.exports = swaggerJsDoc(swaggerOptions)
diff --git a/src/middlewares/multer.js b/src/middlewares/multer.js
index 162539f..56ed05f 100644
--- a/src/middlewares/multer.js
+++ b/src/middlewares/multer.js
@@ -1,12 +1,19 @@
-const multer = require('multer')
-
-const storage = multer.memoryStorage()
-const upload = multer({
-  storage,
-  limits: {
-    fileSize: 10 * 1024 * 1024,
-    fieldNameSize: 100
-  }
-})
-
-module.exports = upload
+const multer = require('multer')
+
+const defaultStorage = multer.memoryStorage()
+
+const defaultLimits = {
+  fileSize: 10 * 1024 * 1024, // 10MB
+  fieldNameSize: 100
+}
+const createUpload = ({ storage = defaultStorage, limits = defaultLimits, fileFilter } = {}) => {
+  return multer({
+    storage,
+    limits,
+    fileFilter
+  })
+}
+
+const upload = createUpload()
+
+module.exports = { upload, createUpload }
diff --git a/src/routes/index.js b/src/routes/index.js
index 1faf156..a8b37d8 100644
--- a/src/routes/index.js
+++ b/src/routes/index.js
@@ -1,26 +1,27 @@
-const router = require('express').Router()
-
-const auth = require('~/routes/auth')
-const user = require('~/routes/user')
-const email = require('~/routes/email')
-const adminInvitation = require('~/routes/adminInvitation')
-const question = require('~/routes/question')
-const resourcesCategory = require('~/routes/resourcesCategory')
-const offer = require('~/routes/offer')
-const category = require('~/routes/category')
-const country = require('~/routes/countries')
-const subject = require('~/routes/subject')
-
-router.use('/auth', auth)
-router.use('/users', user)
-router.use('/send-email', email)
-router.use('/admin-invitations', adminInvitation)
-router.use('/questions', question)
-router.use('/resources-categories', resourcesCategory)
-router.use('/offers', offer)
-router.use('/categories', category)
-router.use('/countries', country)
-router.use('/subjects', subject)
-
-
-module.exports = router
+const router = require('express').Router()
+
+const auth = require('~/routes/auth')
+const user = require('~/routes/user')
+const email = require('~/routes/email')
+const adminInvitation = require('~/routes/adminInvitation')
+const question = require('~/routes/question')
+const resourcesCategory = require('~/routes/resourcesCategory')
+const offer = require('~/routes/offer')
+const category = require('~/routes/category')
+const country = require('~/routes/countries')
+const uploadRoutes = require('~/routes/uploadPhoto')
+const subject = require('~/routes/subject')
+
+router.use('/auth', auth)
+router.use('/users', user)
+router.use('/send-email', email)
+router.use('/admin-invitations', adminInvitation)
+router.use('/questions', question)
+router.use('/resources-categories', resourcesCategory)
+router.use('/offers', offer)
+router.use('/categories', category)
+router.use('/countries', country)
+router.use('/upload', uploadRoutes)
+router.use('/subjects', subject)
+
+module.exports = router
diff --git a/src/routes/uploadPhoto.js b/src/routes/uploadPhoto.js
new file mode 100644
index 0000000..64e8573
--- /dev/null
+++ b/src/routes/uploadPhoto.js
@@ -0,0 +1,22 @@
+const express = require('express')
+const { createUpload } = require('~/middlewares/multer')
+const { authMiddleware } = require('~/middlewares/auth')
+const { uploadController } = require('../controllers/uploadPhoto')
+
+const router = express.Router()
+
+const allowedTypes = ['image/jpeg', 'image/png', 'image/jpg']
+
+const fileFilter = (req, file, cb) => {
+  if (allowedTypes.includes(file.mimetype)) {
+    cb(null, true)
+  } else {
+    cb(new Error('Unsupported file type'), false)
+  }
+}
+
+const upload = createUpload({ fileFilter })
+
+router.post('/', authMiddleware, upload.single('image'), uploadController)
+
+module.exports = router


Reviews:
user: login: coderabbitai[bot]
body: **Actionable comments posted: 10**

<details>
<summary>🧹 Nitpick comments (4)</summary><blockquote>

<details>
<summary>src/routes/index.js (1)</summary><blockquote>

`11-11`: **Upload route correctly integrated.**

The new upload route is properly imported and mounted in the Express router, following the established pattern in the codebase.


There's a linebreak style inconsistency (CRLF vs LF) with other lines. Consider using a `.editorconfig` file or Git settings to ensure consistent line endings across the codebase.


Also applies to: 21-21

<details>
<summary>🧰 Tools</summary>

<details>
<summary>🪛 ESLint</summary>

[error] 10-11: Expected linebreaks to be 'CRLF' but found 'LF'.

(linebreak-style)

---

[error] 11-12: Expected linebreaks to be 'CRLF' but found 'LF'.

(linebreak-style)

</details>

</details>

</blockquote></details>
<details>
<summary>src/controllers/uploadPhoto.js (3)</summary><blockquote>

`26-43`: **Improve error handling with more specific error messages.**

The current error handling is basic and could be enhanced to provide more helpful feedback to users.

Consider adding more specific error handling:

```diff
const uploadController = async (req, res) => {
  try {
    if (!req.file) {
      return res.status(400).json({ error: 'No file provided' })
    }
+    
+    // Validate file type
+    if (!ALLOWED_FILE_TYPES.includes(req.file.mimetype)) {
+      return res.status(400).json({ 
+        error: 'Invalid file type. Allowed types: JPEG, PNG, GIF, WebP' 
+      });
+    }
+    
+    // Validate file size
+    if (req.file.size > MAX_FILE_SIZE) {
+      return res.status(400).json({ 
+        error: `File too large. Maximum size: ${MAX_FILE_SIZE / (1024 * 1024)}MB` 
+      });
+    }

    const result = await uploadImage(req.file.buffer)

    res.status(200).json({
      message: 'Image uploaded successfully',
      url: result.secure_url,
      public_id: result.public_id
    })
  } catch (error) {
    console.error('Upload error:', error)
-    res.status(500).json({ error: 'Failed to upload image' })
+    if (error.http_code) {
+      // Cloudinary specific errors
+      res.status(error.http_code).json({ error: error.message || 'Failed to upload image' })
+    } else {
+      res.status(500).json({ error: 'Failed to upload image' })
+    }
  }
}
```

---

`22-22`: **Consider handling potential stream errors.**

The current implementation doesn't handle potential errors when sending data to the stream.

Add error handling for the stream:

```diff
-    stream.end(buffer)
+    try {
+      stream.end(buffer)
+    } catch (err) {
+      reject(new Error('Failed to process image buffer: ' + err.message))
+    }
```

---

`7-14`: **Consider additional security settings for Cloudinary upload.**

The current Cloudinary configuration could potentially be enhanced with additional security settings.

Consider adding resource type validation and disabling remote URLs:

```diff
{
  use_filename: true,
  unique_filename: true,
  overwrite: true,
  folder: 'sp_project/images',
+  resource_type: 'image', // Explicitly specify resource type
+  allowed_formats: ['jpg', 'png', 'gif', 'webp'], // Restrict allowed formats
+  disallow_url: true, // Prevent uploading from remote URLs
  transformation: [
    { width: 600, crop: 'limit' },
    { fetch_format: 'auto', quality: 'auto' }
  ]
}
```

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 1f61dcec2913b3131b96a351465a8f9b7fd54188 and 91d6f95f704f72e57a3a3a8b2053f2d17ee70449.

</details>

<details>
<summary>⛔ Files ignored due to path filters (1)</summary>

* `package-lock.json` is excluded by `!**/package-lock.json`

</details>

<details>
<summary>📒 Files selected for processing (6)</summary>

* `docs/uploadPhoto.yaml` (1 hunks)
* `package.json` (1 hunks)
* `src/configs/cloudinary.js` (1 hunks)
* `src/controllers/uploadPhoto.js` (1 hunks)
* `src/routes/index.js` (2 hunks)
* `src/routes/uploadPhoto.js` (1 hunks)

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🧬 Code Graph Analysis (3)</summary>

<details>
<summary>src/routes/index.js (1)</summary><blockquote>

<details>
<summary>src/routes/uploadPhoto.js (2)</summary>

* `require` (3-3)
* `router` (5-5)

</details>

</blockquote></details>
<details>
<summary>src/configs/cloudinary.js (1)</summary><blockquote>

<details>
<summary>src/controllers/uploadPhoto.js (1)</summary>

* `cloudinary` (1-1)

</details>

</blockquote></details>
<details>
<summary>src/routes/uploadPhoto.js (2)</summary><blockquote>

<details>
<summary>src/routes/index.js (1)</summary>

* `router` (1-1)

</details>
<details>
<summary>src/controllers/uploadPhoto.js (1)</summary>

* `uploadController` (26-43)

</details>

</blockquote></details>

</details><details>
<summary>🪛 ESLint</summary>

<details>
<summary>src/routes/index.js</summary>

[error] 10-11: Expected linebreaks to be 'CRLF' but found 'LF'.

(linebreak-style)

---

[error] 11-12: Expected linebreaks to be 'CRLF' but found 'LF'.

(linebreak-style)

---

[error] 20-21: Expected linebreaks to be 'CRLF' but found 'LF'.

(linebreak-style)

---

[error] 21-22: Expected linebreaks to be 'CRLF' but found 'LF'.

(linebreak-style)

</details>

</details>

</details>

<details>
<summary>🔇 Additional comments (1)</summary><blockquote>

<details>
<summary>package.json (1)</summary>

`30-30`: <details>
<summary>✅ Verification successful</summary>

**Cloudinary dependency correctly added.**

The Cloudinary SDK has been added with the proper version syntax. This is required for the user photo upload integration.


---

🌐 Web query:

```web
What is the latest stable version of the Cloudinary Node.js SDK?
```

💡 Result:

The latest stable version of the Cloudinary Node.js SDK is **2.6.0**, which was last published in March 2025[2]. This version is compatible with Node.js 9 and above[5]. You can install it using npm:

```
npm install cloudinary
```

For the most up-to-date documentation, you can refer to Cloudinary's official Node.js SDK guide[1][3][6].

Citations:

- 1: https://cloudinary.com/documentation/node_integration
- 2: https://www.npmjs.com/package/cloudinary
- 3: https://cloudinary.com/documentation/cloudinary_sdks
- 4: https://github.com/cloudinary/js-transformation-builder-sdk
- 5: https://classic.yarnpkg.com/en/package/cloudinary
- 6: https://cloudinary.com/documentation/node_quickstart
- 7: https://www.contentful.com/developers/changelog/
- 8: https://github.com/cloudinary/js-url-gen
- 9: https://docs.astro.build/en/guides/media/cloudinary/
- 10: https://nextjs.org/docs/pages/guides/static-exports

---



</details>

**Approve Cloudinary dependency**

Verified that version **2.6.0** is the latest stable Cloudinary Node.js SDK (compatible with Node.js 9+). This dependency is required for the user photo upload integration and follows standard versioning practice.

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->
state: COMMENTED
author_association: NONE
submitted_at: 2025-04-24T11:55:41Z
user: login: coderabbitai[bot]
body: **Actionable comments posted: 0**

<details>
<summary>♻️ Duplicate comments (2)</summary><blockquote>

<details>
<summary>src/routes/uploadPhoto.js (2)</summary><blockquote>

`18-18`: _🛠️ Refactor suggestion_

**Add file size limits to prevent large file uploads.**

The current implementation does not specify size limits for uploaded files, which could lead to server overload if extremely large files are uploaded.


```diff
-const upload = createUpload({ fileFilter })
+const upload = createUpload({ 
+  fileFilter,
+  limits: {
+    fileSize: 5 * 1024 * 1024, // 5MB limit
+  }
+})
```

---

`20-20`: _⚠️ Potential issue_

**Implement error handling for multer upload failures.**

The route is missing error handling for file upload failures (like exceeding size limits or invalid file types). These errors should be properly caught and formatted.


```diff
-router.post('/', authMiddleware, upload.single('image'), uploadController)
+router.post('/', authMiddleware, (req, res, next) => {
+  upload.single('image')(req, res, (err) => {
+    if (err) {
+      return res.status(400).json({ 
+        error: err.message || 'File upload error'
+      });
+    }
+    next();
+  });
+}, uploadController)
```

</blockquote></details>

</blockquote></details>

<details>
<summary>🧹 Nitpick comments (6)</summary><blockquote>

<details>
<summary>src/routes/uploadPhoto.js (3)</summary><blockquote>

`2-4`: **Standardize import paths for consistency.**

The import for the uploadController uses a relative path (`../controllers/uploadPhoto`) while other imports use the `~` alias path. This inconsistency can make the codebase harder to maintain.

```diff
 const express = require('express')
 const { createUpload } = require('~/middlewares/multer')
 const { authMiddleware } = require('~/middlewares/auth')
-const { uploadController } = require('../controllers/uploadPhoto')
+const { uploadController } = require('~/controllers/uploadPhoto')
```

---

`8-8`: **Consider removing redundant MIME type.**

'image/jpg' and 'image/jpeg' in the allowed types array are essentially the same; 'image/jpeg' is the standard MIME type for JPEG images.

```diff
-const allowedTypes = ['image/jpeg', 'image/png', 'image/jpg']
+const allowedTypes = ['image/jpeg', 'image/png']
```

---

`10-16`: **Enhance file validation beyond MIME type checking.**

MIME types can be spoofed by clients. Consider adding file extension validation or using a library like `file-type` to analyze file content.

```diff
 const fileFilter = (req, file, cb) => {
+  // Get file extension from original filename
+  const fileExtension = file.originalname.split('.').pop().toLowerCase();
+  const validExtensions = ['jpg', 'jpeg', 'png'];
+  
   if (allowedTypes.includes(file.mimetype)) {
+    // Additional check for file extension
+    if (!validExtensions.includes(fileExtension)) {
+      return cb(new Error('Invalid file extension'), false);
+    }
     cb(null, true)
   } else {
     cb(new Error('Unsupported file type'), false)
   }
 }
```

</blockquote></details>
<details>
<summary>src/middlewares/multer.js (3)</summary><blockquote>

`3-10`: **Remove commented out code.**

Commented out code should be removed rather than kept in the codebase. Version control systems like Git already maintain history, making commented code redundant and potentially confusing.

```diff
 const multer = require('multer')

-// const storage = multer.memoryStorage()
-// const upload = multer({
-//   storage,
-//   limits: {
-//     fileSize: 10 * 1024 * 1024,
-//     fieldNameSize: 100
-//   }
-// })
```

---

`14-17`: **Add comments explaining the chosen limits.**

The default file size limit is set to 10MB without explanation. Consider adding a comment explaining why this limit was chosen, especially for profile photos which are typically much smaller.

```diff
 const defaultLimits = {
-  fileSize: 10 * 1024 * 1024, // 10MB
+  fileSize: 10 * 1024 * 1024, // 10MB - Allows for high-resolution profile photos while preventing abuse
   fieldNameSize: 100
 }
```

---

`18-24`: **Add JSDoc documentation and parameter validation.**

The `createUpload` function lacks proper documentation and input validation. Adding JSDoc comments would improve developer experience, and parameter validation would prevent runtime errors.

```diff
+/**
+ * Creates a configured multer middleware instance
+ * @param {Object} options - Configuration options
+ * @param {Object} [options.storage=defaultStorage] - Multer storage engine
+ * @param {Object} [options.limits=defaultLimits] - Size and count limits
+ * @param {Function} [options.fileFilter] - Function to control which files are accepted
+ * @returns {Object} Configured multer middleware
+ */
 const createUpload = ({ storage = defaultStorage, limits = defaultLimits, fileFilter } = {}) => {
+  // Validate inputs
+  if (storage && typeof storage !== 'object') {
+    throw new Error('Storage must be a valid multer storage engine');
+  }
+  if (limits && typeof limits !== 'object') {
+    throw new Error('Limits must be an object');
+  }
+  if (fileFilter && typeof fileFilter !== 'function') {
+    throw new Error('File filter must be a function');
+  }
+
   return multer({
     storage,
     limits,
     fileFilter
   })
 }
```

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 91d6f95f704f72e57a3a3a8b2053f2d17ee70449 and 341b4696602fd6504ee6b1b6c2c250febc04964d.

</details>

<details>
<summary>📒 Files selected for processing (5)</summary>

* `docs/uploadPhoto.yaml` (1 hunks)
* `src/controllers/uploadPhoto.js` (1 hunks)
* `src/initialization/swaggerSettings.js` (1 hunks)
* `src/middlewares/multer.js` (1 hunks)
* `src/routes/uploadPhoto.js` (1 hunks)

</details>

<details>
<summary>✅ Files skipped from review due to trivial changes (1)</summary>

* src/initialization/swaggerSettings.js

</details>

<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (2)</summary>

* src/controllers/uploadPhoto.js
* docs/uploadPhoto.yaml

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🧬 Code Graph Analysis (1)</summary>

<details>
<summary>src/middlewares/multer.js (1)</summary><blockquote>

<details>
<summary>src/routes/uploadPhoto.js (4)</summary>

* `require` (2-2)
* `require` (3-3)
* `require` (4-4)
* `upload` (18-18)

</details>

</blockquote></details>

</details>

</details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->
state: COMMENTED
author_association: NONE
submitted_at: 2025-04-25T02:39:00Z
user: login: pavlo1377
state: APPROVED
author_association: NONE
submitted_at: 2025-04-25T08:32:24Z
user: login: NataliiaDanchenko
state: APPROVED
author_association: NONE
submitted_at: 2025-04-25T09:45:28Z
user: login: ssashayurchenko
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-25T15:03:59Z
user: login: coderabbitai[bot]
body: **Actionable comments posted: 1**

<details>
<summary>♻️ Duplicate comments (1)</summary><blockquote>

<details>
<summary>src/controllers/uploadPhoto.js (1)</summary><blockquote>

`4-25`: _🛠️ Refactor suggestion_

**Add validation for image file types and size limits.**

The `uploadImage` function doesn't validate file types or sizes, which could lead to security vulnerabilities. Although there may be validation in the middleware (as suggested by the route file), adding a secondary validation layer here would improve security.




```diff
const cloudinary = require('../configs/cloudinary')
const User = require('~/models/user')

+// Allowed mime types and max file size
+const ALLOWED_FILE_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp']
+const MAX_FILE_SIZE = 5 * 1024 * 1024 // 5MB
+
const uploadImage = async (buffer) => {
  return new Promise((resolve, reject) => {
    const stream = cloudinary.uploader.upload_stream(
      {
        use_filename: true,
        unique_filename: true,
        overwrite: true,
        folder: 'sp_project/images',
        transformation: [
          { width: 600, crop: 'limit' },
          { fetch_format: 'auto', quality: 'auto' }
        ]
      },
      (error, result) => {
        if (error) return reject(error)
        resolve(result)
      }
    )

    stream.end(buffer)
  })
}
```

</blockquote></details>

</blockquote></details>

<details>
<summary>🧹 Nitpick comments (3)</summary><blockquote>

<details>
<summary>src/controllers/uploadPhoto.js (3)</summary><blockquote>

`1-3`: **Review the import paths for consistency.**

The file uses different import styles: a relative path (`../configs/cloudinary`) and an alias path (`~/models/user`). Consider standardizing all imports to use the alias pattern for better maintainability.

```diff
-const cloudinary = require('../configs/cloudinary')
+const cloudinary = require('~/configs/cloudinary')
 const User = require('~/models/user')
```

---

`4-25`: **Add timeout handling for the upload process.**

The Cloudinary upload has no timeout handling, which could lead to hung requests if Cloudinary is slow to respond. Consider adding a timeout mechanism to prevent this.



```diff
const uploadImage = async (buffer) => {
  return new Promise((resolve, reject) => {
+   // Set a timeout to prevent hung requests
+   const timeoutId = setTimeout(() => {
+     reject(new Error('Upload timeout - operation took too long'))
+   }, 30000) // 30 seconds timeout
+   
    const stream = cloudinary.uploader.upload_stream(
      {
        use_filename: true,
        unique_filename: true,
        overwrite: true,
        folder: 'sp_project/images',
        transformation: [
          { width: 600, crop: 'limit' },
          { fetch_format: 'auto', quality: 'auto' }
        ]
      },
      (error, result) => {
+       clearTimeout(timeoutId) // Clear the timeout on completion
        if (error) return reject(error)
        resolve(result)
      }
    )

    stream.end(buffer)
  })
}
```

---

`43-46`: **Improve error logging and response details.**

The error handling could be more detailed to help with debugging. Consider adding more context to the error logs and potentially returning different status codes based on the error type.



```diff
  } catch (error) {
-   console.error('Upload error:', error)
-   res.status(500).json({ code: 'Failed to upload image' })
+   console.error('Upload error:', error.message, error.stack)
+   // Determine if it's a client error or server error
+   const statusCode = error.name === 'ValidationError' ? 400 : 500
+   const errorCode = error.name === 'ValidationError' ? 'Invalid image data' : 'Failed to upload image'
+   res.status(statusCode).json({ code: errorCode })
  }
```

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 341b4696602fd6504ee6b1b6c2c250febc04964d and 9a07e1e0f1d8ec054e5f5901a36800aff8ef4e25.

</details>

<details>
<summary>📒 Files selected for processing (2)</summary>

* `src/controllers/uploadPhoto.js` (1 hunks)
* `src/middlewares/multer.js` (1 hunks)

</details>

<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary>

* src/middlewares/multer.js

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🧬 Code Graph Analysis (1)</summary>

<details>
<summary>src/controllers/uploadPhoto.js (2)</summary><blockquote>

<details>
<summary>src/configs/cloudinary.js (1)</summary>

* `cloudinary` (1-1)

</details>
<details>
<summary>src/routes/uploadPhoto.js (3)</summary>

* `require` (2-2)
* `require` (3-3)
* `require` (4-4)

</details>

</blockquote></details>

</details>

</details>

<details>
<summary>🔇 Additional comments (2)</summary><blockquote>

<details>
<summary>src/controllers/uploadPhoto.js (2)</summary>

`38-42`: **Consider removing the message field from the response.**

According to the past review comments, the `message` field was removed in a later commit to match the OpenAPI documentation. Ensure this change is applied in the final version.



```diff
res.status(200).json({
-  message: 'Image uploaded successfully',
  url: result.secure_url,
  public_id: result.public_id
})
```

---

`49-49`: **File organization looks clean.**

Good job exporting only what's needed from this module. The clear separation between the helper function and controller function is a good practice.

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->
state: COMMENTED
author_association: NONE
submitted_at: 2025-04-27T21:55:59Z
user: login: VoroninaMaria
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-04-28T08:16:26Z
user: login: vlad-khrychov
state: APPROVED
author_association: NONE
submitted_at: 2025-04-28T15:16:32Z
user: login: oksana0145
state: APPROVED
author_association: NONE
submitted_at: 2025-04-28T17:31:27Z
user: login: yrudikov
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-04-28T20:36:47Z

Review comments:
diff_hunk: @@ -0,0 +1,10 @@
+const { v2: cloudinary } = require('cloudinary')
+
+cloudinary.config({
+  cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
+  api_key: process.env.CLOUDINARY_API_KEY,
+  api_secret: process.env.CLOUDINARY_API_SECRET,
+  secure: true
+})
path: src/configs/cloudinary.js
user: login: coderabbitai[bot]
body: _🛠️ Refactor suggestion_

**Environment variable validation needed.**

The configuration is correctly set up with environment variables and secure connection. However, there's no validation to ensure these required environment variables are actually defined.

Consider adding validation to prevent runtime errors if environment variables are missing:

```diff
-cloudinary.config({
+// Validate environment variables
+const requiredEnvVars = [
+  'CLOUDINARY_CLOUD_NAME',
+  'CLOUDINARY_API_KEY',
+  'CLOUDINARY_API_SECRET'
+];
+
+const missingEnvVars = requiredEnvVars.filter(varName => !process.env[varName]);
+if (missingEnvVars.length > 0) {
+  throw new Error(`Missing required environment variables: ${missingEnvVars.join(', ')}`);
+}
+
+cloudinary.config({
  cloud_name: process.env.CLOUDINARY_CLOUD_NAME,
  api_key: process.env.CLOUDINARY_API_KEY,
  api_secret: process.env.CLOUDINARY_API_SECRET,
  secure: true
})
```

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-04-24T11:55:39Z
author_association: NONE
diff_hunk: @@ -0,0 +1,11 @@
+const express = require('express')
+const multer = require('multer')
+const { uploadController } = require('../controllers/uploadPhoto')
+
+const router = express.Router()
+const storage = multer.memoryStorage()
+const upload = multer({ storage })
path: src/routes/uploadPhoto.js
user: login: coderabbitai[bot]
body: _🛠️ Refactor suggestion_

**Add file validation to prevent security issues.**

Using memory storage is good for Cloudinary integration, but the implementation lacks file type and size validation, which is crucial for security and performance.

Add file type and size restrictions to the multer configuration:

```diff
-const upload = multer({ storage })
+const upload = multer({
+  storage,
+  limits: {
+    fileSize: 5 * 1024 * 1024, // 5MB limit
+  },
+  fileFilter: (req, file, cb) => {
+    // Accept only images
+    if (!file.mimetype.startsWith('image/')) {
+      return cb(new Error('Only image files are allowed'), false);
+    }
+    cb(null, true);
+  }
+})
```


<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

`````suggestion
const storage = multer.memoryStorage()
const upload = multer({
  storage,
  limits: {
    fileSize: 5 * 1024 * 1024, // 5MB limit
  },
  fileFilter: (req, file, cb) => {
    // Accept only images
    if (!file.mimetype.startsWith('image/')) {
      return cb(new Error('Only image files are allowed'), false)
    }
    cb(null, true)
  }
})
`````

</details>

<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-04-24T11:55:39Z
author_association: NONE
diff_hunk: @@ -0,0 +1,11 @@
+const express = require('express')
+const multer = require('multer')
+const { uploadController } = require('../controllers/uploadPhoto')
+
+const router = express.Router()
+const storage = multer.memoryStorage()
+const upload = multer({ storage })
+
+router.post('/', upload.single('image'), uploadController)
path: src/routes/uploadPhoto.js
user: login: coderabbitai[bot]
body: _🛠️ Refactor suggestion_

**Implement error handling for multer middleware.**

The route is missing error handling for file upload failures (like exceeding size limits or invalid file types). These errors should be properly caught and formatted before reaching the controller.

Implement error handling middleware for multer:

```diff
-router.post('/', upload.single('image'), uploadController)
+router.post('/', (req, res, next) => {
+  upload.single('image')(req, res, (err) => {
+    if (err instanceof multer.MulterError) {
+      // A Multer error occurred when uploading
+      return res.status(400).json({ 
+        error: err.message || 'File upload error',
+        code: err.code
+      });
+    } else if (err) {
+      // An unknown error occurred
+      return res.status(400).json({ error: err.message || 'Invalid file' });
+    }
+    // No errors, proceed to controller
+    next();
+  });
+}, uploadController)
```


<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

`````suggestion
router.post('/', (req, res, next) => {
  upload.single('image')(req, res, (err) => {
    if (err instanceof multer.MulterError) {
      // A Multer error occurred when uploading
      return res.status(400).json({
        error: err.message || 'File upload error',
        code: err.code
      });
    } else if (err) {
      // An unknown error occurred
      return res.status(400).json({ 
        error: err.message || 'Invalid file'
      });
    }
    // No errors, proceed to controller
    next();
  });
}, uploadController);
`````

</details>

<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-04-24T11:55:40Z
author_association: NONE
diff_hunk: @@ -0,0 +1,45 @@
+const cloudinary = require('../configs/cloudinary')
+
+const uploadImage = async (buffer) => {
+  return new Promise((resolve, reject) => {
+    const stream = cloudinary.uploader.upload_stream(
+      {
+        use_filename: true,
+        unique_filename: true,
+        overwrite: true,
+        folder: 'sp_project/images',
+        transformation: [
+          { width: 600, crop: 'limit' },
+          { fetch_format: 'auto', quality: 'auto' }
+        ]
+      },
+      (error, result) => {
+        if (error) return reject(error)
+        resolve(result)
+      }
+    )
+
+    stream.end(buffer)
+  })
+}
+
path: src/controllers/uploadPhoto.js
user: login: coderabbitai[bot]
body: _🛠️ Refactor suggestion_

**Add validation for image file types and size limits.**

The `uploadImage` function doesn't validate file types, which could lead to security vulnerabilities. Attackers might upload malicious files disguised as images.

Consider adding validation before uploading:

```diff
const cloudinary = require('../configs/cloudinary')
+
+// Allowed mime types and max file size
+const ALLOWED_FILE_TYPES = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
+const MAX_FILE_SIZE = 5 * 1024 * 1024; // 5MB

const uploadImage = async (buffer) => {
+  // This is a secondary check - primary should be in middleware
+  return new Promise((resolve, reject) => {
    const stream = cloudinary.uploader.upload_stream(
      {
        use_filename: true,
        unique_filename: true,
        overwrite: true,
        folder: 'sp_project/images',
        transformation: [
          { width: 600, crop: 'limit' },
          { fetch_format: 'auto', quality: 'auto' }
        ]
      },
      (error, result) => {
        if (error) return reject(error)
        resolve(result)
      }
    )

    stream.end(buffer)
  })
}
```


> Committable suggestion skipped: line range outside the PR's diff.

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-04-24T11:55:40Z
author_association: NONE
diff_hunk: @@ -0,0 +1,45 @@
+const cloudinary = require('../configs/cloudinary')
+
+const uploadImage = async (buffer) => {
+  return new Promise((resolve, reject) => {
+    const stream = cloudinary.uploader.upload_stream(
+      {
+        use_filename: true,
+        unique_filename: true,
+        overwrite: true,
+        folder: 'sp_project/images',
+        transformation: [
+          { width: 600, crop: 'limit' },
+          { fetch_format: 'auto', quality: 'auto' }
+        ]
+      },
+      (error, result) => {
+        if (error) return reject(error)
+        resolve(result)
+      }
+    )
+
+    stream.end(buffer)
+  })
+}
+
+const uploadController = async (req, res) => {
+  try {
+    if (!req.file) {
+      return res.status(400).json({ error: 'No file provided' })
+    }
+
+    const result = await uploadImage(req.file.buffer)
+
+    res.status(200).json({
+      message: 'Image uploaded successfully',
+      url: result.secure_url,
+      public_id: result.public_id
+    })
path: src/controllers/uploadPhoto.js
user: login: coderabbitai[bot]
body: _🛠️ Refactor suggestion_

**Ensure response format matches OpenAPI documentation.**

The response format doesn't match the OpenAPI specification in `docs/uploadPhoto.yaml`. The spec doesn't include a `message` field.

Update the response to match the documented format:

```diff
res.status(200).json({
-      message: 'Image uploaded successfully',
      url: result.secure_url,
      public_id: result.public_id
})
```


<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

`````suggestion
    res.status(200).json({
      url: result.secure_url,
      public_id: result.public_id
    })
`````

</details>

<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->

✅ Addressed in commit 341b469
created_at: 2025-04-24T11:55:40Z
author_association: NONE
diff_hunk: @@ -0,0 +1,54 @@
+paths:
+  /upload:
+    post:
+      tags:
+        - Upload
+      summary: Upload a user photo
+      description: Uploads an image to Cloudinary and returns the public ID and secure URL of the uploaded file.
+      requestBody:
+        required: true
+        content:
+          multipart/form-data:
+            schema:
+              type: object
+              properties:
+                image:
+                  type: string
+                  format: binary
+                  description: The image file to be uploaded
+      responses:
+        '200':
+          description: Image uploaded successfully
+          content:
+            application/json:
+              schema:
+                type: object
+                properties:
+                  public_id:
+                    type: string
+                    example: "sp_project/images/avatar_123"
+                    description: Public Cloudinary ID for the uploaded image
+                  url:
+                    type: string
+                    example: "https://res.cloudinary.com/example/image/upload/v1740000000/sp_project/images/avatar_123.jpg"
+                    description: Direct HTTPS link to the uploaded image
+        '400':
+          description: No image file provided
+          content:
+            application/json:
+              schema:
+                type: object
+                properties:
+                  error:
+                    type: string
+                    example: "Image is required"
path: docs/uploadPhoto.yaml
user: login: coderabbitai[bot]
body: _🛠️ Refactor suggestion_

**Make error message example consistent with implementation.**

The error message example in the 400 response doesn't match the error message in the controller.

Update the error message to match the implementation:

```diff
                  error:
                    type: string
-                    example: "Image is required"
+                    example: "No file provided"
```


<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

`````suggestion
                  error:
                    type: string
                    example: "No file provided"
`````

</details>

<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->

✅ Addressed in commit 341b469
created_at: 2025-04-24T11:55:40Z
author_association: NONE
diff_hunk: @@ -0,0 +1,54 @@
+paths:
+  /upload:
+    post:
+      tags:
+        - Upload
+      summary: Upload a user photo
+      description: Uploads an image to Cloudinary and returns the public ID and secure URL of the uploaded file.
+      requestBody:
+        required: true
+        content:
+          multipart/form-data:
+            schema:
+              type: object
+              properties:
+                image:
+                  type: string
+                  format: binary
+                  description: The image file to be uploaded
+      responses:
+        '200':
+          description: Image uploaded successfully
+          content:
+            application/json:
+              schema:
+                type: object
+                properties:
+                  public_id:
+                    type: string
+                    example: "sp_project/images/avatar_123"
+                    description: Public Cloudinary ID for the uploaded image
+                  url:
+                    type: string
+                    example: "https://res.cloudinary.com/example/image/upload/v1740000000/sp_project/images/avatar_123.jpg"
+                    description: Direct HTTPS link to the uploaded image
path: docs/uploadPhoto.yaml
user: login: coderabbitai[bot]
body: _🛠️ Refactor suggestion_

**Ensure field names in documentation match the implementation.**

The field name in the controller is `result.secure_url` but the documentation uses `url`.

Update the field name to match the implementation:

```diff
                  url:
-                    type: string
-                    example: "https://res.cloudinary.com/example/image/upload/v1740000000/sp_project/images/avatar_123.jpg"
-                    description: Direct HTTPS link to the uploaded image
+                  secure_url:
+                    type: string
+                    example: "https://res.cloudinary.com/example/image/upload/v1740000000/sp_project/images/avatar_123.jpg"
+                    description: Secure HTTPS link to the uploaded image
```


> Committable suggestion skipped: line range outside the PR's diff.

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-04-24T11:55:40Z
author_association: NONE
diff_hunk: @@ -0,0 +1,54 @@
+paths:
+  /upload:
+    post:
+      tags:
+        - Upload
+      summary: Upload a user photo
+      description: Uploads an image to Cloudinary and returns the public ID and secure URL of the uploaded file.
+      requestBody:
+        required: true
+        content:
+          multipart/form-data:
+            schema:
+              type: object
+              properties:
+                image:
+                  type: string
+                  format: binary
+                  description: The image file to be uploaded
+      responses:
path: docs/uploadPhoto.yaml
user: login: coderabbitai[bot]
body: _🛠️ Refactor suggestion_

**Enhance request documentation with file type and size constraints.**

The API specification should clearly document allowed file types and size limitations for better client integration.

Add more detailed constraints to the image property:

```diff
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                image:
                  type: string
                  format: binary
-                  description: The image file to be uploaded
+                  description: |
+                    The image file to be uploaded.
+                    - Allowed formats: JPEG, PNG, GIF, WebP
+                    - Maximum file size: 5MB
+                  maxLength: 5242880 # 5MB in bytes
+              required:
+                - image
```


<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

`````suggestion
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                image:
                  type: string
                  format: binary
                  description: |
                    The image file to be uploaded.
                    - Allowed formats: JPEG, PNG, GIF, WebP
                    - Maximum file size: 5MB
                  maxLength: 5242880 # 5MB in bytes
              required:
                - image
      responses:
`````

</details>

<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-04-24T11:55:40Z
author_association: NONE
diff_hunk: @@ -0,0 +1,54 @@
+paths:
+  /upload:
+    post:
+      tags:
+        - Upload
+      summary: Upload a user photo
+      description: Uploads an image to Cloudinary and returns the public ID and secure URL of the uploaded file.
+      requestBody:
+        required: true
+        content:
+          multipart/form-data:
+            schema:
+              type: object
+              properties:
+                image:
+                  type: string
+                  format: binary
+                  description: The image file to be uploaded
+      responses:
+        '200':
+          description: Image uploaded successfully
+          content:
+            application/json:
+              schema:
+                type: object
+                properties:
+                  public_id:
+                    type: string
+                    example: "sp_project/images/avatar_123"
+                    description: Public Cloudinary ID for the uploaded image
+                  url:
+                    type: string
+                    example: "https://res.cloudinary.com/example/image/upload/v1740000000/sp_project/images/avatar_123.jpg"
+                    description: Direct HTTPS link to the uploaded image
+        '400':
path: docs/uploadPhoto.yaml
user: login: coderabbitai[bot]
body: _⚠️ Potential issue_

**Update response schema to match actual implementation.**

The response schema doesn't match the implementation in the controller, which also includes a `message` field.

Either update this documentation to include the message field or modify the controller to match this specification:

```diff
                properties:
+                  message:
+                    type: string
+                    example: "Image uploaded successfully"
+                    description: Status message
                  public_id:
                    type: string
                    example: "sp_project/images/avatar_123"
                    description: Public Cloudinary ID for the uploaded image
                  url:
                    type: string
                    example: "https://res.cloudinary.com/example/image/upload/v1740000000/sp_project/images/avatar_123.jpg"
                    description: Direct HTTPS link to the uploaded image
```


<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

`````suggestion
                properties:
                  message:
                    type: string
                    example: "Image uploaded successfully"
                    description: Status message
                  public_id:
                    type: string
                    example: "sp_project/images/avatar_123"
                    description: Public Cloudinary ID for the uploaded image
                  url:
                    type: string
                    example: "https://res.cloudinary.com/example/image/upload/v1740000000/sp_project/images/avatar_123.jpg"
                    description: Direct HTTPS link to the uploaded image
        '400':
`````

</details>

<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-04-24T11:55:40Z
author_association: NONE
diff_hunk: @@ -0,0 +1,54 @@
+paths:
+  /upload:
+    post:
+      tags:
+        - Upload
+      summary: Upload a user photo
+      description: Uploads an image to Cloudinary and returns the public ID and secure URL of the uploaded file.
+      requestBody:
path: docs/uploadPhoto.yaml
user: login: coderabbitai[bot]
body: _💡 Verification agent_

<details>
<summary>🧩 Analysis chain</summary>

**Consider documenting authentication requirements.**

The endpoint doesn't specify if authentication is required to upload images, which could lead to security issues if unauthorized users can upload files.

---

🏁 Script executed:

```shell
#!/bin/bash
# Check if authentication middleware is applied to upload routes

echo "Checking authentication for upload routes..."
# Look for route definitions
rg -A 10 -B 10 "upload.*router" --include "*.js"
# Check for any authentication middleware usage
rg "auth.*middleware" --include "*.js"
```

Length of output: 1074

---

To verify whether the `/upload` endpoint is protected, let’s search the codebase for its route definitions and any authentication middleware usages:

---

🏁 Script executed:

```shell
#!/bin/bash
echo "Searching for upload handlers..."
# Look for Express app-level upload handlers
rg -A3 -B3 -g "*.js" "app\.post.*upload"
# Look for router-level upload handlers
rg -A3 -B3 -g "*.js" "router\.post.*upload"

echo "Searching for authentication middleware patterns..."
rg -g "*.js" "authMiddleware"
rg -g "*.js" "authenticate"
rg -g "*.js" "passport"
rg -g "*.js" "jwt"
```

Length of output: 2634

---



</details>

**Enforce and document authentication on the upload endpoint**

The `/upload` route in `src/routes/uploadPhoto.js` is exposed without any authentication middleware, which lets unauthenticated users upload files. To secure it:

• In `src/routes/uploadPhoto.js`, apply your `authMiddleware` before the upload handler:  
```diff
- router.post('/', upload.single('image'), uploadController)
+ router.post(
+   '/', 
+   authMiddleware,         // <-- ensure only authenticated users
+   upload.single('image'),
+   uploadController
+ )
```  
• Update `docs/uploadPhoto.yaml` to declare the security requirement:  
```yaml
/upload:
  post:
    security:
      - bearerAuth: []       # <-- require a bearer token
    tags:
      - Upload
    summary: Upload a user photo
    description: Uploads an image to Cloudinary…
    requestBody:
      …
```  
This guarantees only authorized clients can call the endpoint and keeps the documentation in sync with your implementation.

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-04-24T11:55:41Z
author_association: NONE
diff_hunk: @@ -0,0 +1,49 @@
+const cloudinary = require('../configs/cloudinary')
+const User = require('~/models/user')
+
+const uploadImage = async (buffer) => {
+  return new Promise((resolve, reject) => {
+    const stream = cloudinary.uploader.upload_stream(
+      {
+        use_filename: true,
+        unique_filename: true,
+        overwrite: true,
+        folder: 'sp_project/images',
+        transformation: [
+          { width: 600, crop: 'limit' },
+          { fetch_format: 'auto', quality: 'auto' }
+        ]
+      },
+      (error, result) => {
+        if (error) return reject(error)
+        resolve(result)
+      }
+    )
+
+    stream.end(buffer)
+  })
+}
+
+const uploadController = async (req, res) => {
+  try {
+    if (!req.file) {
+      return res.status(400).json({ code: 'No file provided' })
+    }
+
+    const result = await uploadImage(req.file.buffer)
+
+    const userId = req.user.id
+    await User.findByIdAndUpdate(userId, { photo: result.public_id })
+
path: src/controllers/uploadPhoto.js
user: login: coderabbitai[bot]
body: _🛠️ Refactor suggestion_

**Add error handling for the database update operation.**

The function updates the user's photo in the database but doesn't specifically handle database errors. Consider adding more specific error handling to distinguish between Cloudinary upload errors and database update errors.



```diff
const uploadController = async (req, res) => {
  try {
    if (!req.file) {
      return res.status(400).json({ code: 'No file provided' })
    }

    const result = await uploadImage(req.file.buffer)

    const userId = req.user.id
-   await User.findByIdAndUpdate(userId, { photo: result.public_id })
+   try {
+     const updatedUser = await User.findByIdAndUpdate(
+       userId, 
+       { photo: result.public_id },
+       { new: true, runValidators: true }
+     )
+     
+     if (!updatedUser) {
+       return res.status(404).json({ code: 'User not found' })
+     }
+   } catch (dbError) {
+     console.error('Database update error:', dbError)
+     return res.status(500).json({ code: 'Failed to update user profile' })
+   }
```


<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

`````suggestion
const uploadController = async (req, res) => {
  try {
    if (!req.file) {
      return res.status(400).json({ code: 'No file provided' })
    }

    const result = await uploadImage(req.file.buffer)

    const userId = req.user.id
    try {
      const updatedUser = await User.findByIdAndUpdate(
        userId,
        { photo: result.public_id },
        { new: true, runValidators: true }
      )

      if (!updatedUser) {
        return res.status(404).json({ code: 'User not found' })
      }
    } catch (dbError) {
      console.error('Database update error:', dbError)
      return res.status(500).json({ code: 'Failed to update user profile' })
    }

    // ...rest of your success response...
  } catch (err) {
    console.error('Upload error:', err)
    return res.status(500).json({ code: 'Image upload failed' })
  }
}
`````

</details>

<!-- suggestion_end -->

<!-- This is an auto-generated comment by CodeRabbit -->
created_at: 2025-04-27T21:55:57Z
author_association: NONE
diff_hunk: @@ -0,0 +1,49 @@
+const cloudinary = require('../configs/cloudinary')
+const User = require('~/models/user')
+
+const uploadImage = async (buffer) => {
+  return new Promise((resolve, reject) => {
+    const stream = cloudinary.uploader.upload_stream(
+      {
+        use_filename: true,
path: src/controllers/uploadPhoto.js
user: login: vlad-khrychov
body: Is it good idea to use original  filenames across all users? Or do we rename the received files?
created_at: 2025-04-28T15:16:07Z
author_association: NONE
diff_hunk: @@ -0,0 +1,49 @@
+const cloudinary = require('../configs/cloudinary')
+const User = require('~/models/user')
+
+const uploadImage = async (buffer) => {
+  return new Promise((resolve, reject) => {
+    const stream = cloudinary.uploader.upload_stream(
+      {
+        use_filename: true,
path: src/controllers/uploadPhoto.js
user: login: yrudikov
body: I organized uploads into folders based on User ID.
Each user's photo is saved as a fixed public_id like users/:userId/file_unique_key
created_at: 2025-04-28T20:36:47Z
author_association: CONTRIBUTOR

PR comments:
user: login: coderabbitai[bot]
created_at: 2025-04-24T11:52:30Z
body: <!-- This is an auto-generated comment: summarize by coderabbit.ai -->
<!-- walkthrough_start -->

## Walkthrough

A user photo upload feature has been implemented, enabling clients to upload images via a new `/upload` endpoint. The backend integrates Cloudinary for image storage, with configuration managed through environment variables. The upload process uses the `multer` middleware for handling multipart/form-data, processes images in-memory, and applies transformations before uploading to Cloudinary. The endpoint returns metadata about the uploaded image, such as its public ID and secure URL. Error handling is provided for missing files and internal upload failures. Documentation has been added via an OpenAPI specification, and the necessary dependencies have been updated. Additionally, the multer middleware was refactored to a factory pattern to allow customizable upload configurations.

## Changes

| File(s)                                   | Change Summary                                                                                                   |
|-------------------------------------------|-----------------------------------------------------------------------------------------------------------------|
| docs/uploadPhoto.yaml                     | Added OpenAPI specification for `/upload` endpoint, detailing request, response, and error schemas.             |
| package.json                              | Added `cloudinary` dependency for Cloudinary integration.                                                       |
| src/configs/cloudinary.js                 | Introduced Cloudinary configuration using environment variables; exports configured Cloudinary instance.        |
| src/controllers/uploadPhoto.js            | Added controller for handling image upload, transformation, error handling, and Cloudinary integration.         |
| src/routes/uploadPhoto.js                 | Added Express router for `/upload`, using `multer` for in-memory file upload with MIME type filtering and delegating to upload controller. |
| src/routes/index.js                       | Mounted the new upload photo router at `/upload` in the main application router.                                |
| src/initialization/swaggerSettings.js    | Updated Swagger config to include bearer token authentication scheme for API security.                          |
| src/middlewares/multer.js                 | Refactored multer middleware to a factory function `createUpload` allowing customizable storage, limits, and file filters; exported default and factory. |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant Client
    participant Router
    participant Multer
    participant Controller
    participant Cloudinary

    Client->>Router: POST /upload (multipart/form-data)
    Router->>Multer: Process file upload (field: image)
    Multer->>Controller: Pass req with file buffer
    Controller->>Cloudinary: Upload image buffer (transform, store)
    Cloudinary-->>Controller: Return public_id, secure_url
    Controller-->>Client: Respond with JSON { public_id, secure_url }
    alt Error: No file
        Controller-->>Client: 400 Bad Request
    else Error: Upload failure
        Controller-->>Client: 500 Internal Server Error
    end
```

## Poem

> 🐇  
> A hop, a skip, a photo upload,  
> To Cloudinary’s cloud abode!  
> With routes and configs all in line,  
> Your selfies now will safely shine.  
> Multer’s paws sort every file,  
> And public URLs appear with style—  
> This bunny’s work is done for now,  
> Enjoy your uploads—take a bow!  
> 📸✨

<!-- walkthrough_end -->


---

<details>
<summary>📜 Recent review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between fd27dac5f3bd675f8573945ce9fd9629e601b3ff and 8205d0a30cde9de68611f2c244d572eeb91b459b.

</details>

<details>
<summary>📒 Files selected for processing (1)</summary>

* `src/routes/index.js` (1 hunks)

</details>

<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (1)</summary>

* src/routes/index.js

</details>

</details>
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpETZWaCrKNwSPbABsvkCiQBHbGlcSHFcLzpIACIzACYAVgAWSABJZm5ItgwaemxESh5YfAJIbEz8NHoAd3VYSABhL3xsWngMZ3l2miIqcXwMaMhqtGQHAWZ1XMg5MNgPfMLZClb4AGt8CXRkbm9ffyCQyAxHAUKARgBmDRh5yGZtLAZYTFIUHIpFbAYo9rnUWwoZC4O5VNr9LD4ABmkCh2AwYngAzQXnU8lKDm43HwFFC5WaVXaRHQGHoiDQEiJZQKfF40PgkSKJXwiBucFQUJI1Gw/iBKAyWXYUXyVKaLTaHRcABp0Ixmq0wAJRr8Hm9MPRKUp8PdMGhSNlQjTKT82XduiRetQkVgUc1qshFrTigRgdqzmUKlUour7AR/Br4GhGvKJZ0ZWQXgiqSCFjSeJ8oQyPAw0NwVAz1PBpPwYTH0FjUSmIaaPICU1h3f5KSRqr8sEpcNpfNQ5h46ZqogBVGwAGS4sFwuG4iA4AHpR0Q6tgBBomMxRwBlNM/OIL3CtWRgTsAQTAVwSCTAAAZzqOAEJoBhrACipOPp92PlHVw0Rn0xnAUDI9GhOAIxDIZRpjnA0uF4fhhFEcQpBkeQmCUKhVHULQdHfEwoHZZBUEwP9CFIcg+iiED2C4KhqnsRwHhcGY4MUZQkM0bRdDAQwP1MAxaHwBhEFHfFKloKxnXwDRZDQZgvA4AxomkgwLEgbdUgAgjqCiBwnGo39nleaQjG3Y4a0gAB5bgyG3KxUnsEyGHgRMi2tSBOIYRx2D5bpPlob4oiURMMCpINECJRkrEMhdoEgb9sW6SAAANeM9WhorKUlCjzaJO3ioZGyIU1UAi/AooObB4H8GQuX8PgCDWMg/3mHJ4DsgYSXoW18HtOUsxyV0PQJZrqUKb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EGFCjdf7dRHTeRlJTJbyN3UrfFKzAAN6+g4jbS840yzUyj42E2QAAC+kAAAvJALPZvRZRfLjGtHXZVQ3TWWWqUXJlzZ8B2NxSba3ZRXjNGe+AYOhOyj+NlqZqnjZcRDkKRGgORCFdRDLXRIhGoIxKhCxO/Z+AoKwOoAAPoFyICIMzk1h0CIPly4jMSsQf0ACc5wtAbSUI+DCQUIAA7EeEkJQ3ECQAkBQ2gJcEw2gAABwCB8wJCXBQhxC0DnAUMkAkBUNJBJD4O4OwMQCQCXBJDnACBJBtL4NtK6ZxBQjEOlxJCCNtICCyNtIMBxB6OlycgCAMDUOKNJD0BoRwP4NoBHgCPnAkBHhQhEOsOiBHjJD0NQgJD4MnhMNtKsP8xoDoYuNQgaOJDiMf2qNxAUNzQMDkOXACDEMUPkOsMMOXD4NJAJA/D4OqOKNxD4MkC6ayPcMwiWOSOsOcO0BHhMNHgMBKD4NKB+NtLnDnA8N6MiO0AMN0MkACCENyNeMCDiMSNQAgRIMoNoMkDVhXGIPfi4NAA -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=Space2Study-UA-1355-01/BackEnd-01&utm_content=13):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Generate unit testing code for this file.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai generate unit testing code for this file.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and generate unit testing code.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### CodeRabbit Configuration File (`.coderabbit.yaml`)

- You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository.
- Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json`

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->
author_association: NONE
user: login: sonarqubecloud[bot]
created_at: 2025-04-28T20:34:03Z
body: ## [![Quality Gate Passed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-passed-20px.png 'Quality Gate Passed')](https://sonarcloud.io/dashboard?id=Space2Study-UA-1355-01_BackEnd-01&pullRequest=13) **Quality Gate passed**  
Issues  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 New issues](https://sonarcloud.io/project/issues?id=Space2Study-UA-1355-01_BackEnd-01&pullRequest=13&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/accepted-16px.png '') [0 Accepted issues](https://sonarcloud.io/project/issues?id=Space2Study-UA-1355-01_BackEnd-01&pullRequest=13&issueStatuses=ACCEPTED)

Measures  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0 Security Hotspots](https://sonarcloud.io/project/security_hotspots?id=Space2Study-UA-1355-01_BackEnd-01&pullRequest=13&issueStatuses=OPEN,CONFIRMED&sinceLeakPeriod=true)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=Space2Study-UA-1355-01_BackEnd-01&pullRequest=13&metric=new_coverage&view=list)  
![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/passed-16px.png '') [0.0% Duplication on New Code](https://sonarcloud.io/component_measures?id=Space2Study-UA-1355-01_BackEnd-01&pullRequest=13&metric=new_duplicated_lines_density&view=list)  
  
[See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=Space2Study-UA-1355-01_BackEnd-01&pullRequest=13)


author_association: NONE