This commit is contained in:
MOHAN 2026-07-02 23:56:55 +05:30
parent fb7d447648
commit ef1a963c7f

View File

@ -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