mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-08 03:28:51 +01:00
refactor: get balance config primarily from appConfig
This commit is contained in:
parent
d853c10920
commit
1d2be247cf
11 changed files with 89 additions and 79 deletions
|
|
@ -5,7 +5,7 @@ import type { Model } from 'mongoose';
|
|||
import type { BalanceUpdateFields } from '~/types';
|
||||
|
||||
export interface BalanceMiddlewareOptions {
|
||||
getBalanceConfig: () => Promise<BalanceConfig | null>;
|
||||
getBalanceConfig: ({ role }?: { role?: string }) => Promise<BalanceConfig | null>;
|
||||
Balance: Model<IBalance>;
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +82,8 @@ export function createSetBalanceConfig({
|
|||
) => Promise<void> {
|
||||
return async (req: ServerRequest, res: ServerResponse, next: NextFunction): Promise<void> => {
|
||||
try {
|
||||
const balanceConfig = await getBalanceConfig();
|
||||
const user = req.user as IUser & { _id: string | ObjectId };
|
||||
const balanceConfig = await getBalanceConfig({ role: user?.role });
|
||||
if (!balanceConfig?.enabled) {
|
||||
return next();
|
||||
}
|
||||
|
|
@ -90,7 +91,6 @@ export function createSetBalanceConfig({
|
|||
return next();
|
||||
}
|
||||
|
||||
const user = req.user as IUser & { _id: string | ObjectId };
|
||||
if (!user || !user._id) {
|
||||
return next();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue