Dashboard
🔥
Iste'mol qilingan
0kkal
🎯
Kunlik maqsad
2000kkal
Qoldi
2000kkal
💪
Jami oqsil
0g
Makroelementlar
🔥 Kaloriya 0 / 2000 kkal
🥩 Oqsil (Protein) 0 / 50g
🥑 Yog' (Fat) 0 / 65g
🍞 Uglevod (Carbs) 0 / 250g
📉 Haftalik vazn grafigi
Haftalik vazn: Du 75kg, Se 74.5, Ch 74.8, Pa 74.2, Ju 73.9, Sh 73.5, Ya 73.2
🍱 Bugungi ovqatlar
🥣
Hali ovqat qo'shilmagan
Taom qo'shish →
Avval yuqoridan taom tanlang
👤 Shaxsiy ma'lumotlar
Mifflin-St Jeor formulasi
📐 Formula haqida

Mifflin-St Jeor formulasi — bugungi kunda eng aniq BMR (Basal Metabolik Darajasi) hisoblash usuli hisoblanadi.

Erkak: (10×vazn) + (6.25×bo'y) − (5×yosh) + 5
Ayol: (10×vazn) + (6.25×bo'y) − (5×yosh) − 161
TDEE = BMR × faollik koeffitsiyenti
💧 Suv me'yori
Kunlik suv:
Hisoblash: vazn × 0.033 litr
⚖️ BMI
BMI:
Normal: 18.5–24.9 | Ortiqcha: 25–29.9
📄 User Schema — models/User.js
const UserSchema = new Schema({
  name:     { type: String,  required: true },
  email:    { type: String,  unique: true },
  password: { type: String,  required: true },
  age:      { type: Number },
  height:   { type: Number },  // sm
  weight:   { type: Number },  // kg
  gender:   { type: String,
    enum: ['male', 'female'] },
  activity: { type: Number, default: 1.55 },
  goal:     { type: Number, default: 0 },
  dailyGoal:{ type: Number, default: 2000 },
  createdAt:{ type: Date,
    default: Date.now }
});
🍱 Food Schema — models/Food.js
const FoodSchema = new Schema({
  name:    { type: String, required: true },
  nameUz:  { type: String },
  category:{ type: String },
  isLocal: { type: Boolean, default: true },
  per100g: {
    kcal:    Number,
    protein: Number,
    fat:     Number,
    carbs:   Number
  }
});
📋 DailyLog Schema — models/DailyLog.js
const EntrySchema = new Schema({
  foodId:  { type: ObjectId, ref: 'Food' },
  name:    String,
  grams:   Number,
  kcal:    Number,
  protein: Number,
  fat:     Number,
  carbs:   Number
});

const DailyLogSchema = new Schema({
  userId: { type: ObjectId,
    ref: 'User', required: true },
  date:  { type: String, required: true },
  // format: 'YYYY-MM-DD'
  foods: [EntrySchema],
  totalKcal:    { type: Number, default: 0 },
  totalProtein: { type: Number, default: 0 },
  totalFat:     { type: Number, default: 0 },
  totalCarbs:   { type: Number, default: 0 },
  weight: { type: Number },
  notes:  { type: String }
});
🔗 MongoDB ulanish — config/db.js
const mongoose = require('mongoose');

const connectDB = async () => {
  try {
    await mongoose.connect(
      process.env.MONGO_URI
    );
    console.log('MongoDB ulandi ✓');
  } catch (err) {
    console.error(err.message);
    process.exit(1);
  }
};

module.exports = connectDB;
POST   /api/log/add-food — Ovqat qo'shish
// Body: { userId, date, food: { foodId, grams } }
router.post('/add-food', auth, async (req, res) => {
  const { userId, date, food } = req.body;
  const foodDoc = await Food.findById(food.foodId);
  const ratio = food.grams / 100;

  const entry = {
    foodId:  food.foodId,
    name:    foodDoc.name,
    grams:   food.grams,
    kcal:    Math.round(foodDoc.per100g.kcal    * ratio),
    protein: +(foodDoc.per100g.protein * ratio).toFixed(1),
    fat:     +(foodDoc.per100g.fat     * ratio).toFixed(1),
    carbs:   +(foodDoc.per100g.carbs   * ratio).toFixed(1),
  };

  const log = await DailyLog.findOneAndUpdate(
    { userId, date },
    { $push: { foods: entry },
      $inc: { totalKcal: entry.kcal,
               totalProtein: entry.protein,
               totalFat: entry.fat,
               totalCarbs: entry.carbs } },
    { upsert: true, new: true }
  );
  res.json({ success: true, log });
});
GET   /api/log/:userId/:date
router.get(
  '/:userId/:date', auth,
  async (req, res) => {
    const log = await
      DailyLog.findOne({
        userId: req.params.userId,
        date:   req.params.date
      });
    res.json(log || {
      foods: [],
      totalKcal: 0
    });
});
PUT   /api/user/profile
router.put(
  '/profile', auth,
  async (req, res) => {
    const { weight, height,
      age, gender,
      activity, goal } = req.body;

    let bmr = gender === 'male'
      ? (10*weight) +
        (6.25*height) -
        (5*age) + 5
      : (10*weight) +
        (6.25*height) -
        (5*age) - 161;

    const dailyGoal =
      Math.round(bmr*activity)
      + Number(goal);

    const user = await
      User.findByIdAndUpdate(
        req.user.id,
        { ...req.body, dailyGoal },
        { new: true }
      );
    res.json({ user, dailyGoal });
});
POST   /api/auth/register
router.post(
  '/register',
  async (req, res) => {
    const { name, email,
      password } = req.body;
    const hashed = await
      bcrypt.hash(password, 10);
    const user = new User({
      name, email,
      password: hashed
    });
    await user.save();
    res.json({
      token: jwt.sign(
        { id: user._id },
        process.env.JWT_SECRET)
    });
});
DEL   /api/log/remove-food
router.delete(
  '/remove-food', auth,
  async (req, res) => {
    const { userId, date,
      entryId } = req.body;
    const log = await
      DailyLog.findOneAndUpdate(
        { userId, date },
        { $pull: {
          foods: { _id: entryId }
        }},
        { new: true }
      );
    // totalKcal ni qayta hisoblash
    log.totalKcal = log.foods
      .reduce((s,f) =>
        s + f.kcal, 0);
    await log.save();
    res.json({ success: true });
});
Qo'shildi!