mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-20 10:20:15 +01:00
- 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.
26 lines
784 B
JavaScript
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;
|