feat: add parapharmacy API with MongoDB and N8N setup
- Create parapharmacy-api microservice with Express + Swagger + MongoDB - Add product model with full-text search and deduplication - Add CRUD endpoints and bulk upsert for scrapers - Update docker-compose.yml with MongoDB, N8N, and parapharmacy-api services - Add proxy endpoints in FarmaFinder backend for parapharmacy - Update frontend services to use parapharmacy API - Add Swagger documentation at /api/docs
This commit is contained in:
@@ -778,6 +778,65 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user