chore: remove Open Food Facts (OFF) integration
- Remove off-service.js and off-service.test.js - Remove OFF import from server.js - Simplify /api/products/search to only use CIMA - Remove 'openfoodfacts' from valid product sources - Update frontend-mobile Product interface to remove OFF source - Remove OFF env vars from .env.example - Add PARAPHARMACY_API_URL to .env.example OFF was replaced by the new parapharmacy-api microservice.
This commit is contained in:
+8
-21
@@ -23,7 +23,6 @@ import pino from 'pino';
|
||||
import pinoHttp from 'pino-http';
|
||||
import multer from 'multer';
|
||||
import { searchMedicines, getMedicineDetails, searchOTC } from './cima-service.js';
|
||||
import { searchBabyProducts, getBabyProductDetails } from './off-service.js';
|
||||
import { runFarmaciaWebhookImport, DEFAULT_FARMACIAS_WEBHOOK, importPharmaciesFromRows } from './farmacias-webhook-import.js';
|
||||
import { fetchPharmaciesExternal } from '../API/index.js';
|
||||
|
||||
@@ -680,7 +679,7 @@ app.get('/api/medicines/:medicineId', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// ========== UNIFIED PRODUCT SEARCH ==========
|
||||
// ========== OTC PRODUCT SEARCH (CIMA only) ==========
|
||||
|
||||
app.get('/api/products/search', searchLimiter, async (req, res) => {
|
||||
try {
|
||||
@@ -689,18 +688,11 @@ app.get('/api/products/search', searchLimiter, async (req, res) => {
|
||||
return res.json({ results: [], total: 0 });
|
||||
}
|
||||
const searchTerm = q.trim();
|
||||
const [cimaResults, offResults] = await Promise.allSettled([
|
||||
searchOTC(searchTerm),
|
||||
searchBabyProducts(searchTerm)
|
||||
]);
|
||||
const cimaProducts = cimaResults.status === 'fulfilled' ? cimaResults.value : [];
|
||||
const offProducts = offResults.status === 'fulfilled' ? offResults.value : [];
|
||||
const allProducts = [...cimaProducts, ...offProducts]
|
||||
.sort((a, b) => a.name.localeCompare(b.name));
|
||||
const cimaProducts = await searchOTC(searchTerm);
|
||||
res.json({
|
||||
results: allProducts,
|
||||
total: allProducts.length,
|
||||
sources: { cima: cimaProducts.length, openfoodfacts: offProducts.length }
|
||||
results: cimaProducts,
|
||||
total: cimaProducts.length,
|
||||
sources: { cima: cimaProducts.length }
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('[Products] Search error:', err);
|
||||
@@ -716,11 +708,6 @@ app.get('/api/products/:source/:id', async (req, res) => {
|
||||
if (!product) return res.status(404).json({ error: 'Product not found' });
|
||||
return res.json({ ...product, source: 'cima', category: 'otc' });
|
||||
}
|
||||
if (source === 'openfoodfacts') {
|
||||
const product = await getBabyProductDetails(id);
|
||||
if (!product) return res.status(404).json({ error: 'Product not found' });
|
||||
return res.json(product);
|
||||
}
|
||||
res.status(400).json({ error: 'Invalid source' });
|
||||
} catch (err) {
|
||||
console.error('[Products] Detail error:', err);
|
||||
@@ -733,7 +720,7 @@ app.get('/api/products/:source/:productId/pharmacies', async (req, res) => {
|
||||
try {
|
||||
const { source, productId } = req.params;
|
||||
|
||||
if (source !== 'cima' && source !== 'openfoodfacts') {
|
||||
if (source !== 'cima') {
|
||||
return res.status(400).json({ error: 'Invalid source' });
|
||||
}
|
||||
|
||||
@@ -2137,8 +2124,8 @@ app.post('/api/admin/pharmacy-products', requireAdmin, async (req, res) => {
|
||||
return res.status(400).json({ error: 'pharmacy_id, product_source, and product_off_id are required' });
|
||||
}
|
||||
|
||||
if (product_source !== 'cima' && product_source !== 'openfoodfacts') {
|
||||
return res.status(400).json({ error: 'product_source must be "cima" or "openfoodfacts"' });
|
||||
if (product_source !== 'cima') {
|
||||
return res.status(400).json({ error: 'product_source must be "cima"' });
|
||||
}
|
||||
|
||||
const existing = await userDbGet(
|
||||
|
||||
Reference in New Issue
Block a user