Refactor userId handling in cigarettes and stats routes to use mongoose ObjectId for consistency; add debug logging for stats aggregation.

This commit is contained in:
Primakov Alexandr Alexandrovich
2025-11-17 14:04:46 +03:00
parent f6f9163c3f
commit dd75c54b32
2 changed files with 13 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
const { Router } = require('express')
const mongoose = require('mongoose')
const { getAnswer } = require('../../utils/common')
const { CigaretteModel } = require('./model/cigarette')
@@ -27,7 +28,7 @@ router.post('/', async (req, res, next) => {
}
const item = await CigaretteModel.create({
userId: user.id,
userId: new mongoose.Types.ObjectId(user.id),
smokedAt: date,
note,
})
@@ -44,7 +45,7 @@ router.get('/', async (req, res, next) => {
const user = req.user
const { from, to } = req.query
const filter = { userId: user.id }
const filter = { userId: new mongoose.Types.ObjectId(user.id) }
if (from || to) {
filter.smokedAt = {}