server: re-fetch poll votes before end notif

This commit is contained in:
Johann150 2024-08-29 22:39:10 +02:00
parent 650869e2f7
commit 6ce067af56
Signed by: Johann150
GPG key ID: 9EE6577A2A06F8F1

View file

@ -2,6 +2,8 @@ import Bull from 'bull';
import { Notes, PollVotes } from '@/models/index.js'; import { Notes, PollVotes } from '@/models/index.js';
import { EndedPollNotificationJobData } from '@/queue/types.js'; import { EndedPollNotificationJobData } from '@/queue/types.js';
import { createNotification } from '@/services/create-notification.js'; import { createNotification } from '@/services/create-notification.js';
import { Resolver } from '@/remote/activitypub/resolver.js';
import { updateQuestion } from '@/remote/activitypub/models/question.js';
export async function endedPollNotification(job: Bull.Job<EndedPollNotificationJobData>, done: any): Promise<void> { export async function endedPollNotification(job: Bull.Job<EndedPollNotificationJobData>, done: any): Promise<void> {
const note = await Notes.findOneBy({ id: job.data.noteId }); const note = await Notes.findOneBy({ id: job.data.noteId });
@ -10,6 +12,9 @@ export async function endedPollNotification(job: Bull.Job<EndedPollNotificationJ
return; return;
} }
// get the (final) numbers of votes
await updateQuestion(note.uri, new Resolver());
const votes = await PollVotes.createQueryBuilder('vote') const votes = await PollVotes.createQueryBuilder('vote')
.select('vote.userId') .select('vote.userId')
.where('vote.noteId = :noteId', { noteId: note.id }) .where('vote.noteId = :noteId', { noteId: note.id })