This commit is contained in:
seb
2026-10-03 23:13:40 +02:00
parent 6520665dcf
commit 3b74c12f4e
36 changed files with 3669 additions and 2183 deletions

View File

@@ -0,0 +1,33 @@
import { GET_BY_COMPANYUSER_AND_ID as MSSQL_GET } from '../../providers/mssql/queries/modelconversation.js';
import { GET_BY_COMPANYUSER_AND_ID as SQLITE_GET } from '../../providers/sqlite3/queries/modelconversation.js';
import resolveSelectedCompanyAccess from '../companyuser/resolveSelectedCompanyAccess.js';
import makeRunner from '../runner.js';
import shape from './shape.js';
export default function get(provider) {
const access = resolveSelectedCompanyAccess(provider);
const sql = provider?.dialect === 'sqlite3' ? SQLITE_GET : MSSQL_GET;
/**
* Gets a single model conversation by ID for the user in the selected company.
*
* @param {number} googleAuthId - The id of the Google auth user.
* @param {number} conversationId - The conversation id.
* @param {object} [tx] - Optional transaction to run within.
* @returns {Promise<{id: number, companyuser_id: number, provider: string, model: string, created_at: string, updated_at: string, state: string}>}
* @throws {Error} 'Conversation not found'.
*/
return async (googleAuthId, conversationId, tx) => {
const id = Number(conversationId);
if (!Number.isInteger(id) || id <= 0) {
throw new Error('Conversation not found');
}
const runner = makeRunner(provider, tx);
const { companyuserId } = await access(googleAuthId, runner);
const result = await runner.query(sql, { id, companyuserId });
if (!result.rows[0]) throw new Error('Conversation not found');
return shape(result.rows[0]);
};
}