Agenda Sync refactor Mig Graph
This commit is contained in:
parent
56d52c50fa
commit
c859068e87
@ -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
|
* Get user's email credentials from database
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -2,8 +2,7 @@ import { NotificationAdapter } from './notification-adapter.interface';
|
|||||||
import { logger } from '@/lib/logger';
|
import { logger } from '@/lib/logger';
|
||||||
import { Notification, NotificationCount } from '@/lib/types/notification';
|
import { Notification, NotificationCount } from '@/lib/types/notification';
|
||||||
import { getRedisClient } from '@/lib/redis';
|
import { getRedisClient } from '@/lib/redis';
|
||||||
import { prisma } from '@/lib/prisma';
|
import { getImapConnection, shouldUseGraphAPI, getUserEmailAccounts } from '@/lib/services/email-service';
|
||||||
import { getImapConnection, shouldUseGraphAPI } from '@/lib/services/email-service';
|
|
||||||
import { getGraphUnreadCount, fetchGraphEmails } from '@/lib/services/microsoft-graph-mail';
|
import { getGraphUnreadCount, fetchGraphEmails } from '@/lib/services/microsoft-graph-mail';
|
||||||
|
|
||||||
export class EmailAdapter implements NotificationAdapter {
|
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>>> {
|
private async fetchUnreadCounts(userId: string): Promise<Record<string, Record<string, number>>> {
|
||||||
// Get all accounts from the database
|
// Get all accounts from the database
|
||||||
const accounts = await prisma.mailCredentials.findMany({
|
const accounts = await getUserEmailAccounts(userId);
|
||||||
where: { userId },
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
email: true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
logger.debug('[EMAIL_ADAPTER] Found accounts', {
|
logger.debug('[EMAIL_ADAPTER] Found accounts', {
|
||||||
userId,
|
userId,
|
||||||
@ -236,13 +229,7 @@ export class EmailAdapter implements NotificationAdapter {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
// Get all accounts from the database
|
// Get all accounts from the database
|
||||||
const accounts = await prisma.mailCredentials.findMany({
|
const accounts = await getUserEmailAccounts(userId);
|
||||||
where: { userId },
|
|
||||||
select: {
|
|
||||||
id: true,
|
|
||||||
email: true
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (accounts.length === 0) {
|
if (accounts.length === 0) {
|
||||||
return [];
|
return [];
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user