fix chat notification

This commit is contained in:
ismail 2026-02-02 20:00:52 +01:00
parent 36b95da09d
commit 22f2a41c89
2 changed files with 15 additions and 29 deletions

View File

@ -48,7 +48,7 @@
"react": "19.1.0", "react": "19.1.0",
"react-dom": "19.1.0", "react-dom": "19.1.0",
"react-icons": "^5.5.0", "react-icons": "^5.5.0",
"sharp": "^0.34.5", "sharp": "^0.34.3",
"tailwind-merge": "^3.3.1", "tailwind-merge": "^3.3.1",
"zod": "^4.3.6" "zod": "^4.3.6"
}, },

View File

@ -150,24 +150,12 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
); );
} }
} else { } else {
// Customer replying to admins // Customer replying - send ONE email to CONTACT_EMAIL
const [admins] = await pool.query<RowDataPacket[]>( const adminEmail = process.env.CONTACT_EMAIL || 'info@nordicstorium.se';
`SELECT id, email FROM users WHERE role = 'admin'`
);
for (const admin of admins) {
const [sessions] = await pool.query<RowDataPacket[]>(
`SELECT COUNT(*) as count FROM user_sessions
WHERE user_id = ? AND expires_at > NOW()`,
[admin.id]
);
const isAdminOnline = sessions[0].count > 0;
if (!isAdminOnline) {
await sendMessageNotification( await sendMessageNotification(
admin.email, adminEmail,
`Nytt meddelande: ${conversation.subject}`, `Nytt kundmeddelande: ${conversation.subject}`,
sender.full_name, sender.full_name,
sender.email, sender.email,
sender.mobile, sender.mobile,
@ -177,8 +165,6 @@ export async function POST(request: NextRequest, { params }: RouteParams) {
'Svara i Adminpanelen' 'Svara i Adminpanelen'
); );
} }
}
}
return NextResponse.json({ success: true }); return NextResponse.json({ success: true });
} catch (error) { } catch (error) {