diff --git a/server.js b/server.js index bd08738..c8b5190 100755 --- a/server.js +++ b/server.js @@ -36,14 +36,13 @@ app.get('/free-access/:shop', (req, res) => { // ── BACKFILL: Re-run fulfillment service + locationId for shops that have null ─ // Hit: GET /admin/fix-location → runs all shops with null locationId // Hit: GET /admin/fix-location/:shop → runs one specific shop -app.get('/admin/fix-location/:shop?', async (req, res) => { - const { createFulfillmentService } = require('./fulfillmentService'); +async function runFixLocation(req, res) { const stores = listTokens(); const targetShop = req.params.shop ? decodeURIComponent(req.params.shop).toLowerCase().trim() : null; const toFix = Object.entries(stores).filter(([shop, record]) => { if (targetShop) return shop === targetShop; - return !record.locationId; // only null locationId shops + return !record.locationId; }); if (toFix.length === 0) { @@ -69,7 +68,10 @@ app.get('/admin/fix-location/:shop?', async (req, res) => { } res.json({ fixed: results.filter(r => r.status === 'fixed').length, total: toFix.length, results }); -}); +} + +app.get('/admin/fix-location', runFixLocation); +app.get('/admin/fix-location/:shop', runFixLocation); // ── PUBLIC CHAT ENDPOINTS (for customer widget) ────────────────────────────── // widget.js MUST be before /chat/:shop — otherwise Express treats "widget.js" as the :shop param