mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-20 18:30:15 +01:00
refactor: remove use/mention of mongoose sessions
This commit is contained in:
parent
a4c2bd7278
commit
0a73caf1d8
2 changed files with 12 additions and 18 deletions
|
|
@ -5,17 +5,16 @@ const Action = mongoose.model('action', actionSchema);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update an action with new data without overwriting existing properties,
|
* Update an action with new data without overwriting existing properties,
|
||||||
* or create a new action if it doesn't exist, within a transaction session if provided.
|
* or create a new action if it doesn't exist.
|
||||||
*
|
*
|
||||||
* @param {Object} searchParams - The search parameters to find the action to update.
|
* @param {Object} searchParams - The search parameters to find the action to update.
|
||||||
* @param {string} searchParams.action_id - The ID of the action to update.
|
* @param {string} searchParams.action_id - The ID of the action to update.
|
||||||
* @param {string} searchParams.user - The user ID of the action's author.
|
* @param {string} searchParams.user - The user ID of the action's author.
|
||||||
* @param {Object} updateData - An object containing the properties to update.
|
* @param {Object} updateData - An object containing the properties to update.
|
||||||
* @param {mongoose.ClientSession} [session] - The transaction session to use.
|
|
||||||
* @returns {Promise<Action>} The updated or newly created action document as a plain object.
|
* @returns {Promise<Action>} The updated or newly created action document as a plain object.
|
||||||
*/
|
*/
|
||||||
const updateAction = async (searchParams, updateData, session = null) => {
|
const updateAction = async (searchParams, updateData) => {
|
||||||
const options = { new: true, upsert: true, session };
|
const options = { new: true, upsert: true };
|
||||||
return await Action.findOneAndUpdate(searchParams, updateData, options).lean();
|
return await Action.findOneAndUpdate(searchParams, updateData, options).lean();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -49,31 +48,27 @@ const getActions = async (searchParams, includeSensitive = false) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes an action by params, within a transaction session if provided.
|
* Deletes an action by params.
|
||||||
*
|
*
|
||||||
* @param {Object} searchParams - The search parameters to find the action to delete.
|
* @param {Object} searchParams - The search parameters to find the action to delete.
|
||||||
* @param {string} searchParams.action_id - The ID of the action to delete.
|
* @param {string} searchParams.action_id - The ID of the action to delete.
|
||||||
* @param {string} searchParams.user - The user ID of the action's author.
|
* @param {string} searchParams.user - The user ID of the action's author.
|
||||||
* @param {mongoose.ClientSession} [session] - The transaction session to use (optional).
|
|
||||||
* @returns {Promise<Action>} A promise that resolves to the deleted action document as a plain object, or null if no document was found.
|
* @returns {Promise<Action>} A promise that resolves to the deleted action document as a plain object, or null if no document was found.
|
||||||
*/
|
*/
|
||||||
const deleteAction = async (searchParams, session = null) => {
|
const deleteAction = async (searchParams) => {
|
||||||
const options = session ? { session } : {};
|
return await Action.findOneAndDelete(searchParams).lean();
|
||||||
return await Action.findOneAndDelete(searchParams, options).lean();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes actions by params, within a transaction session if provided.
|
* Deletes actions by params.
|
||||||
*
|
*
|
||||||
* @param {Object} searchParams - The search parameters to find the actions to delete.
|
* @param {Object} searchParams - The search parameters to find the actions to delete.
|
||||||
* @param {string} searchParams.action_id - The ID of the action(s) to delete.
|
* @param {string} searchParams.action_id - The ID of the action(s) to delete.
|
||||||
* @param {string} searchParams.user - The user ID of the action's author.
|
* @param {string} searchParams.user - The user ID of the action's author.
|
||||||
* @param {mongoose.ClientSession} [session] - The transaction session to use (optional).
|
|
||||||
* @returns {Promise<Number>} A promise that resolves to the number of deleted action documents.
|
* @returns {Promise<Number>} A promise that resolves to the number of deleted action documents.
|
||||||
*/
|
*/
|
||||||
const deleteActions = async (searchParams, session = null) => {
|
const deleteActions = async (searchParams) => {
|
||||||
const options = session ? { session } : {};
|
const result = await Action.deleteMany(searchParams);
|
||||||
const result = await Action.deleteMany(searchParams, options);
|
|
||||||
return result.deletedCount;
|
return result.deletedCount;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,17 +5,16 @@ const Assistant = mongoose.model('assistant', assistantSchema);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update an assistant with new data without overwriting existing properties,
|
* Update an assistant with new data without overwriting existing properties,
|
||||||
* or create a new assistant if it doesn't exist, within a transaction session if provided.
|
* or create a new assistant if it doesn't exist.
|
||||||
*
|
*
|
||||||
* @param {Object} searchParams - The search parameters to find the assistant to update.
|
* @param {Object} searchParams - The search parameters to find the assistant to update.
|
||||||
* @param {string} searchParams.assistant_id - The ID of the assistant to update.
|
* @param {string} searchParams.assistant_id - The ID of the assistant to update.
|
||||||
* @param {string} searchParams.user - The user ID of the assistant's author.
|
* @param {string} searchParams.user - The user ID of the assistant's author.
|
||||||
* @param {Object} updateData - An object containing the properties to update.
|
* @param {Object} updateData - An object containing the properties to update.
|
||||||
* @param {mongoose.ClientSession} [session] - The transaction session to use (optional).
|
|
||||||
* @returns {Promise<AssistantDocument>} The updated or newly created assistant document as a plain object.
|
* @returns {Promise<AssistantDocument>} The updated or newly created assistant document as a plain object.
|
||||||
*/
|
*/
|
||||||
const updateAssistantDoc = async (searchParams, updateData, session = null) => {
|
const updateAssistantDoc = async (searchParams, updateData) => {
|
||||||
const options = { new: true, upsert: true, session };
|
const options = { new: true, upsert: true };
|
||||||
return await Assistant.findOneAndUpdate(searchParams, updateData, options).lean();
|
return await Assistant.findOneAndUpdate(searchParams, updateData, options).lean();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue