mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10:31 +00:00
add server to monorepo.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import events from '@/subscribers/events';
|
||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||
import SettingsService from '@/services/Settings/SettingsService';
|
||||
import { ISaleEstimateCreatedPayload } from '@/interfaces';
|
||||
|
||||
@Service()
|
||||
export default class SaleEstimateAutoSerialSubscriber {
|
||||
@Inject()
|
||||
tenancy: TenancyService;
|
||||
|
||||
@Inject()
|
||||
settingsService: SettingsService;
|
||||
|
||||
/**
|
||||
* Attaches events to handles.events.saleEstimate.onCreated
|
||||
*/
|
||||
public attach(bus) {
|
||||
bus.subscribe(
|
||||
events.saleEstimate.onCreated,
|
||||
this.handleEstimateNextNumberIncrement
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle sale estimate increment next number once be created.
|
||||
*/
|
||||
private handleEstimateNextNumberIncrement = async ({
|
||||
tenantId,
|
||||
saleEstimateId,
|
||||
trx,
|
||||
}: ISaleEstimateCreatedPayload) => {
|
||||
await this.settingsService.incrementNextNumber(tenantId, {
|
||||
key: 'next_number',
|
||||
group: 'sales_estimates',
|
||||
});
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import events from '@/subscribers/events';
|
||||
import SaleEstimateNotifyBySms from '@/services/Sales/Estimates/SaleEstimateSmsNotify';
|
||||
import { ISaleEstimateCreatedPayload } from '@/interfaces';
|
||||
import { runAfterTransaction } from '@/services/UnitOfWork/TransactionsHooks';
|
||||
|
||||
@Service()
|
||||
export default class SaleEstimateSmsNotificationSubscriber {
|
||||
@Inject()
|
||||
saleEstimateNotifyBySms: SaleEstimateNotifyBySms;
|
||||
|
||||
/**
|
||||
* Attaches events to handles.events.saleEstimate.onCreated
|
||||
*/
|
||||
public attach(bus) {
|
||||
bus.subscribe(
|
||||
events.saleEstimate.onCreated,
|
||||
this.handleNotifySmSNotificationAfterCreation
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notify via SMS notification after sale estimate creation.
|
||||
*/
|
||||
private handleNotifySmSNotificationAfterCreation = async ({
|
||||
tenantId,
|
||||
saleEstimateId,
|
||||
saleEstimate,
|
||||
trx,
|
||||
}: ISaleEstimateCreatedPayload) => {
|
||||
// Can't continue if estimate is not delivered.
|
||||
if (!saleEstimate.isDelivered) return;
|
||||
|
||||
runAfterTransaction(trx, async () => {
|
||||
try {
|
||||
await this.saleEstimateNotifyBySms.notifyViaSmsNotificationAfterCreation(
|
||||
tenantId,
|
||||
saleEstimateId
|
||||
);
|
||||
} catch (error) {}
|
||||
});
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user