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
+6 -1
View File
@@ -85,7 +85,12 @@ function createRouter() {
if (!companyId) {
// Админ без ?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) {
const includeDeleted = req.query.includeDeleted === 'true' ? '&includeDeleted=true' : '';
const er = await api.get('/api/v1/entries?company=' + ownCo.id + includeDeleted, token);