Agenda Sync refactor Mig Graph

This commit is contained in:
alma 2026-01-14 16:18:55 +01:00
parent 56d52c50fa
commit c859068e87
2 changed files with 17 additions and 16 deletions

View File

@ -632,6 +632,20 @@ async function updateSessionData(userId: string, accountId?: string): Promise<vo
}
}
/**
* Get user's email account IDs and emails
*/
export async function getUserEmailAccounts(userId: string): Promise<Array<{ id: string; email: string }>> {
const accounts = await prisma.mailCredentials.findMany({
where: { userId },
select: {
id: true,
email: true
}
});
return accounts;
}
/**
* Get user's email credentials from database
*/

View File

@ -2,8 +2,7 @@ import { NotificationAdapter } from './notification-adapter.interface';
import { logger } from '@/lib/logger';
import { Notification, NotificationCount } from '@/lib/types/notification';
import { getRedisClient } from '@/lib/redis';
import { prisma } from '@/lib/prisma';
import { getImapConnection, shouldUseGraphAPI } from '@/lib/services/email-service';
import { getImapConnection, shouldUseGraphAPI, getUserEmailAccounts } from '@/lib/services/email-service';
import { getGraphUnreadCount, fetchGraphEmails } from '@/lib/services/microsoft-graph-mail';
export class EmailAdapter implements NotificationAdapter {
@ -21,13 +20,7 @@ export class EmailAdapter implements NotificationAdapter {
*/
private async fetchUnreadCounts(userId: string): Promise<Record<string, Record<string, number>>> {
// Get all accounts from the database
const accounts = await prisma.mailCredentials.findMany({
where: { userId },
select: {
id: true,
email: true
}
});
const accounts = await getUserEmailAccounts(userId);
logger.debug('[EMAIL_ADAPTER] Found accounts', {
userId,
@ -236,13 +229,7 @@ export class EmailAdapter implements NotificationAdapter {
try {
// Get all accounts from the database
const accounts = await prisma.mailCredentials.findMany({
where: { userId },
select: {
id: true,
email: true
}
});
const accounts = await getUserEmailAccounts(userId);
if (accounts.length === 0) {
return [];