refactor(backend): resolve strategy preset legacy client inside repository
Made-with: Cursor
This commit is contained in:
parent
9898289974
commit
b632a0d946
@ -1990,7 +1990,7 @@ export class ApiServer {
|
|||||||
|
|
||||||
this.app.get('/api/marketplace-presets', this.requireAuth, async (_req, res) => {
|
this.app.get('/api/marketplace-presets', this.requireAuth, async (_req, res) => {
|
||||||
try {
|
try {
|
||||||
const presets = await listStrategyPresets(supabaseService);
|
const presets = await listStrategyPresets();
|
||||||
res.json({ presets });
|
res.json({ presets });
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
res.status(500).json({ error: `Failed to load marketplace presets: ${error.message}` });
|
res.status(500).json({ error: `Failed to load marketplace presets: ${error.message}` });
|
||||||
@ -2009,7 +2009,7 @@ export class ApiServer {
|
|||||||
...(req.body || {}),
|
...(req.body || {}),
|
||||||
created_by: authUserId
|
created_by: authUserId
|
||||||
};
|
};
|
||||||
await createStrategyPreset(payload, supabaseService);
|
await createStrategyPreset(payload);
|
||||||
res.status(201).json({ success: true });
|
res.status(201).json({ success: true });
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
res.status(400).json({ error: `Failed to publish preset: ${error.message}` });
|
res.status(400).json({ error: `Failed to publish preset: ${error.message}` });
|
||||||
|
|||||||
@ -2,9 +2,8 @@ import { getContainer } from '@bytelyst/cosmos';
|
|||||||
import { randomUUID } from 'node:crypto';
|
import { randomUUID } from 'node:crypto';
|
||||||
import { config } from '../config/index.js';
|
import { config } from '../config/index.js';
|
||||||
import logger from '../utils/logger.js';
|
import logger from '../utils/logger.js';
|
||||||
import type { supabaseService } from './SupabaseService.js';
|
import { supabaseService } from './SupabaseService.js';
|
||||||
|
|
||||||
type LegacySupabaseService = typeof supabaseService;
|
|
||||||
const PRESET_CONTAINER = 'strategy_presets';
|
const PRESET_CONTAINER = 'strategy_presets';
|
||||||
|
|
||||||
interface StrategyPresetDocument {
|
interface StrategyPresetDocument {
|
||||||
@ -19,11 +18,11 @@ function isCosmosConfigured(): boolean {
|
|||||||
return Boolean(config.COSMOS_ENDPOINT && config.COSMOS_KEY);
|
return Boolean(config.COSMOS_ENDPOINT && config.COSMOS_KEY);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getClient(legacyService?: LegacySupabaseService) {
|
function getLegacyClient() {
|
||||||
return legacyService?.getClient?.() ?? null;
|
return supabaseService.getClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function listStrategyPresets(legacyService?: LegacySupabaseService): Promise<any[]> {
|
export async function listStrategyPresets(): Promise<any[]> {
|
||||||
if (isCosmosConfigured()) {
|
if (isCosmosConfigured()) {
|
||||||
try {
|
try {
|
||||||
const container = getContainer(PRESET_CONTAINER);
|
const container = getContainer(PRESET_CONTAINER);
|
||||||
@ -43,7 +42,7 @@ export async function listStrategyPresets(legacyService?: LegacySupabaseService)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = getClient(legacyService);
|
const client = getLegacyClient();
|
||||||
if (!client) return [];
|
if (!client) return [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -78,7 +77,7 @@ export async function listStrategyPresets(legacyService?: LegacySupabaseService)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createStrategyPreset(payload: Record<string, unknown>, legacyService?: LegacySupabaseService): Promise<void> {
|
export async function createStrategyPreset(payload: Record<string, unknown>): Promise<void> {
|
||||||
if (isCosmosConfigured()) {
|
if (isCosmosConfigured()) {
|
||||||
const container = getContainer(PRESET_CONTAINER);
|
const container = getContainer(PRESET_CONTAINER);
|
||||||
await container.items.upsert<StrategyPresetDocument>({
|
await container.items.upsert<StrategyPresetDocument>({
|
||||||
@ -90,7 +89,7 @@ export async function createStrategyPreset(payload: Record<string, unknown>, leg
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const client = getClient(legacyService);
|
const client = getLegacyClient();
|
||||||
if (!client) {
|
if (!client) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user