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:
@@ -55,21 +55,32 @@ function PublicView({
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
try {
|
||||
const productsResponse = await fetch(`/api/products/search?q=${encodeURIComponent(searchQuery)}`);
|
||||
if (productsResponse.ok) {
|
||||
const productsData = await productsResponse.json();
|
||||
setProducts(productsData.results || []);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Product search error:', err);
|
||||
}
|
||||
// Only search medications from CIMA
|
||||
};
|
||||
|
||||
const timeoutId = setTimeout(searchMedicines, 300);
|
||||
return () => clearTimeout(timeoutId);
|
||||
}, [searchQuery]);
|
||||
|
||||
// Search parapharmacy when user switches to Parafarmacia tab
|
||||
useEffect(() => {
|
||||
if (searchMode !== 'products' || searchQuery.trim().length < 2) return;
|
||||
|
||||
const searchProducts = async () => {
|
||||
try {
|
||||
const response = await fetch(`/api/products/parapharmacy/search?q=${encodeURIComponent(searchQuery)}`);
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
setProducts(data.results || []);
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Parapharmacy search error:', err);
|
||||
}
|
||||
};
|
||||
|
||||
searchProducts();
|
||||
}, [searchMode, searchQuery]);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchPharmacies = async () => {
|
||||
if (!selectedMedicine) {
|
||||
|
||||
@@ -88,24 +88,16 @@ function SearchView({ currentUser, onLoginRequest, initialQuery = '', onNavigate
|
||||
const query = searchQuery.trim();
|
||||
|
||||
try {
|
||||
// Run both searches in parallel for speed
|
||||
const [medicinesRes, productsRes] = await Promise.allSettled([
|
||||
fetch(`/api/medicines/search?q=${encodeURIComponent(query)}`),
|
||||
fetch(`/api/products/search?q=${encodeURIComponent(query)}`),
|
||||
]);
|
||||
// Only search medications from CIMA
|
||||
const medicinesRes = await fetch(`/api/medicines/search?q=${encodeURIComponent(query)}`);
|
||||
|
||||
// Only update if this search is still the current one
|
||||
if (query !== searchQuery.trim()) return;
|
||||
|
||||
if (medicinesRes.status === 'fulfilled' && medicinesRes.value.ok) {
|
||||
const medicinesData = await medicinesRes.value.json();
|
||||
if (medicinesRes.ok) {
|
||||
const medicinesData = await medicinesRes.json();
|
||||
setMedicines(medicinesData);
|
||||
}
|
||||
|
||||
if (productsRes.status === 'fulfilled' && productsRes.value.ok) {
|
||||
const productsData = await productsRes.value.json();
|
||||
setProducts(productsData.results || []);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Search error:', error);
|
||||
} finally {
|
||||
@@ -116,6 +108,26 @@ function SearchView({ currentUser, onLoginRequest, initialQuery = '', onNavigate
|
||||
return () => clearTimeout(timeoutId);
|
||||
}, [searchQuery]);
|
||||
|
||||
// Search parapharmacy when user switches to Parafarmacia tab
|
||||
useEffect(() => {
|
||||
if (searchMode !== 'products' || searchQuery.trim().length < 2) return;
|
||||
|
||||
const searchProducts = async () => {
|
||||
const query = searchQuery.trim();
|
||||
try {
|
||||
const response = await fetch(`/api/products/parapharmacy/search?q=${encodeURIComponent(query)}`);
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
setProducts(data.results || []);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Parapharmacy search error:', error);
|
||||
}
|
||||
};
|
||||
|
||||
searchProducts();
|
||||
}, [searchMode, searchQuery]);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchPharmacies = async () => {
|
||||
if (!selectedMedicine) {
|
||||
|
||||
Reference in New Issue
Block a user