web/website/node/member-political-offices.mjs

11 lines
864 B
JavaScript

import {readGovernmentOffices} from './public-government.mjs';
// Display only the same unambiguous, active elected terms as Government.
// Recognition ranks and expiring forum caches cannot establish current office.
export async function memberPoliticalOffices(db,target,{clock=Date.now}={}){
const observedAt=clock();
try{
const offices=await readGovernmentOffices(db,observedAt),username=target.username.toLowerCase();
const records=offices.filter(office=>office.holder?.username.toLowerCase()===username).map(office=>({key:office.key,label:office.name,scope:office.scope,office:office.office,faction:office.faction,seal:'https://www.dunerealms.com/assets/seals/'+office.art,startsAt:office.term.startsAt,expiresAt:office.term.expiresAt}));
return {status:'available',records,observedAt};
}catch{return {status:'unavailable',records:[],observedAt};}
}