added ability to add exchanges and a custom delete exchange dialog

This commit is contained in:
Boki 2025-06-18 09:41:25 -04:00
parent 0bec1eca83
commit 1d299e52d4
8 changed files with 550 additions and 16 deletions

View file

@ -714,6 +714,98 @@ exchangeRoutes.get('/provider-exchanges/unmapped/:provider', async c => {
}
});
// Create new exchange
exchangeRoutes.post('/', async c => {
try {
const body = await c.req.json();
const postgresClient = getPostgreSQLClient();
const { code, name, country, currency, active = true } = body;
if (!code || !name || !country || !currency) {
return c.json(
{
success: false,
error: 'Missing required fields: code, name, country, currency',
},
400
);
}
// Validate currency is 3 characters
if (currency.length !== 3) {
return c.json(
{
success: false,
error: 'Currency must be exactly 3 characters (e.g., USD, EUR, CAD)',
},
400
);
}
// Validate country is 2 characters
if (country.length !== 2) {
return c.json(
{
success: false,
error: 'Country must be exactly 2 characters (e.g., US, CA, GB)',
},
400
);
}
const query = `
INSERT INTO exchanges (code, name, country, currency, active, visible)
VALUES ($1, $2, $3, $4, $5, true)
RETURNING *
`;
const result = await postgresClient.query(query, [
code.toUpperCase(),
name,
country.toUpperCase(),
currency.toUpperCase(),
active,
]);
logger.info('Exchange created', {
exchangeId: result.rows[0].id,
code,
name,
});
return c.json(
{
success: true,
data: result.rows[0],
message: 'Exchange created successfully',
},
201
);
} catch (error) {
logger.error('Failed to create exchange', { error });
// Handle unique constraint violations
if (error instanceof Error && error.message.includes('duplicate key')) {
return c.json(
{
success: false,
error: 'Exchange with this code already exists',
},
409
);
}
return c.json(
{
success: false,
error: error instanceof Error ? error.message : 'Unknown error',
},
500
);
}
});
// Get exchange statistics
exchangeRoutes.get('/stats/summary', async c => {
try {