Add debug logging for markContactEmailsAsRead and remove password change restriction
This commit is contained in:
@@ -2,6 +2,7 @@ import * as contactService from '../services/contact.service.js';
|
||||
import { discoverContactsFromJMAP, getJmapConfigFromAccount } from '../services/jmap.service.js';
|
||||
import { formatErrorResponse } from '../utils/errors.js';
|
||||
import * as emailAccountService from '../services/email-account.service.js';
|
||||
import { logger } from '../utils/logger.js';
|
||||
|
||||
/**
|
||||
* Get all contacts for authenticated user
|
||||
@@ -34,18 +35,18 @@ export const discoverContacts = async (req, res) => {
|
||||
const userId = req.userId;
|
||||
const { accountId, search = '', limit = 50 } = req.query;
|
||||
|
||||
console.log('🔍 discoverContacts called:', { userId, accountId, search, limit });
|
||||
logger.debug('discoverContacts called', { userId, accountId, search, limit });
|
||||
|
||||
// Get email account (or primary if not specified)
|
||||
let emailAccount;
|
||||
if (accountId) {
|
||||
console.log('📧 Getting email account by ID:', accountId);
|
||||
logger.debug('Getting email account by ID', { accountId });
|
||||
emailAccount = await emailAccountService.getEmailAccountWithCredentials(accountId, userId);
|
||||
console.log('✅ Email account retrieved:', { id: emailAccount.id, email: emailAccount.email });
|
||||
logger.debug('Email account retrieved', { id: emailAccount.id, email: emailAccount.email });
|
||||
} else {
|
||||
console.log('📧 No accountId provided, getting primary account for user:', userId);
|
||||
logger.debug('No accountId provided, getting primary account', { userId });
|
||||
const primaryAccount = await emailAccountService.getPrimaryEmailAccount(userId);
|
||||
console.log('🔑 Primary account:', primaryAccount ? { id: primaryAccount.id, email: primaryAccount.email } : 'NOT FOUND');
|
||||
logger.debug('Primary account', primaryAccount ? { id: primaryAccount.id, email: primaryAccount.email } : { found: false });
|
||||
if (!primaryAccount) {
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
@@ -56,11 +57,11 @@ export const discoverContacts = async (req, res) => {
|
||||
});
|
||||
}
|
||||
emailAccount = await emailAccountService.getEmailAccountWithCredentials(primaryAccount.id, userId);
|
||||
console.log('✅ Email account retrieved from primary:', { id: emailAccount.id, email: emailAccount.email });
|
||||
logger.debug('Email account retrieved from primary', { id: emailAccount.id, email: emailAccount.email });
|
||||
}
|
||||
|
||||
const jmapConfig = getJmapConfigFromAccount(emailAccount);
|
||||
console.log('🔧 JMAP Config created:', {
|
||||
logger.debug('JMAP Config created', {
|
||||
server: jmapConfig.server,
|
||||
username: jmapConfig.username,
|
||||
accountId: jmapConfig.accountId,
|
||||
@@ -80,8 +81,7 @@ export const discoverContacts = async (req, res) => {
|
||||
data: potentialContacts,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('❌ ERROR in discoverContacts:', error);
|
||||
console.error('Error stack:', error.stack);
|
||||
logger.error('ERROR in discoverContacts', { error: error.message, stack: error.stack });
|
||||
const errorResponse = formatErrorResponse(error, process.env.NODE_ENV === 'development');
|
||||
res.status(error.statusCode || 500).json(errorResponse);
|
||||
}
|
||||
@@ -95,10 +95,10 @@ export const discoverContacts = async (req, res) => {
|
||||
export const addContact = async (req, res) => {
|
||||
try {
|
||||
const userId = req.userId;
|
||||
console.log('📦 Full req.body:', JSON.stringify(req.body, null, 2));
|
||||
logger.debug('Full req.body', { body: req.body });
|
||||
const { email, name = '', notes = '', accountId } = req.body;
|
||||
|
||||
console.log('➕ addContact called:', { userId, email, name, accountId });
|
||||
logger.debug('addContact called', { userId, email, name, accountId });
|
||||
|
||||
if (!email) {
|
||||
return res.status(400).json({
|
||||
@@ -113,10 +113,10 @@ export const addContact = async (req, res) => {
|
||||
// Get email account (or primary if not specified)
|
||||
let emailAccount;
|
||||
if (accountId) {
|
||||
console.log('📧 Using provided accountId:', accountId);
|
||||
logger.debug('Using provided accountId', { accountId });
|
||||
emailAccount = await emailAccountService.getEmailAccountWithCredentials(accountId, userId);
|
||||
} else {
|
||||
console.log('📧 No accountId provided, using primary account');
|
||||
logger.debug('No accountId provided, using primary account');
|
||||
const primaryAccount = await emailAccountService.getPrimaryEmailAccount(userId);
|
||||
if (!primaryAccount) {
|
||||
return res.status(400).json({
|
||||
@@ -128,7 +128,7 @@ export const addContact = async (req, res) => {
|
||||
});
|
||||
}
|
||||
emailAccount = await emailAccountService.getEmailAccountWithCredentials(primaryAccount.id, userId);
|
||||
console.log('📧 Using primary account:', primaryAccount.id);
|
||||
logger.debug('Using primary account', { accountId: primaryAccount.id });
|
||||
}
|
||||
|
||||
const jmapConfig = getJmapConfigFromAccount(emailAccount);
|
||||
|
||||
Reference in New Issue
Block a user