mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 12:20:31 +00:00
41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
import { Service, Inject } from 'typedi';
|
|
import events from '@/subscribers/events';
|
|
import { PaymentReceiveNotifyBySms } from '@/services/Sales/PaymentReceives/PaymentReceiveSmsNotify';
|
|
import { IPaymentReceiveCreatedPayload } from '@/interfaces';
|
|
import { runAfterTransaction } from '@/services/UnitOfWork/TransactionsHooks';
|
|
|
|
@Service()
|
|
export default class SendSmsNotificationPaymentReceive {
|
|
@Inject()
|
|
private paymentReceiveSmsNotify: PaymentReceiveNotifyBySms;
|
|
|
|
/**
|
|
* Attach events.
|
|
*/
|
|
public attach(bus) {
|
|
bus.subscribe(
|
|
events.paymentReceive.onCreated,
|
|
this.handleNotifyViaSmsOncePaymentPublish
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Handles send SMS notification after payment transaction creation.
|
|
*/
|
|
private handleNotifyViaSmsOncePaymentPublish = ({
|
|
tenantId,
|
|
paymentReceiveId,
|
|
trx,
|
|
}: IPaymentReceiveCreatedPayload) => {
|
|
// Notify via Sms after transactions complete running.
|
|
runAfterTransaction(trx, async () => {
|
|
try {
|
|
await this.paymentReceiveSmsNotify.notifyViaSmsNotificationAfterCreation(
|
|
tenantId,
|
|
paymentReceiveId
|
|
);
|
|
} catch (error) {}
|
|
});
|
|
};
|
|
}
|