fixed exchange mappings and added visible column

This commit is contained in:
Boki 2025-06-18 09:29:20 -04:00
parent 4f4f615a62
commit 0bec1eca83
5 changed files with 66 additions and 7 deletions

View file

@ -14,7 +14,7 @@ exchangeRoutes.get('/', async c => {
try {
const postgresClient = getPostgreSQLClient();
// First get all exchanges with counts
// First get all exchanges with counts (only visible ones)
const exchangesQuery = `
SELECT
e.id,
@ -23,6 +23,7 @@ exchangeRoutes.get('/', async c => {
e.country,
e.currency,
e.active,
e.visible,
e.created_at,
e.updated_at,
COUNT(pem.id) as provider_mapping_count,
@ -31,7 +32,8 @@ exchangeRoutes.get('/', async c => {
STRING_AGG(DISTINCT pem.provider, ', ') as providers
FROM exchanges e
LEFT JOIN provider_exchange_mappings pem ON e.id = pem.master_exchange_id
GROUP BY e.id, e.code, e.name, e.country, e.currency, e.active, e.created_at, e.updated_at
WHERE e.visible = true
GROUP BY e.id, e.code, e.name, e.country, e.currency, e.active, e.visible, e.created_at, e.updated_at
ORDER BY e.code
`;
@ -97,8 +99,8 @@ exchangeRoutes.get('/:id', async c => {
const exchangeId = c.req.param('id');
const postgresClient = getPostgreSQLClient();
// Get exchange details
const exchangeQuery = 'SELECT * FROM exchanges WHERE id = $1';
// Get exchange details (only if visible)
const exchangeQuery = 'SELECT * FROM exchanges WHERE id = $1 AND visible = true';
const exchangeResult = await postgresClient.query(exchangeQuery, [exchangeId]);
if (exchangeResult.rows.length === 0) {
@ -169,6 +171,11 @@ exchangeRoutes.patch('/:id', async c => {
values.push(body.currency);
}
if (body.visible !== undefined) {
updateFields.push(`visible = $${paramIndex++}`);
values.push(body.visible);
}
if (updateFields.length === 0) {
return c.json({ success: false, error: 'No valid fields to update' }, 400);
}
@ -189,6 +196,20 @@ exchangeRoutes.patch('/:id', async c => {
return c.json({ success: false, error: 'Exchange not found' }, 404);
}
// If hiding an exchange (visible=false), delete its provider mappings to make them available for remapping
if (body.visible === false) {
const deleteMappingsQuery = `
DELETE FROM provider_exchange_mappings
WHERE master_exchange_id = $1
`;
const mappingsResult = await postgresClient.query(deleteMappingsQuery, [exchangeId]);
logger.info('Deleted provider mappings for hidden exchange', {
exchangeId,
deletedMappings: mappingsResult.rowCount
});
}
logger.info('Exchange updated', { exchangeId, updates: body });
return c.json({