mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-17 12:43:05 +00:00
- 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>
70 lines
1.8 KiB
TypeScript
70 lines
1.8 KiB
TypeScript
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,
|
||
},
|
||
],
|
||
}
|