fix: Use userEmailAccounts join table for email account lookup
The emailAccounts table doesn't have a userId column - it uses a many-to-many relationship through userEmailAccounts table. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
import { db } from '../../config/database.js';
|
||||
import { prilohy, registracie, ucastnici, kurzy, emailAccounts } from '../../db/schema.js';
|
||||
import { prilohy, registracie, ucastnici, kurzy, emailAccounts, userEmailAccounts } from '../../db/schema.js';
|
||||
import { eq, and } from 'drizzle-orm';
|
||||
import { NotFoundError, BadRequestError } from '../../utils/errors.js';
|
||||
import { logger } from '../../utils/logger.js';
|
||||
@@ -462,17 +462,26 @@ export const sendCertificateEmail = async (prilohaId, userId) => {
|
||||
throw new BadRequestError('Účastník nemá zadaný email');
|
||||
}
|
||||
|
||||
// Get email account for sending
|
||||
const [emailAccount] = await db
|
||||
.select()
|
||||
.from(emailAccounts)
|
||||
.where(and(eq(emailAccounts.userId, userId), eq(emailAccounts.isActive, true)))
|
||||
// Get email account for sending (through userEmailAccounts join table)
|
||||
const [emailAccountResult] = await db
|
||||
.select({
|
||||
id: emailAccounts.id,
|
||||
email: emailAccounts.email,
|
||||
emailPassword: emailAccounts.emailPassword,
|
||||
jmapAccountId: emailAccounts.jmapAccountId,
|
||||
isActive: emailAccounts.isActive,
|
||||
})
|
||||
.from(userEmailAccounts)
|
||||
.innerJoin(emailAccounts, eq(userEmailAccounts.emailAccountId, emailAccounts.id))
|
||||
.where(and(eq(userEmailAccounts.userId, userId), eq(emailAccounts.isActive, true)))
|
||||
.limit(1);
|
||||
|
||||
if (!emailAccount) {
|
||||
if (!emailAccountResult) {
|
||||
throw new BadRequestError('Nemáte nastavený aktívny emailový účet pre odosielanie');
|
||||
}
|
||||
|
||||
const emailAccount = emailAccountResult;
|
||||
|
||||
// Build participant name
|
||||
const participantName = [
|
||||
registration.ucastnikTitul,
|
||||
|
||||
Reference in New Issue
Block a user