35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { prismaClient } from '../../../common/database/prisma.lambda.service';
|
|
import { sendAMEmailForHostAssign } from './AMEmail.service';
|
|
|
|
@Injectable()
|
|
export class AMNotificationService {
|
|
private prisma = prismaClient;
|
|
|
|
/**
|
|
* Fetch account manager email by id and send assignment email.
|
|
* Returns true if email was attempted (sent or attempted), false if AM missing or no email.
|
|
*/
|
|
async notifyAMOfAssignment(accountManagerXid: number, hostXid?: number): Promise<boolean> {
|
|
if (!accountManagerXid) return false;
|
|
|
|
const amUser = await this.prisma.user.findUnique({
|
|
where: { id: accountManagerXid },
|
|
select: { emailAddress: true, firstName: true, lastName: true },
|
|
});
|
|
|
|
if (!amUser || !amUser.emailAddress) {
|
|
console.warn(`AM notification skipped: user not found or missing email for id=${accountManagerXid}`);
|
|
return false;
|
|
}
|
|
|
|
try {
|
|
await sendAMEmailForHostAssign(amUser.emailAddress);
|
|
return true;
|
|
} catch (err) {
|
|
console.error('Error sending AM assignment email', err);
|
|
return false;
|
|
}
|
|
}
|
|
}
|