diff --git a/package.json b/package.json index ce1519a..c55d24b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ipwhitelist", - "version": "0.5.2", + "version": "0.5.3", "description": "IP WhiteList microservice for cloud provider", "main": "server.js", "scripts": { diff --git a/src/api/routes/entries.js b/src/api/routes/entries.js index 7f48a17..b6f62cf 100644 --- a/src/api/routes/entries.js +++ b/src/api/routes/entries.js @@ -37,6 +37,7 @@ function createEntriesRouter({ q }) { // Определить компанию из запроса. // Admin с ?company= → компания по ID. + // User с ?client_id= (мульти-компания) → компания по clientId. // Иначе → компания пользователя (UPSERT). async function resolveCompany(req) { if (req.user.isAdmin && req.query.company) { @@ -48,7 +49,9 @@ function createEntriesRouter({ q }) { if (!c) throw Object.assign(new Error('Company not found'), { status: 404 }); return c; } - return q.getOrCreateCompany(req.user.clientId, req.user.companyName); + // Мульти-компания: если передан client_id — использовать его + const effectiveClientId = req.query.client_id || req.user.clientId; + return q.getOrCreateCompany(effectiveClientId, req.user.companyName); } // GET /api/v1/entries — список записей + лимит diff --git a/ui/routes/entries.js b/ui/routes/entries.js index dcf4860..d1fa99e 100644 --- a/ui/routes/entries.js +++ b/ui/routes/entries.js @@ -27,7 +27,12 @@ function createRouter() { // Суффикс ?company= для API — только числовой ID или пусто function companyQuery(req) { const id = req.query.company || (req.body && req.body.company_id); - return id ? '?company=' + id : ''; + if (id) return '?company=' + id; + // Мульти-компания: передаём активный client_id + if (!req.user.isAdmin && req.user.allClientIds && req.user.allClientIds.length > 1) { + return '?client_id=' + encodeURIComponent(req.user.activeClientId || req.user.clientId); + } + return ''; } // GET / — список записей @@ -69,7 +74,10 @@ function createRouter() { } else { // Обычный пользователь: запрашиваем записи для активной компании const activeClientId = req.user.activeClientId || req.user.clientId; - const er = await api.get('/api/v1/entries', token); + const clientIdParam = req.user.allClientIds && req.user.allClientIds.length > 1 + ? '?client_id=' + encodeURIComponent(activeClientId) + : ''; + const er = await api.get('/api/v1/entries' + clientIdParam, token); entries = er.data.entries || []; limit = er.data.limit || 15; }