mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-27 06:13:06 +00:00
Add baseUpdatedAt CAS for declareVotes, municipalityUpdate, political trend, engagement level, and advisors. Sibling outbox executor wires hybrid controls when OPS_HYBRID is on; flag OFF keeps legacy paths. Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
49 lines
1.7 KiB
TypeScript
49 lines
1.7 KiB
TypeScript
import type { OpsLeadership, OpsMunicipality, OpsVotePledge } from '@/lib/campaignOps/opsContract'
|
|
import {
|
|
toVoteEstimateScenarioViewModel,
|
|
type VoteEstimateScenarioViewModel,
|
|
} from '@/lib/voteEstimate'
|
|
|
|
/** Mirror→panel row — structural match for `StaffPledgeRow` without importing utilities. */
|
|
export type OpsLocalStaffPledgeRow = {
|
|
id: number
|
|
leadershipID: number
|
|
contactName: string
|
|
declaredVotes: number
|
|
declaredAt: string | null
|
|
estimatedVotes: VoteEstimateScenarioViewModel
|
|
estimateNote: string | null
|
|
estimatedAt: string | null
|
|
updatedAt: string
|
|
}
|
|
|
|
export const findOpsMunicipalityBySlug = (
|
|
municipalities: ReadonlyArray<OpsMunicipality>,
|
|
slug: string,
|
|
): OpsMunicipality | null => municipalities.find((row) => row.slug === slug) ?? null
|
|
|
|
export const toLocalStaffPledgeRows = (
|
|
municipalityId: number,
|
|
pledges: ReadonlyArray<OpsVotePledge>,
|
|
leaderships: ReadonlyArray<OpsLeadership>,
|
|
): OpsLocalStaffPledgeRow[] => {
|
|
const leadershipById = new Map(leaderships.map((row) => [row.id, row]))
|
|
|
|
return pledges
|
|
.filter((pledge) => pledge.municipality === municipalityId)
|
|
.map((pledge) => {
|
|
const leadership = leadershipById.get(pledge.leadership)
|
|
return {
|
|
id: pledge.id,
|
|
leadershipID: pledge.leadership,
|
|
contactName: leadership?.contact.name ?? 'Liderança',
|
|
declaredVotes: pledge.declaredVotes,
|
|
declaredAt: pledge.declaredAt ?? null,
|
|
estimatedVotes: toVoteEstimateScenarioViewModel(pledge.estimatedVotes),
|
|
estimateNote: pledge.estimateNote ?? null,
|
|
estimatedAt: pledge.estimatedAt ?? null,
|
|
updatedAt: pledge.updatedAt,
|
|
}
|
|
})
|
|
.sort((left, right) => left.contactName.localeCompare(right.contactName, 'pt-BR'))
|
|
}
|