mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
refactor(nestjs): currencies module
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { Currency } from '../models/Currency.model';
|
||||
import { TenantModelProxy } from '../../System/models/TenantBaseModel';
|
||||
import { EditCurrencyDto } from '../dtos/EditCurrency.dto';
|
||||
|
||||
@Injectable()
|
||||
export class EditCurrencyService {
|
||||
constructor(
|
||||
@Inject(Currency.name)
|
||||
private readonly currencyModel: TenantModelProxy<typeof Currency>,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Edit details of the given currency.
|
||||
* @param {number} tenantId
|
||||
* @param {number} currencyId
|
||||
* @param {ICurrencyDTO} currencyDTO
|
||||
*/
|
||||
public async editCurrency(
|
||||
currencyId: number,
|
||||
currencyDTO: EditCurrencyDto,
|
||||
): Promise<Currency> {
|
||||
const foundCurrency = await this.currencyModel()
|
||||
.query()
|
||||
.findOne('id', currencyId)
|
||||
.throwIfNotFound();
|
||||
|
||||
const currency = await this.currencyModel()
|
||||
.query()
|
||||
.patchAndFetchById(currencyId, {
|
||||
...currencyDTO,
|
||||
});
|
||||
return currency;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user