mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 06:40:31 +00:00
wip
This commit is contained in:
@@ -35,11 +35,10 @@ import { ThrottlerStorageRedisService } from '@nest-lab/throttler-storage-redis'
|
|||||||
const password = configService.get<string>('redis.password');
|
const password = configService.get<string>('redis.password');
|
||||||
const db = configService.get<number>('redis.db');
|
const db = configService.get<number>('redis.db');
|
||||||
|
|
||||||
// Ensure we always have valid numbers with fallback defaults
|
const globalTtl = configService.get<number>('throttle.global.ttl');
|
||||||
const globalTtl = configService.get<number>('throttle.global.ttl') ?? 60000;
|
const globalLimit = configService.get<number>('throttle.global.limit');
|
||||||
const globalLimit = configService.get<number>('throttle.global.limit') ?? 100;
|
const authTtl = configService.get<number>('throttle.auth.ttl');
|
||||||
const authTtl = configService.get<number>('throttle.auth.ttl') ?? 60000;
|
const authLimit = configService.get<number>('throttle.auth.limit');
|
||||||
const authLimit = configService.get<number>('throttle.auth.limit') ?? 10;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
throttlers: [
|
throttlers: [
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||||
import {
|
import {
|
||||||
ITransactionsByReferencePojo,
|
ITransactionsByReferencePojo,
|
||||||
ITransactionsByReferenceQuery,
|
|
||||||
} from './TransactionsByReference.types';
|
} from './TransactionsByReference.types';
|
||||||
import { TransactionsByReferenceRepository } from './TransactionsByReferenceRepository';
|
import { TransactionsByReferenceRepository } from './TransactionsByReferenceRepository';
|
||||||
import { TransactionsByReference } from './TransactionsByReferenceReport';
|
import { TransactionsByReference } from './TransactionsByReferenceReport';
|
||||||
import { getTransactionsByReferenceQuery } from './_utils';
|
import { getTransactionsByReferenceQuery } from './_utils';
|
||||||
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';
|
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';
|
||||||
|
import { TransactionsByReferenceQueryDto } from './TransactionsByReferenceQuery.dto';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TransactionsByReferenceService {
|
export class TransactionsByReferenceService {
|
||||||
@@ -17,18 +17,12 @@ export class TransactionsByReferenceService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve accounts transactions by given reference id and type.
|
* Retrieve accounts transactions by given reference id and type.
|
||||||
* @param {ITransactionsByReferenceQuery} filter - Transactions by reference query.
|
* @param {TransactionsByReferenceQueryDto} filter - Transactions by reference query.
|
||||||
* @returns {Promise<ITransactionsByReferencePojo>}
|
* @returns {Promise<ITransactionsByReferencePojo>}
|
||||||
*/
|
*/
|
||||||
public async getTransactionsByReference(
|
public async getTransactionsByReference(
|
||||||
query: ITransactionsByReferenceQuery
|
query: TransactionsByReferenceQueryDto
|
||||||
): Promise<ITransactionsByReferencePojo> {
|
): Promise<ITransactionsByReferencePojo> {
|
||||||
// Validate referenceId is a valid positive number
|
|
||||||
const referenceId = Number(query.referenceId);
|
|
||||||
if (isNaN(referenceId) || referenceId <= 0) {
|
|
||||||
throw new BadRequestException('referenceId must be a valid positive number');
|
|
||||||
}
|
|
||||||
|
|
||||||
const filter = {
|
const filter = {
|
||||||
...getTransactionsByReferenceQuery(),
|
...getTransactionsByReferenceQuery(),
|
||||||
...query,
|
...query,
|
||||||
@@ -37,7 +31,7 @@ export class TransactionsByReferenceService {
|
|||||||
|
|
||||||
// Retrieve the accounts transactions of the given reference.
|
// Retrieve the accounts transactions of the given reference.
|
||||||
const transactions = await this.repository.getTransactions(
|
const transactions = await this.repository.getTransactions(
|
||||||
referenceId,
|
query.referenceId,
|
||||||
filter.referenceType
|
filter.referenceType
|
||||||
);
|
);
|
||||||
// Transactions by reference report.
|
// Transactions by reference report.
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { TransactionsByReferenceService } from './TransactionsByReference.service';
|
import { TransactionsByReferenceService } from './TransactionsByReference.service';
|
||||||
import { ITransactionsByReferenceQuery } from './TransactionsByReference.types';
|
import { TransactionsByReferenceQueryDto } from './TransactionsByReferenceQuery.dto';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TransactionsByReferenceApplication {
|
export class TransactionsByReferenceApplication {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly transactionsByReferenceService: TransactionsByReferenceService,
|
private readonly transactionsByReferenceService: TransactionsByReferenceService,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve accounts transactions by given reference id and type.
|
* Retrieve accounts transactions by given reference id and type.
|
||||||
* @param {ITransactionsByReferenceQuery} query - Transactions by reference query.
|
* @param {TransactionsByReferenceQueryDto} query - Transactions by reference query.
|
||||||
* @returns {Promise<ITransactionsByReferencePojo>}
|
* @returns {Promise<ITransactionsByReferencePojo>}
|
||||||
*/
|
*/
|
||||||
public async getTransactions(query: ITransactionsByReferenceQuery) {
|
public async getTransactions(query: TransactionsByReferenceQueryDto) {
|
||||||
return this.transactionsByReferenceService.getTransactionsByReference(
|
return this.transactionsByReferenceService.getTransactionsByReference(
|
||||||
query,
|
query,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -18,5 +18,5 @@ export class TransactionsByReferenceQueryDto {
|
|||||||
example: '1',
|
example: '1',
|
||||||
required: true,
|
required: true,
|
||||||
})
|
})
|
||||||
referenceId: string;
|
referenceId: number;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,27 @@
|
|||||||
import {
|
import {
|
||||||
ITransactionsByReferenceQuery,
|
|
||||||
ITransactionsByReferenceTransaction,
|
ITransactionsByReferenceTransaction,
|
||||||
} from './TransactionsByReference.types';
|
} from './TransactionsByReference.types';
|
||||||
import { FinancialSheet } from '../../common/FinancialSheet';
|
import { FinancialSheet } from '../../common/FinancialSheet';
|
||||||
import { ModelObject } from 'objection';
|
import { ModelObject } from 'objection';
|
||||||
import { AccountTransaction } from '@/modules/Accounts/models/AccountTransaction.model';
|
import { AccountTransaction } from '@/modules/Accounts/models/AccountTransaction.model';
|
||||||
import { INumberFormatQuery } from '../../types/Report.types';
|
import { INumberFormatQuery } from '../../types/Report.types';
|
||||||
|
import { TransactionsByReferenceQueryDto } from './TransactionsByReferenceQuery.dto';
|
||||||
|
|
||||||
export class TransactionsByReference extends FinancialSheet {
|
export class TransactionsByReference extends FinancialSheet {
|
||||||
readonly transactions: ModelObject<AccountTransaction>[];
|
readonly transactions: ModelObject<AccountTransaction>[];
|
||||||
readonly query: ITransactionsByReferenceQuery;
|
readonly query: TransactionsByReferenceQueryDto;
|
||||||
readonly baseCurrency: string;
|
readonly baseCurrency: string;
|
||||||
readonly numberFormat: INumberFormatQuery;
|
readonly numberFormat: INumberFormatQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor method.
|
* Constructor method.
|
||||||
* @param {ModelObject<AccountTransaction>[]} transactions
|
* @param {ModelObject<AccountTransaction>[]} transactions
|
||||||
* @param {ITransactionsByReferenceQuery} query
|
* @param {TransactionsByVendorQueryDto} query
|
||||||
* @param {string} baseCurrency
|
* @param {string} baseCurrency
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
transactions: ModelObject<AccountTransaction>[],
|
transactions: ModelObject<AccountTransaction>[],
|
||||||
query: ITransactionsByReferenceQuery,
|
query: TransactionsByReferenceQueryDto,
|
||||||
baseCurrency: string
|
baseCurrency: string
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
@@ -46,12 +46,9 @@ export class TransactionsByReference extends FinancialSheet {
|
|||||||
credit: this.getAmountMeta(transaction.credit, { money: false }),
|
credit: this.getAmountMeta(transaction.credit, { money: false }),
|
||||||
debit: this.getAmountMeta(transaction.debit, { money: false }),
|
debit: this.getAmountMeta(transaction.debit, { money: false }),
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
// formattedReferenceType: transaction.referenceTypeFormatted,
|
|
||||||
formattedReferenceType: '',
|
|
||||||
|
|
||||||
referenceType: transaction.referenceType,
|
referenceType: transaction.referenceType,
|
||||||
referenceId: transaction.referenceId,
|
referenceId: transaction.referenceId,
|
||||||
|
formattedReferenceType: transaction.referenceTypeFormatted,
|
||||||
|
|
||||||
contactId: transaction.contactId,
|
contactId: transaction.contactId,
|
||||||
contactType: transaction.contactType,
|
contactType: transaction.contactType,
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import { Injectable } from '@nestjs/common';
|
|||||||
import { I18nService } from 'nestjs-i18n';
|
import { I18nService } from 'nestjs-i18n';
|
||||||
import { EventEmitter2 } from '@nestjs/event-emitter';
|
import { EventEmitter2 } from '@nestjs/event-emitter';
|
||||||
import {
|
import {
|
||||||
ITransactionsByVendorsFilter,
|
|
||||||
ITransactionsByVendorsStatement,
|
ITransactionsByVendorsStatement,
|
||||||
} from './TransactionsByVendor.types';
|
} from './TransactionsByVendor.types';
|
||||||
import { TransactionsByVendor } from './TransactionsByVendor';
|
import { TransactionsByVendor } from './TransactionsByVendor';
|
||||||
@@ -10,6 +9,7 @@ import { TransactionsByVendorRepository } from './TransactionsByVendorRepository
|
|||||||
import { TransactionsByVendorMeta } from './TransactionsByVendorMeta';
|
import { TransactionsByVendorMeta } from './TransactionsByVendorMeta';
|
||||||
import { getTransactionsByVendorDefaultQuery } from './utils';
|
import { getTransactionsByVendorDefaultQuery } from './utils';
|
||||||
import { events } from '@/common/events/events';
|
import { events } from '@/common/events/events';
|
||||||
|
import { TransactionsByVendorQueryDto } from './TransactionsByVendorQuery.dto';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TransactionsByVendorsInjectable {
|
export class TransactionsByVendorsInjectable {
|
||||||
@@ -18,15 +18,15 @@ export class TransactionsByVendorsInjectable {
|
|||||||
private readonly transactionsByVendorMeta: TransactionsByVendorMeta,
|
private readonly transactionsByVendorMeta: TransactionsByVendorMeta,
|
||||||
private readonly eventPublisher: EventEmitter2,
|
private readonly eventPublisher: EventEmitter2,
|
||||||
private readonly i18n: I18nService,
|
private readonly i18n: I18nService,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve transactions by by the customers.
|
* Retrieve transactions by by the customers.
|
||||||
* @param {ITransactionsByVendorsFilter} query - Transactions by vendors filter.
|
* @param {TransactionsByVendorQueryDto} query - Transactions by vendors filter.
|
||||||
* @return {Promise<ITransactionsByVendorsStatement>}
|
* @return {Promise<ITransactionsByVendorsStatement>}
|
||||||
*/
|
*/
|
||||||
public async transactionsByVendors(
|
public async transactionsByVendors(
|
||||||
query: ITransactionsByVendorsFilter,
|
query: TransactionsByVendorQueryDto,
|
||||||
): Promise<ITransactionsByVendorsStatement> {
|
): Promise<ITransactionsByVendorsStatement> {
|
||||||
const filter = { ...getTransactionsByVendorDefaultQuery(), ...query };
|
const filter = { ...getTransactionsByVendorDefaultQuery(), ...query };
|
||||||
|
|
||||||
|
|||||||
@@ -1,26 +1,26 @@
|
|||||||
import { TransactionsByVendorsTable } from './TransactionsByVendorTable';
|
import { TransactionsByVendorsTable } from './TransactionsByVendorTable';
|
||||||
import {
|
import {
|
||||||
ITransactionsByVendorTable,
|
ITransactionsByVendorTable,
|
||||||
ITransactionsByVendorsFilter,
|
|
||||||
} from './TransactionsByVendor.types';
|
} from './TransactionsByVendor.types';
|
||||||
import { TransactionsByVendorsInjectable } from './TransactionsByVendorInjectable';
|
import { TransactionsByVendorsInjectable } from './TransactionsByVendorInjectable';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { I18nService } from 'nestjs-i18n';
|
import { I18nService } from 'nestjs-i18n';
|
||||||
|
import { TransactionsByVendorQueryDto } from './TransactionsByVendorQuery.dto';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TransactionsByVendorTableInjectable {
|
export class TransactionsByVendorTableInjectable {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly transactionsByVendor: TransactionsByVendorsInjectable,
|
private readonly transactionsByVendor: TransactionsByVendorsInjectable,
|
||||||
private readonly i18n: I18nService
|
private readonly i18n: I18nService
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the transactions by vendor in table format.
|
* Retrieves the transactions by vendor in table format.
|
||||||
* @param {ITransactionsByReferenceQuery} query - The filter query.
|
* @param {TransactionsByVendorQueryDto} query - The filter query.
|
||||||
* @returns {Promise<ITransactionsByVendorTable>}
|
* @returns {Promise<ITransactionsByVendorTable>}
|
||||||
*/
|
*/
|
||||||
public async table(
|
public async table(
|
||||||
query: ITransactionsByVendorsFilter
|
query: TransactionsByVendorQueryDto
|
||||||
): Promise<ITransactionsByVendorTable> {
|
): Promise<ITransactionsByVendorTable> {
|
||||||
const sheet = await this.transactionsByVendor.transactionsByVendors(
|
const sheet = await this.transactionsByVendor.transactionsByVendors(
|
||||||
query
|
query
|
||||||
|
|||||||
Reference in New Issue
Block a user