Feedback page: results, responses, who hasn't answered, reminders (2.1.0)
- Supervisor -> Feedback (supervisors and admins, campus-scoped): every event's form with answered of asked, response rate, average rating and last reminder; per event the results per question (with the AI summary), each response, and on named forms who was asked and who has answered. - Remind those who haven't answered (or one person on a named form): a fresh link, plus the form to anyone eligible who hasn't had it; nobody gets the form or a reminder twice within 24 hours. The 3-day job is unchanged. - Anonymous forms show no names and no list of who has answered. - FeedbackInvite.reminderCount (migration 20261103120000_feedback_reminders); access log action feedback_responses; help page; dashboard and Ctrl+K links. - Roadmap: the AI helpers on the privacy pages are dropped; 2.1.0 is the feedback page. - Tests: tests/feedbackPage.test.ts, e2e/feedback.spec.ts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -19,6 +19,7 @@ const ACCESS_ACTIONS = {
|
||||
kids_offline: 'Kids check-in list downloaded for offline use',
|
||||
volunteer_roster: 'Volunteer roster opened',
|
||||
ai_feedback: 'Feedback comments summarised by the AI helper',
|
||||
feedback_responses: 'Feedback answers viewed (named form)',
|
||||
ai_report: 'Report summarised by the AI helper (anonymised totals)',
|
||||
};
|
||||
|
||||
|
||||
@@ -183,19 +183,37 @@ async function sendFeedbackInvites(formId) {
|
||||
return people.length;
|
||||
}
|
||||
|
||||
/** The single reminder: a fresh link for everyone who hasn't answered. */
|
||||
async function sendFeedbackReminders(formId) {
|
||||
/** A manual reminder isn't sent to the same person again within this long. */
|
||||
const REMIND_GAP_MS = 24 * 3600e3;
|
||||
|
||||
/**
|
||||
* A fresh link for everyone who hasn't answered. With no options it's the automatic reminder:
|
||||
* only people never reminded. `userIds` limits it to those people; `minGapMs` skips anyone
|
||||
* reminded more recently than that (the manual "Remind" button). Returns how many were sent.
|
||||
*/
|
||||
async function sendFeedbackReminders(formId, { userIds = null, minGapMs = null, now = new Date() } = {}) {
|
||||
const form = await prisma.feedbackForm.findUnique({ where: { id: formId }, include: { event: true } });
|
||||
if (!form) return 0;
|
||||
// Manual: not if they were sent the form, or reminded, within minGapMs.
|
||||
const since = minGapMs == null ? null : new Date(now.getTime() - minGapMs);
|
||||
const recent = since == null ? { remindedAt: null } : { sentAt: { lt: since }, OR: [{ remindedAt: null }, { remindedAt: { lt: since } }] };
|
||||
const invites = await prisma.feedbackInvite.findMany({
|
||||
where: { formId, respondedAt: null, remindedAt: null },
|
||||
where: { formId, respondedAt: null, ...recent, ...(userIds ? { userId: { in: userIds } } : {}) },
|
||||
include: { user: { select: { id: true, name: true, email: true, phoneNumber: true, notificationPreference: true } } },
|
||||
});
|
||||
let sent = 0;
|
||||
for (const inv of invites) {
|
||||
const token = newToken();
|
||||
await prisma.feedbackInvite.update({ where: { id: inv.id }, data: { tokenHash: hashToken(token), remindedAt: new Date() } });
|
||||
// Only if they still haven't answered (they may have while this ran).
|
||||
const claimed = await prisma.feedbackInvite.updateMany({
|
||||
where: { id: inv.id, respondedAt: null },
|
||||
data: { tokenHash: hashToken(token), remindedAt: now, reminderCount: { increment: 1 } },
|
||||
});
|
||||
if (claimed.count !== 1) continue;
|
||||
sent += 1;
|
||||
await sendFeedbackMessage(inv.user, form.event, token, { reminder: true }).catch(e => console.warn('[feedback] reminder failed:', e?.message || e));
|
||||
}
|
||||
return invites.length;
|
||||
return sent;
|
||||
}
|
||||
|
||||
/** Background job: send forms whose time has come, and reminders 3 days after. */
|
||||
@@ -224,7 +242,7 @@ async function findInviteByToken(token) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
ANSWERABLE, ALL_TYPES, REMINDER_AFTER_MS, feedbackError, hashToken, feedbackLink,
|
||||
ANSWERABLE, ALL_TYPES, REMINDER_AFTER_MS, REMIND_GAP_MS, feedbackError, hashToken, feedbackLink,
|
||||
cleanFields, cleanAnswer, summarise,
|
||||
feedbackRecipients, sendFeedbackInvites, sendFeedbackReminders, runFeedbackJob, findInviteByToken,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user