diff --git a/src/composables/useBotVotesProvider.ts b/src/composables/useBotVotesProvider.ts index c4a52b2..f5856da 100644 --- a/src/composables/useBotVotesProvider.ts +++ b/src/composables/useBotVotesProvider.ts @@ -10,14 +10,14 @@ export default function useBotVotesProvider(botId: Ref, provider: VotesP const config = computed<{ connectionId?: string webhookSecret?: string - } | null>(() => store.bots[botId.value]?.webhooksConfig[provider] ?? null) + } | null>(() => store.bots[botId.value]?.webhooksConfig.providers[provider] ?? null) async function update(token: string) { if (!api.userId) throw new Error('Not authenticated') await api.bots.votes.update(botId.value, provider, token) - if (store.bots[botId.value]?.webhooksConfig[provider]) { - store.bots[botId.value]!.webhooksConfig[provider]!.webhookSecret = token + if (store.bots[botId.value]?.webhooksConfig.providers[provider]) { + store.bots[botId.value]!.webhooksConfig.providers[provider]!.webhookSecret = token } } diff --git a/src/utils/statsManager.ts b/src/utils/statsManager.ts index 5ffae3e..1fe4d08 100644 --- a/src/utils/statsManager.ts +++ b/src/utils/statsManager.ts @@ -418,15 +418,18 @@ export function calculateVotes( rawVotes.forEach((votes) => { const date = toBucket(votes.date, granularity) - const providerName = selectVotesProvider(votes.provider) if (!votesMap.has(date.getTime())) votesMap.set(date.getTime(), { total: 0, byProvider: new Map() }) const entry = votesMap.get(date.getTime())! - entry.total += votes.count - if (providerName) { - entry.byProvider.set(providerName, (entry.byProvider.get(providerName) ?? 0) + votes.count) - pieMap.set(providerName, (pieMap.get(providerName) ?? 0) + votes.count) + + for (const [provider, count] of Object.entries(votes.votes)) { + const providerName = selectVotesProvider(provider as VotesProvider) + entry.total += count + if (providerName) { + entry.byProvider.set(providerName, (entry.byProvider.get(providerName) ?? 0) + count) + pieMap.set(providerName, (pieMap.get(providerName) ?? 0) + count) + } } }) diff --git a/src/utils/types.ts b/src/utils/types.ts index fd60e01..4919e6b 100644 --- a/src/utils/types.ts +++ b/src/utils/types.ts @@ -73,10 +73,11 @@ export interface Bot { teammatesLimit: number webhooksConfig: { webhookUrl?: string - } & { - [provider: string]: { - connectionId?: string - webhookSecret?: string + providers: { + [provider: string]: { + connectionId?: string + webhookSecret?: string + } } } } @@ -143,9 +144,10 @@ export interface CustomEvent { export interface RawVotes { id: number date: string - provider: VotesProvider + votes: { + [provider: string]: number + } botId: string - count: number } export interface ChartData {