🧹 chore: Move direct model usage from PermissionsController to data-schemas
Some checks are pending
Docker Dev Branch Images Build / build (Dockerfile, lc-dev, node) (push) Waiting to run
Docker Dev Branch Images Build / build (Dockerfile.multi, lc-dev-api, api-build) (push) Waiting to run

This commit is contained in:
Danny Avila 2026-03-21 15:20:15 -04:00
parent a78865b5e0
commit 04e65bb21a
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
3 changed files with 47 additions and 80 deletions

View file

@ -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,
};
}