mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
fix(InventoryValuation): inventory valuation report.
This commit is contained in:
@@ -135,30 +135,6 @@ export default class ExchangeRatesService implements IExchangeRatesService {
|
||||
return exchangeRates;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes exchange rates in bulk.
|
||||
* @param {number} tenantId
|
||||
* @param {number[]} exchangeRatesIds
|
||||
*/
|
||||
public async deleteBulkExchangeRates(
|
||||
tenantId: number,
|
||||
exchangeRatesIds: number[]
|
||||
): Promise<void> {
|
||||
const { ExchangeRate } = this.tenancy.models(tenantId);
|
||||
|
||||
this.logger.info('[exchange_rates] trying delete in bulk.', {
|
||||
tenantId,
|
||||
exchangeRatesIds,
|
||||
});
|
||||
await this.validateExchangeRatesIdsExistance(tenantId, exchangeRatesIds);
|
||||
|
||||
await ExchangeRate.query().whereIn('id', exchangeRatesIds).delete();
|
||||
this.logger.info('[exchange_rates] deleted successfully.', {
|
||||
tenantId,
|
||||
exchangeRatesIds,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates period of the exchange rate existance.
|
||||
* @param {number} tenantId - Tenant id.
|
||||
@@ -214,33 +190,4 @@ export default class ExchangeRatesService implements IExchangeRatesService {
|
||||
throw new ServiceError(ERRORS.EXCHANGE_RATE_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates exchange rates ids existance.
|
||||
* @param {number} tenantId - Tenant id.
|
||||
* @param {number[]} exchangeRatesIds - Exchange rates ids.
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
private async validateExchangeRatesIdsExistance(
|
||||
tenantId: number,
|
||||
exchangeRatesIds: number[]
|
||||
): Promise<void> {
|
||||
const { ExchangeRate } = this.tenancy.models(tenantId);
|
||||
|
||||
const storedExchangeRates = await ExchangeRate.query().whereIn(
|
||||
'id',
|
||||
exchangeRatesIds
|
||||
);
|
||||
const storedExchangeRatesIds = storedExchangeRates.map(
|
||||
(category) => category.id
|
||||
);
|
||||
const notFoundExRates = difference(
|
||||
exchangeRatesIds,
|
||||
storedExchangeRatesIds
|
||||
);
|
||||
|
||||
if (notFoundExRates.length > 0) {
|
||||
throw new ServiceError(ERRORS.NOT_FOUND_EXCHANGE_RATES);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user