feat: admin own company option in dropdown + fix company=own routing + bump 0.4.5
This commit is contained in:
+23
-11
@@ -17,13 +17,16 @@ function createRouter() {
|
||||
// Вычислить URL для возврата (с учётом выбранной компании)
|
||||
function backUrl(req) {
|
||||
const companyId = req.query.company || (req.body && req.body.company_id);
|
||||
return companyId ? '/?company=' + companyId : '/';
|
||||
if (!companyId || companyId === 'own') return '/?company=own';
|
||||
return '/?company=' + companyId;
|
||||
}
|
||||
|
||||
// Суффикс ?company=<id> для вызовов API
|
||||
// 'own' = компания admin без ?company — API использует getOrCreateCompany
|
||||
function companyQuery(req) {
|
||||
const companyId = req.query.company || (req.body && req.body.company_id);
|
||||
return companyId ? '?company=' + companyId : '';
|
||||
if (!companyId || companyId === 'own') return '';
|
||||
return '?company=' + companyId;
|
||||
}
|
||||
|
||||
// GET / — список записей
|
||||
@@ -36,19 +39,28 @@ function createRouter() {
|
||||
const cr = await api.get('/api/v1/companies', token);
|
||||
companies = cr.data.companies || [];
|
||||
|
||||
const companyId = req.query.company ? parseInt(req.query.company, 10) : null;
|
||||
const companyParam = req.query.company || '';
|
||||
const companyId = companyParam && companyParam !== 'own' ? parseInt(companyParam, 10) : null;
|
||||
|
||||
// Если company не выбрана — редиректим на первую в списке
|
||||
if (!companyId && companies.length > 0) {
|
||||
return res.redirect('/?company=' + companies[0].id);
|
||||
// Без параметра — редирект на свою компанию
|
||||
if (!companyParam) {
|
||||
return res.redirect('/?company=own');
|
||||
}
|
||||
|
||||
selectedCompany = companyId ? companies.find(c => c.id === companyId) || null : null;
|
||||
|
||||
if (selectedCompany) {
|
||||
const er = await api.get('/api/v1/entries?company=' + companyId, token);
|
||||
if (companyParam === 'own') {
|
||||
// Собственные записи admin (getOrCreateCompany внутри API)
|
||||
const er = await api.get('/api/v1/entries', token);
|
||||
entries = er.data.entries || [];
|
||||
limit = er.data.limit || selectedCompany.custom_limit || selectedCompany.default_limit || 15;
|
||||
limit = er.data.limit || 15;
|
||||
selectedCompany = { id: 'own', name: 'Моя компания', client_id: req.user.clientId };
|
||||
} else {
|
||||
selectedCompany = companyId ? companies.find(c => c.id === companyId) || null : null;
|
||||
|
||||
if (selectedCompany) {
|
||||
const er = await api.get('/api/v1/entries?company=' + companyId, token);
|
||||
entries = er.data.entries || [];
|
||||
limit = er.data.limit || selectedCompany.custom_limit || selectedCompany.default_limit || 15;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const er = await api.get('/api/v1/entries', token);
|
||||
|
||||
Reference in New Issue
Block a user