Add debug logging for markContactEmailsAsRead and remove password change restriction
This commit is contained in:
@@ -129,12 +129,52 @@ export const getUnreadCount = async (userId) => {
|
||||
* Mark thread as read
|
||||
*/
|
||||
export const markThreadAsRead = async (userId, threadId) => {
|
||||
console.log('🟦 markThreadAsRead called:', { userId, threadId });
|
||||
|
||||
const result = await db
|
||||
.update(emails)
|
||||
.set({ isRead: true, updatedAt: new Date() })
|
||||
.where(and(eq(emails.userId, userId), eq(emails.threadId, threadId), eq(emails.isRead, false)))
|
||||
.returning();
|
||||
|
||||
console.log('✅ markThreadAsRead result:', { count: result.length, threadId });
|
||||
|
||||
return { success: true, count: result.length };
|
||||
};
|
||||
|
||||
/**
|
||||
* Mark all emails from a contact as read
|
||||
*/
|
||||
export const markContactEmailsAsRead = async (userId, contactId) => {
|
||||
console.log('🟦 markContactEmailsAsRead called:', { userId, contactId });
|
||||
|
||||
// First, check what emails exist for this contact (including already read ones)
|
||||
const allContactEmails = await db
|
||||
.select({
|
||||
id: emails.id,
|
||||
contactId: emails.contactId,
|
||||
isRead: emails.isRead,
|
||||
from: emails.from,
|
||||
subject: emails.subject,
|
||||
})
|
||||
.from(emails)
|
||||
.where(and(eq(emails.userId, userId), eq(emails.contactId, contactId)));
|
||||
|
||||
console.log('📧 All emails for this contact:', {
|
||||
total: allContactEmails.length,
|
||||
unread: allContactEmails.filter(e => !e.isRead).length,
|
||||
read: allContactEmails.filter(e => e.isRead).length,
|
||||
sampleEmails: allContactEmails.slice(0, 3),
|
||||
});
|
||||
|
||||
const result = await db
|
||||
.update(emails)
|
||||
.set({ isRead: true, updatedAt: new Date() })
|
||||
.where(and(eq(emails.userId, userId), eq(emails.contactId, contactId), eq(emails.isRead, false)))
|
||||
.returning();
|
||||
|
||||
console.log('✅ markContactEmailsAsRead result:', { count: result.length, contactId });
|
||||
|
||||
return { success: true, count: result.length };
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user