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 fs from 'fs/promises';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { db } from '../../config/database.js';
|
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 { eq, and } from 'drizzle-orm';
|
||||||
import { NotFoundError, BadRequestError } from '../../utils/errors.js';
|
import { NotFoundError, BadRequestError } from '../../utils/errors.js';
|
||||||
import { logger } from '../../utils/logger.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');
|
throw new BadRequestError('Účastník nemá zadaný email');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get email account for sending
|
// Get email account for sending (through userEmailAccounts join table)
|
||||||
const [emailAccount] = await db
|
const [emailAccountResult] = await db
|
||||||
.select()
|
.select({
|
||||||
.from(emailAccounts)
|
id: emailAccounts.id,
|
||||||
.where(and(eq(emailAccounts.userId, userId), eq(emailAccounts.isActive, true)))
|
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);
|
.limit(1);
|
||||||
|
|
||||||
if (!emailAccount) {
|
if (!emailAccountResult) {
|
||||||
throw new BadRequestError('Nemáte nastavený aktívny emailový účet pre odosielanie');
|
throw new BadRequestError('Nemáte nastavený aktívny emailový účet pre odosielanie');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const emailAccount = emailAccountResult;
|
||||||
|
|
||||||
// Build participant name
|
// Build participant name
|
||||||
const participantName = [
|
const participantName = [
|
||||||
registration.ucastnikTitul,
|
registration.ucastnikTitul,
|
||||||
|
|||||||
Reference in New Issue
Block a user