teqo-backup/src/collections/CampaignVoteSummarySnapshot.ts
Cursor Agent af6c180211
B57 — delta 7 dias do total estimado no Início
- Collection campaignVoteSummarySnapshot (snapshot diário statewide)
- Gravação idempotente on-read no loadCampaignHomeSummary + retenção 30d
- UI: seta + magnitude ao lado do total B56 (aria-label completo)
- Reusa rollup statewide para CG/candidato; assessor vê Δ global (opção A)

Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
2026-08-01 06:33:39 +00:00

70 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { CollectionConfig } from 'payload'
import { isCampaignStaff, payloadAdminOnly } from '@/utilities/campaignAccess'
/**
* Daily statewide snapshot of the B56 hero scalar (`staffVoteTotal` central).
* B57 reads T−7d for the Início delta; rows are written idempotently on the
* first staff home load of each Bahia civil day and pruned after 30 days.
*
* Hidden from admin nav — staff interact via `loadCampaignHomeSummary`; internal
* snapshot writes use an intentional admin bypass through the Local API.
*/
export const CampaignVoteSummarySnapshot: CollectionConfig = {
slug: 'campaignVoteSummarySnapshot',
labels: {
singular: 'Snapshot de estimativa',
plural: 'Snapshots de estimativa',
},
admin: {
group: 'Campanha',
hidden: () => true,
useAsTitle: 'day',
defaultColumns: ['day', 'scopeKey', 'staffVoteTotalCentral'],
},
access: {
create: payloadAdminOnly,
read: ({ req }) => isCampaignStaff(req.user),
update: payloadAdminOnly,
delete: payloadAdminOnly,
},
fields: [
{
name: 'day',
type: 'date',
label: 'Dia (Bahia)',
required: true,
index: true,
admin: {
description: 'Dia civil America/Bahia (`aaaa-mm-dd`), armazenado como meia-noite UTC.',
date: {
pickerAppearance: 'dayOnly',
},
},
},
{
name: 'scopeKey',
type: 'text',
label: 'Escopo',
required: true,
defaultValue: 'statewide',
index: true,
admin: {
readOnly: true,
},
},
{
name: 'staffVoteTotalCentral',
type: 'number',
label: 'Total estimado (central)',
required: true,
min: 0,
},
],
indexes: [
{
fields: ['day', 'scopeKey'],
unique: true,
},
],
}