Files
bigcapital/packages/server/src/services/Accounts/susbcribers/MutateBaseCurrencyAccounts.ts
2023-02-03 11:57:50 +02:00

35 lines
874 B
TypeScript

import { Service, Inject } from 'typedi';
import events from '@/subscribers/events';
import { MutateBaseCurrencyAccounts } from '../MutateBaseCurrencyAccounts';
@Service()
export class MutateBaseCurrencyAccountsSubscriber {
@Inject()
public mutateBaseCurrencyAccounts: MutateBaseCurrencyAccounts;
/**
* Attaches the events with handles.
* @param bus
*/
attach(bus) {
bus.subscribe(
events.organization.baseCurrencyUpdated,
this.updateAccountsCurrencyOnBaseCurrencyMutated
);
}
/**
* Updates the all accounts currency once the base currency
* of the organization is mutated.
*/
private updateAccountsCurrencyOnBaseCurrencyMutated = async ({
tenantId,
organizationDTO,
}) => {
await this.mutateBaseCurrencyAccounts.mutateAllAccountsCurrency(
tenantId,
organizationDTO.baseCurrency
);
};
}