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.
This commit is contained in:
Danny Avila 2025-05-30 13:13:10 -04:00
parent eb368fcb70
commit 20ad7d52f3
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
46 changed files with 61 additions and 66 deletions

View file

@ -7,7 +7,7 @@ const { createSocialUser, handleExistingUser } = require('./process');
const { isEnabled } = require('~/server/utils');
const socialLogin = require('./socialLogin');
const User = mongoose.models.User;
const User = require('~/db/models').User;
// Mocking external dependencies
jest.mock('jsonwebtoken');

View file

@ -3,7 +3,7 @@ const { logger } = require('@librechat/data-schemas');
const { SystemRoles } = require('librechat-data-provider');
const { Strategy: JwtStrategy, ExtractJwt } = require('passport-jwt');
const User = mongoose.models.User;
const User = require('~/db/models').User;
// JWT strategy
const jwtLogin = () =>

View file

@ -7,7 +7,7 @@ const { createUser, findUser, updateUser } = require('~/models');
const { getBalanceConfig } = require('~/server/services/Config');
const { isEnabled } = require('~/server/utils');
const User = mongoose.models.User;
const User = require('~/db/models').User;
const {
LDAP_URL,

View file

@ -6,7 +6,7 @@ const { isEnabled, checkEmailConfig } = require('~/server/utils');
const { comparePassword } = require('~/models');
const { loginSchema } = require('./validators');
const User = mongoose.models.User;
const User = require('~/db/models').User;
// Unix timestamp for 2024-06-07 15:20:18 Eastern Time
const verificationEnabledTimestamp = 1717788018;

View file

@ -11,7 +11,7 @@ const { getStrategyFunctions } = require('~/server/services/Files/strategies');
const getLogStores = require('~/cache/getLogStores');
const { isEnabled } = require('~/server/utils');
const User = mongoose.models.User;
const User = require('~/db/models').User;
/**
* @typedef {import('openid-client').ClientMetadata} ClientMetadata
@ -38,7 +38,6 @@ class CustomOpenIDStrategy extends OpenIDStrategy {
}
}
const db = require('db/connect');
const { getBalanceConfig } = require('~/server/services/Config');
let crypto;

View file

@ -17,16 +17,6 @@ const mockModels = {
},
};
jest.mock('~/db/connect', () => {
return {
getModels: jest.fn(() => mockModels),
connectDb: jest.fn(),
get models() {
return mockModels;
},
};
});
jest.mock('~/server/services/Config', () => ({
getBalanceConfig: jest.fn(),
}));
@ -132,7 +122,7 @@ describe('setupOpenId', () => {
picture: 'https://example.com/avatar.png',
}),
};
const User = mongoose.models.User;
const User = require('~/db/models').User;
beforeEach(async () => {
// Clear previous mock calls and reset implementations
jest.clearAllMocks();