forked from unimatrix/web
Connect Company dashboard application counts and direct review navigation
This commit is contained in:
parent
2ada1b5ec1
commit
f3c494cf58
1 changed files with 3 additions and 2 deletions
|
|
@ -11,7 +11,7 @@ export function createCompanyWorkspace(db,{authenticate=request=>identity(reques
|
|||
const extra=db.companyDeedsEnabled?' OR EXISTS(SELECT 1 FROM site_company_members m WHERE m.company_id=c.id AND m.user_id=?)':'';
|
||||
const {results=[]}=await db.prepare('SELECT c.id,c.slug,c.name,c.description,c.status,c.founded_by,c.ceo_account_id,a.username ceo_name,f.username founder_name FROM corrino_companies c LEFT JOIN site_accounts a ON a.id=c.ceo_account_id LEFT JOIN site_accounts f ON f.id=c.founded_by WHERE ('+ownerSource+' OR c.ceo_account_id=?'+extra+')'+(db.companyDeedsEnabled?" AND c.status IN ('active','pending')":'')+' ORDER BY c.name LIMIT 100').bind(user.id,user.id,...(db.companyDeedsEnabled?[user.id]:[])).all();
|
||||
let companies=results.map(({founded_by,ceo_account_id,...company})=>({...company,role:founded_by===user.id?'Founder':'CEO'}));
|
||||
if(db.companyDeedsEnabled)companies=await Promise.all(companies.map(async c=>({...c,...companyDeedView(await readCompanyDeed(db,c.id),user.id)})));
|
||||
if(db.companyDeedsEnabled)companies=await Promise.all(companies.map(async c=>{const view=companyDeedView(await readCompanyDeed(db,c.id),user.id),requests=view.canManage?(await db.prepare("SELECT a.username FROM site_company_requests r JOIN site_jarvis_company_applications j ON j.company_id=r.company_id AND j.user_id=r.user_id JOIN site_accounts a ON a.id=r.user_id WHERE r.company_id=? AND r.status='pending' ORDER BY r.created_at LIMIT 101").bind(c.id).all()).results:[];return{...c,...view,canReview:view.canManage,requests};}));
|
||||
if(id&&!companies.some(c=>c.id===id))return reply({message:'This company is not available to your account.'},404);
|
||||
return reply({companies,selected:id||companies[0]?.id||null});
|
||||
};}
|
||||
|
|
|
|||
Loading…
Reference in a new issue

Staff