|
@@ -57,6 +57,9 @@ import { CouncilCandidacyNoteMetadata } from '@joystream/metadata-protobuf'
|
|
|
|
|
|
/////////////////// Common - Gets //////////////////////////////////////////////
|
|
/////////////////// Common - Gets //////////////////////////////////////////////
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ Retrieves the member record by its id.
|
|
|
|
+*/
|
|
async function getMembership(store: DatabaseManager, memberId: string): Promise<Membership> {
|
|
async function getMembership(store: DatabaseManager, memberId: string): Promise<Membership> {
|
|
// TODO: is this enough to load existing membership? this technic was adpoted from forum mappings (`forum.ts`)
|
|
// TODO: is this enough to load existing membership? this technic was adpoted from forum mappings (`forum.ts`)
|
|
const member = new Membership({ id: memberId })
|
|
const member = new Membership({ id: memberId })
|
|
@@ -64,6 +67,10 @@ async function getMembership(store: DatabaseManager, memberId: string): Promise<
|
|
return member
|
|
return member
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ Retrieves the council candidate by its member id. Returns the last record for the member
|
|
|
|
+ if the election round isn't explicitly set.
|
|
|
|
+*/
|
|
async function getCandidate(
|
|
async function getCandidate(
|
|
store: DatabaseManager,
|
|
store: DatabaseManager,
|
|
memberId: string,
|
|
memberId: string,
|
|
@@ -83,6 +90,9 @@ async function getCandidate(
|
|
return candidate
|
|
return candidate
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ Retrieves the member's last council member record.
|
|
|
|
+*/
|
|
async function getCouncilMember(store: DatabaseManager, memberId: string): Promise<CouncilMember> {
|
|
async function getCouncilMember(store: DatabaseManager, memberId: string): Promise<CouncilMember> {
|
|
const councilMember = await store.get(CouncilMember, {
|
|
const councilMember = await store.get(CouncilMember, {
|
|
where: { memberId: memberId },
|
|
where: { memberId: memberId },
|
|
@@ -96,6 +106,9 @@ async function getCouncilMember(store: DatabaseManager, memberId: string): Promi
|
|
return councilMember
|
|
return councilMember
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ Returns the current election round record.
|
|
|
|
+*/
|
|
async function getCurrentElectionRound(store: DatabaseManager): Promise<ElectionRound> {
|
|
async function getCurrentElectionRound(store: DatabaseManager): Promise<ElectionRound> {
|
|
const electionRound = await store.get(ElectionRound, { order: { id: 'DESC' } })
|
|
const electionRound = await store.get(ElectionRound, { order: { id: 'DESC' } })
|
|
|
|
|
|
@@ -106,6 +119,9 @@ async function getCurrentElectionRound(store: DatabaseManager): Promise<Election
|
|
return electionRound
|
|
return electionRound
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ Returns the last council stage update.
|
|
|
|
+*/
|
|
async function getCurrentStageUpdate(store: DatabaseManager): Promise<CouncilStageUpdate> {
|
|
async function getCurrentStageUpdate(store: DatabaseManager): Promise<CouncilStageUpdate> {
|
|
const stageUpdate = await store.get(CouncilStageUpdate, { order: { id: 'DESC' } })
|
|
const stageUpdate = await store.get(CouncilStageUpdate, { order: { id: 'DESC' } })
|
|
|
|
|
|
@@ -116,6 +132,9 @@ async function getCurrentStageUpdate(store: DatabaseManager): Promise<CouncilSta
|
|
return stageUpdate
|
|
return stageUpdate
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ Returns current elected council record.
|
|
|
|
+*/
|
|
async function getCurrentElectedCouncil(
|
|
async function getCurrentElectedCouncil(
|
|
store: DatabaseManager,
|
|
store: DatabaseManager,
|
|
canFail: boolean = false
|
|
canFail: boolean = false
|
|
@@ -129,6 +148,10 @@ async function getCurrentElectedCouncil(
|
|
return electedCouncil
|
|
return electedCouncil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ Returns the last vote cast in an election by the given account. Returns the last record for the account
|
|
|
|
+ if the election round isn't explicitly set.
|
|
|
|
+*/
|
|
async function getAccountCastVote(
|
|
async function getAccountCastVote(
|
|
store: DatabaseManager,
|
|
store: DatabaseManager,
|
|
account: string,
|
|
account: string,
|
|
@@ -139,7 +162,7 @@ async function getAccountCastVote(
|
|
where.electionRound = electionRound
|
|
where.electionRound = electionRound
|
|
}
|
|
}
|
|
|
|
|
|
- const castVote = await store.get(CastVote, { where })
|
|
|
|
|
|
+ const castVote = await store.get(CastVote, { where, order: { id: 'DESC' } })
|
|
|
|
|
|
if (!castVote) {
|
|
if (!castVote) {
|
|
throw new Error(
|
|
throw new Error(
|
|
@@ -158,12 +181,18 @@ function calculateVotePower(accountId: string, stake: BN): BN {
|
|
return stake
|
|
return stake
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ Custom typeguard for council stage - election.
|
|
|
|
+*/
|
|
function isCouncilStageElection(councilStage: typeof CouncilStage): councilStage is CouncilStageElection {
|
|
function isCouncilStageElection(councilStage: typeof CouncilStage): councilStage is CouncilStageElection {
|
|
return councilStage.isTypeOf == 'CouncilStageElection'
|
|
return councilStage.isTypeOf == 'CouncilStageElection'
|
|
}
|
|
}
|
|
|
|
|
|
/////////////////// Common /////////////////////////////////////////////////////
|
|
/////////////////// Common /////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ Creates new council stage update record.
|
|
|
|
+*/
|
|
async function updateCouncilStage(
|
|
async function updateCouncilStage(
|
|
store: DatabaseManager,
|
|
store: DatabaseManager,
|
|
councilStage: typeof CouncilStage,
|
|
councilStage: typeof CouncilStage,
|
|
@@ -189,6 +218,9 @@ async function updateCouncilStage(
|
|
await store.save<ElectedCouncil>(electedCouncil)
|
|
await store.save<ElectedCouncil>(electedCouncil)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ Concludes current election round and starts the next one.
|
|
|
|
+*/
|
|
async function startNextElectionRound(
|
|
async function startNextElectionRound(
|
|
store: DatabaseManager,
|
|
store: DatabaseManager,
|
|
electedCouncil: ElectedCouncil,
|
|
electedCouncil: ElectedCouncil,
|
|
@@ -217,6 +249,9 @@ async function startNextElectionRound(
|
|
return electionRound
|
|
return electionRound
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ Converts successful council candidate records to council member records.
|
|
|
|
+*/
|
|
async function convertCandidatesToCouncilMembers(
|
|
async function convertCandidatesToCouncilMembers(
|
|
store: DatabaseManager,
|
|
store: DatabaseManager,
|
|
candidates: Candidate[],
|
|
candidates: Candidate[],
|
|
@@ -363,7 +398,6 @@ export async function council_NewCandidate({ event, store }: EventContext & Stor
|
|
stakeLocked: true,
|
|
stakeLocked: true,
|
|
candidacyWithdrawn: false,
|
|
candidacyWithdrawn: false,
|
|
votePower: new BN(0),
|
|
votePower: new BN(0),
|
|
- note: '', // note is empty before explicitely set
|
|
|
|
noteMetadata,
|
|
noteMetadata,
|
|
})
|
|
})
|
|
await store.save<Candidate>(candidate)
|
|
await store.save<Candidate>(candidate)
|
|
@@ -513,17 +547,12 @@ export async function council_CandidacyNoteSet({ event, store }: EventContext &
|
|
const candidacyNoteSetEvent = new CandidacyNoteSetEvent({
|
|
const candidacyNoteSetEvent = new CandidacyNoteSetEvent({
|
|
...genericEventFields(event),
|
|
...genericEventFields(event),
|
|
member,
|
|
member,
|
|
- note: bytesToString(note),
|
|
|
|
noteMetadata,
|
|
noteMetadata,
|
|
})
|
|
})
|
|
|
|
|
|
await store.save<CandidacyNoteSetEvent>(candidacyNoteSetEvent)
|
|
await store.save<CandidacyNoteSetEvent>(candidacyNoteSetEvent)
|
|
|
|
|
|
- // specific event processing
|
|
|
|
-
|
|
|
|
- // update candidacy note
|
|
|
|
- candidate.note = bytesToString(note)
|
|
|
|
- await store.save<Candidate>(candidate)
|
|
|
|
|
|
+ // no specific event processing
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|