mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
- Add missing BullModule queue registration and BullBoardModule to UsersModule - Add invitingUser to event payloads to track who sent the invite - Fix incorrect global variable in SendInviteUsersMailMessage (__views_dir -> __images_dirname) - Use invitingUser as fromUser instead of invited user in email - Update processors to use BullMQ pattern Fixes issues: 1. Email not sending due to missing queue/processor registration 2. Null variables in email (firstName/lastName) because fromUser was the invited user 3. Image attachment failing due to wrong path
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { InjectQueue } from '@nestjs/bullmq';
|
|
import { Queue } from 'bullmq';
|
|
import { events } from '@/common/events/events';
|
|
import { OnEvent } from '@nestjs/event-emitter';
|
|
import {
|
|
IUserInviteTenantSyncedEventPayload,
|
|
SendInviteUserMailJobPayload,
|
|
} from '../Users.types';
|
|
import {
|
|
SendInviteUserMailJob,
|
|
SendInviteUserMailQueue,
|
|
} from '../Users.constants';
|
|
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';
|
|
|
|
@Injectable()
|
|
export default class InviteSendMainNotificationSubscribe {
|
|
constructor(
|
|
@InjectQueue(SendInviteUserMailQueue)
|
|
private readonly sendInviteMailQueue: Queue,
|
|
private readonly tenancyContext: TenancyContext,
|
|
) {}
|
|
|
|
/**
|
|
* Sends mail notification.
|
|
* @param {IUserInvitedEventPayload} payload
|
|
*/
|
|
@OnEvent(events.inviteUser.sendInviteTenantSynced)
|
|
async sendMailNotification({
|
|
invite,
|
|
user,
|
|
invitingUser,
|
|
}: IUserInviteTenantSyncedEventPayload) {
|
|
const tenant = await this.tenancyContext.getTenant();
|
|
const authedUser = await this.tenancyContext.getSystemUser();
|
|
|
|
const organizationId = tenant.organizationId;
|
|
const userId = authedUser.id;
|
|
|
|
this.sendInviteMailQueue.add(SendInviteUserMailJob, {
|
|
fromUser: invitingUser,
|
|
invite,
|
|
userId,
|
|
organizationId,
|
|
} as SendInviteUserMailJobPayload);
|
|
}
|
|
}
|