web/website/node/political-identity.mjs

13 lines
1 KiB
JavaScript

import {memberPoliticalOffices} from './member-political-offices.mjs';
// Read projections only: the active office deed and the historical register are
// separate sources. Neither a historical honour nor a title grants permissions.
export async function readPoliticalIdentity(db,target,{clock=Date.now}={}){
const offices=await memberPoliticalOffices(db,target,{clock});
const poldeeds={status:offices.status,records:offices.records};
let register={status:'available',recognitions:[]};
try{
const {results}=await db.prepare(`SELECT DISTINCT t.office,t.kind,t.faction FROM political_election_honours h JOIN political_office_terms t ON t.id=h.term_id AND t.player_uuid=h.player_uuid AND t.kind=h.kind AND t.faction=h.faction WHERE t.user_id=? AND t.outcome='winner' AND t.streak>=3 AND h.earned_at<=?`).bind(target.id,clock()).all();
register.recognitions=results.map(r=>({office:r.office,kind:r.kind,faction:r.faction,title:'Ter Electus'}));
}catch{register={status:'unavailable',recognitions:[]};}
return {poldeeds,register};
}