mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
refactor(nestjs): currencies module
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { Inject, Injectable } from "@nestjs/common";
|
||||
import { Currency } from "../models/Currency.model";
|
||||
import { TenantModelProxy } from "../../System/models/TenantBaseModel";
|
||||
import { TransformerInjectable } from "../../Transformer/TransformerInjectable.service";
|
||||
import { CurrencyTransformer } from "../Currency.transformer";
|
||||
|
||||
@Injectable()
|
||||
export class GetCurrenciesService {
|
||||
constructor(
|
||||
@Inject(Currency.name)
|
||||
private readonly currencyModel: TenantModelProxy<typeof Currency>,
|
||||
private readonly transformerInjectable: TransformerInjectable,
|
||||
) {
|
||||
|
||||
}
|
||||
/**
|
||||
* Retrieves currencies list.
|
||||
* @return {Promise<ICurrency[]>}
|
||||
*/
|
||||
public async getCurrencies(): Promise<Currency[]> {
|
||||
const currencies = await this.currencyModel().query().onBuild((query) => {
|
||||
query.orderBy('createdAt', 'ASC');
|
||||
});
|
||||
return this.transformerInjectable.transform(
|
||||
currencies,
|
||||
new CurrencyTransformer()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||
import { Currency } from '../models/Currency.model';
|
||||
import { TransformerInjectable } from '@/modules/Transformer/TransformerInjectable.service';
|
||||
import { CurrencyTransformer } from '../Currency.transformer';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class GetCurrencyService {
|
||||
constructor(
|
||||
@Inject(Currency.name)
|
||||
private readonly currencyModel: TenantModelProxy<typeof Currency>,
|
||||
private readonly transformInjectable: TransformerInjectable,
|
||||
) {}
|
||||
|
||||
getCurrency(currencyCode: string) {
|
||||
const currency = this.currencyModel()
|
||||
.query()
|
||||
.findOne('currencyCode', currencyCode)
|
||||
.throwIfNotFound();
|
||||
|
||||
return this.transformInjectable.transform(
|
||||
currency,
|
||||
new CurrencyTransformer(),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user