mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { ServiceError } from '@/modules/Items/ServiceError';
|
|
import { OrganizationBaseCurrencyLocking } from '../Organization/OrganizationBaseCurrencyLocking.service';
|
|
import { TenantModel } from '@/modules/System/models/TenantModel';
|
|
import { Injectable } from '@nestjs/common';
|
|
import { ERRORS } from '../Organization.constants';
|
|
|
|
@Injectable()
|
|
export class CommandOrganizationValidators {
|
|
constructor(
|
|
private readonly baseCurrencyMutateLocking: OrganizationBaseCurrencyLocking,
|
|
) {}
|
|
|
|
/**
|
|
* Validate mutate base currency ability.
|
|
* @param {Tenant} tenant -
|
|
* @param {string} newBaseCurrency -
|
|
* @param {string} oldBaseCurrency -
|
|
*/
|
|
async validateMutateBaseCurrency(
|
|
tenant: TenantModel,
|
|
newBaseCurrency: string,
|
|
oldBaseCurrency: string,
|
|
) {
|
|
if (tenant.isReady && newBaseCurrency !== oldBaseCurrency) {
|
|
const isLocked =
|
|
await this.baseCurrencyMutateLocking.isBaseCurrencyMutateLocked(
|
|
tenant.id,
|
|
);
|
|
|
|
if (isLocked) {
|
|
throw new ServiceError(ERRORS.BASE_CURRENCY_MUTATE_LOCKED);
|
|
}
|
|
}
|
|
}
|
|
}
|