LibreChat/api/server/controllers/Balance.js
Danny Avila 20ad7d52f3
refactor(db): streamline model imports and remove unused model exports
- Removed the export of models from the database connection module to simplify the structure.
- Updated various files to import models directly from the new centralized models module.
- Ensured consistency across the codebase by replacing mongoose model references with the new import paths.
2025-05-30 13:13:10 -04:00

26 lines
784 B
JavaScript

const mongoose = require('mongoose');
const Balance = require('~/db/models').Balance;
async function balanceController(req, res) {
const balanceData = await Balance.findOne(
{ user: req.user.id },
'-_id tokenCredits autoRefillEnabled refillIntervalValue refillIntervalUnit lastRefill refillAmount',
).lean();
if (!balanceData) {
return res.status(404).json({ error: 'Balance not found' });
}
// If auto-refill is not enabled, remove auto-refill related fields from the response
if (!balanceData.autoRefillEnabled) {
delete balanceData.refillIntervalValue;
delete balanceData.refillIntervalUnit;
delete balanceData.lastRefill;
delete balanceData.refillAmount;
}
res.status(200).json(balanceData);
}
module.exports = balanceController;