add prod logs

This commit is contained in:
JCEEE
2026-09-11 12:31:31 +01:00
parent 5d47ade845
commit d0856648fa
2 changed files with 32 additions and 8 deletions
+1
View File
@@ -132,6 +132,7 @@ export async function sendMentionEmail(opts: {
message: string; message: string;
dashboardUrl: string; dashboardUrl: string;
}) { }) {
console.log('[email] sendMentionEmail called to:', opts.to);
const { to, parentName, authorName, message, dashboardUrl } = opts; const { to, parentName, authorName, message, dashboardUrl } = opts;
await resend.emails.send({ await resend.emails.send({
+28 -5
View File
@@ -45,7 +45,10 @@ export async function send(
}); });
// Email any @mentioned parents (their in-app toast is client-side, via the // Email any @mentioned parents (their in-app toast is client-side, via the
// same mention tokens). Fire-and-forget — never fail the message itself. // same mention tokens). Fire-and-forget — never fail the message itself.
notifyMentionedParents(pb, famId, actor, record, body.siteUrl || '').catch(() => {}); console.log('[chat] calling notifyMentionedParents for famId:', famId, 'content:', content.slice(0, 50));
notifyMentionedParents(pb, famId, actor, record, body.siteUrl || '').catch((err: any) => {
console.error('[chat] notifyMentionedParents top-level catch:', err);
});
return record; return record;
} }
@@ -58,25 +61,44 @@ async function notifyMentionedParents(
message: any, message: any,
siteUrl: string siteUrl: string
) { ) {
console.log('[chat] notifyMentionedParents called', { famId, actorName: actor.name, contentLen: String(message.content || '').length });
const content = String(message.content || ''); const content = String(message.content || '');
const parents = await pb const parents = await pb
.collection('users') .collection('users')
.getFullList({ filter: `famId = '${famId}' && role = 'parent'` }) .getFullList({ filter: `famId = '${famId}' && role = 'parent'` })
.catch(() => []); .catch((err: any) => {
console.error('[chat] Failed to fetch parents:', err);
return [];
});
console.log('[chat] parents found:', parents.length, 'mentioned parents:', parents.filter((u: any) => {
if (u.id === actor.id || !u.email) return false;
const name = (u.name || '').trim().toLowerCase();
return !!name && content.toLowerCase().includes('@' + name);
}).length);
const mentioned = parents.filter((u: any) => { const mentioned = parents.filter((u: any) => {
if (u.id === actor.id || !u.email) return false; if (u.id === actor.id || !u.email) return false;
const name = (u.name || '').trim().toLowerCase(); const name = (u.name || '').trim().toLowerCase();
return !!name && content.toLowerCase().includes('@' + name); return !!name && content.toLowerCase().includes('@' + name);
}); });
if (!mentioned.length) return; if (!mentioned.length) {
console.log('[chat] no mentioned parents found');
return;
}
const fam = await pb const fam = await pb
.collection('fams') .collection('fams')
.getOne(famId) .getOne(famId)
.catch(() => null); .catch((err: any) => {
console.error('[chat] Failed to fetch fam:', err);
return null;
});
// Don't send emails for the demo family. // Don't send emails for the demo family.
if (fam?.slug === 'showboaters') return; if (fam?.slug === 'showboaters') {
console.log('[chat] skipping demo family');
return;
}
const dashboardUrl = `${siteUrl}/${fam?.slug || famId}`; const dashboardUrl = `${siteUrl}/${fam?.slug || famId}`;
console.log('[chat] sending mention emails to', mentioned.length, 'parents');
for (const parent of mentioned) { for (const parent of mentioned) {
try { try {
await sendMentionEmail({ await sendMentionEmail({
@@ -86,6 +108,7 @@ async function notifyMentionedParents(
message: content, message: content,
dashboardUrl dashboardUrl
}); });
console.log('[chat] email sent to', parent.email);
} catch (err) { } catch (err) {
console.error(`[chat] Failed to send mention email to ${parent.email}:`, err); console.error(`[chat] Failed to send mention email to ${parent.email}:`, err);
} }