mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-03-29 03:47:18 +02:00
🧹 chore: Move direct model usage from PermissionsController to data-schemas
This commit is contained in:
parent
a78865b5e0
commit
04e65bb21a
3 changed files with 47 additions and 80 deletions
|
|
@ -741,19 +741,39 @@ export function createAgentMethods(mongoose: typeof import('mongoose'), deps: Ag
|
|||
return await Agent.countDocuments({ is_promoted: true });
|
||||
}
|
||||
|
||||
/** Removes an agent from the favorites of specified users. */
|
||||
async function removeAgentFromUserFavorites(
|
||||
resourceId: string,
|
||||
userIds: string[],
|
||||
): Promise<void> {
|
||||
const Agent = mongoose.models.Agent as Model<IAgent>;
|
||||
const User = mongoose.models.User as Model<unknown>;
|
||||
|
||||
const agent = await Agent.findOne({ _id: resourceId }, { id: 1 }).lean();
|
||||
if (!agent) {
|
||||
return;
|
||||
}
|
||||
|
||||
await User.updateMany(
|
||||
{ _id: { $in: userIds }, 'favorites.agentId': agent.id },
|
||||
{ $pull: { favorites: { agentId: agent.id } } },
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
createAgent,
|
||||
getAgent,
|
||||
getAgents,
|
||||
createAgent,
|
||||
updateAgent,
|
||||
deleteAgent,
|
||||
deleteUserAgents,
|
||||
revertAgentVersion,
|
||||
countPromotedAgents,
|
||||
addAgentResourceFile,
|
||||
removeAgentResourceFiles,
|
||||
getListAgentsByAccess,
|
||||
removeAgentResourceFiles,
|
||||
generateActionMetadataHash,
|
||||
removeAgentFromUserFavorites,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue