fix: ownCo not found → getOrCreateCompany instead of companies[0]

- Убрал fallback на companies[0] — небезопасно
- Если компания админа не найдена — создаём через getOrCreateCompany
This commit is contained in:
2026-06-11 11:18:59 +04:00
parent 2acad33fd4
commit 1794610f77
2 changed files with 7 additions and 2 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "ipwhitelist", "name": "ipwhitelist",
"version": "0.5.39", "version": "0.5.40",
"description": "IP WhiteList microservice for cloud provider", "description": "IP WhiteList microservice for cloud provider",
"main": "server.js", "main": "server.js",
"scripts": { "scripts": {
+6 -1
View File
@@ -85,7 +85,12 @@ function createRouter() {
if (!companyId) { if (!companyId) {
// Админ без ?company= — показываем свою компанию // Админ без ?company= — показываем свою компанию
const ownCo = companies.find(c => c.client_id === req.user.clientId) || companies[0]; let ownCo = companies.find(c => c.client_id === req.user.clientId) || null;
if (!ownCo) {
await api.get('/api/v1/entries', token); // создаст компанию через getOrCreateCompany
const cr2 = await api.get('/api/v1/companies', token);
ownCo = (cr2.data.companies || []).find(c => c.client_id === req.user.clientId) || null;
}
if (ownCo) { if (ownCo) {
const includeDeleted = req.query.includeDeleted === 'true' ? '&includeDeleted=true' : ''; const includeDeleted = req.query.includeDeleted === 'true' ? '&includeDeleted=true' : '';
const er = await api.get('/api/v1/entries?company=' + ownCo.id + includeDeleted, token); const er = await api.get('/api/v1/entries?company=' + ownCo.id + includeDeleted, token);