Feat/parapharmacy api #38

Merged
Ichitux merged 25 commits from feat/parapharmacy-api into main 2026-07-16 15:38:59 +00:00
Showing only changes of commit 972a59662d - Show all commits
+60 -59
View File
@@ -5,6 +5,7 @@ if (process.env.NODE_ENV !== 'test') {
}
import express from 'express';
import axios from 'axios';
import redisClient from './redis-client.js';
import * as appMetrics from './src/metrics.js';
import cors from 'cors';
@@ -679,6 +680,65 @@ app.get('/api/medicines/:medicineId', async (req, res) => {
}
});
// ========== PARAPHARMACY PROXY ==========
const PARAPHARMACY_API_URL = process.env.PARAPHARMACY_API_URL || 'http://localhost:3002';
// Search parapharmacy products (proxy to parapharmacy-api)
app.get('/api/products/parapharmacy/search', searchLimiter, async (req, res) => {
try {
const { q, category, brand, page = 1, limit = 20 } = req.query;
const params = new URLSearchParams();
if (q) params.set('q', q);
if (category) params.set('category', category);
if (brand) params.set('brand', brand);
params.set('page', page);
params.set('limit', limit);
const response = await axios.get(`${PARAPHARMACY_API_URL}/api/products/search?${params}`);
res.json(response.data);
} catch (error) {
console.error('[Parapharmacy] Search error:', error.message);
res.status(500).json({ error: 'Error searching parapharmacy products' });
}
});
// Get parapharmacy product details (proxy to parapharmacy-api)
app.get('/api/products/parapharmacy/:id', async (req, res) => {
try {
const response = await axios.get(`${PARAPHARMACY_API_URL}/api/products/${req.params.id}`);
res.json(response.data);
} catch (error) {
console.error('[Parapharmacy] Detail error:', error.message);
if (error.response?.status === 404) {
return res.status(404).json({ error: 'Product not found' });
}
res.status(500).json({ error: 'Error fetching product details' });
}
});
// Get parapharmacy categories (proxy to parapharmacy-api)
app.get('/api/products/parapharmacy/categories', async (req, res) => {
try {
const response = await axios.get(`${PARAPHARMACY_API_URL}/api/products/categories`);
res.json(response.data);
} catch (error) {
console.error('[Parapharmacy] Categories error:', error.message);
res.status(500).json({ error: 'Error fetching categories' });
}
});
// Get parapharmacy brands (proxy to parapharmacy-api)
app.get('/api/products/parapharmacy/brands', async (req, res) => {
try {
const response = await axios.get(`${PARAPHARMACY_API_URL}/api/products/brands`);
res.json(response.data);
} catch (error) {
console.error('[Parapharmacy] Brands error:', error.message);
res.status(500).json({ error: 'Error fetching brands' });
}
});
// ========== OTC PRODUCT SEARCH (CIMA only) ==========
app.get('/api/products/search', searchLimiter, async (req, res) => {
@@ -765,65 +825,6 @@ app.get('/api/products/:source/:productId/pharmacies', async (req, res) => {
}
});
// ========== PARAPHARMACY PROXY ==========
const PARAPHARMACY_API_URL = process.env.PARAPHARMACY_API_URL || 'http://localhost:3002';
// Search parapharmacy products (proxy to parapharmacy-api)
app.get('/api/products/parapharmacy/search', searchLimiter, async (req, res) => {
try {
const { q, category, brand, page = 1, limit = 20 } = req.query;
const params = new URLSearchParams();
if (q) params.set('q', q);
if (category) params.set('category', category);
if (brand) params.set('brand', brand);
params.set('page', page);
params.set('limit', limit);
const response = await axios.get(`${PARAPHARMACY_API_URL}/api/products/search?${params}`);
res.json(response.data);
} catch (error) {
console.error('[Parapharmacy] Search error:', error.message);
res.status(500).json({ error: 'Error searching parapharmacy products' });
}
});
// Get parapharmacy product details (proxy to parapharmacy-api)
app.get('/api/products/parapharmacy/:id', async (req, res) => {
try {
const response = await axios.get(`${PARAPHARMACY_API_URL}/api/products/${req.params.id}`);
res.json(response.data);
} catch (error) {
console.error('[Parapharmacy] Detail error:', error.message);
if (error.response?.status === 404) {
return res.status(404).json({ error: 'Product not found' });
}
res.status(500).json({ error: 'Error fetching product details' });
}
});
// Get parapharmacy categories (proxy to parapharmacy-api)
app.get('/api/products/parapharmacy/categories', async (req, res) => {
try {
const response = await axios.get(`${PARAPHARMACY_API_URL}/api/products/categories`);
res.json(response.data);
} catch (error) {
console.error('[Parapharmacy] Categories error:', error.message);
res.status(500).json({ error: 'Error fetching categories' });
}
});
// Get parapharmacy brands (proxy to parapharmacy-api)
app.get('/api/products/parapharmacy/brands', async (req, res) => {
try {
const response = await axios.get(`${PARAPHARMACY_API_URL}/api/products/brands`);
res.json(response.data);
} catch (error) {
console.error('[Parapharmacy] Brands error:', error.message);
res.status(500).json({ error: 'Error fetching brands' });
}
});
// ========== AUTHENTICATION MIDDLEWARE ==========
// Middleware to check if user is authenticated