mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
Merge branch 'develop' into disconnect-bank-account
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import PromisePool from '@supercharge/promise-pool';
|
||||
import { castArray } from 'lodash';
|
||||
import { ExcludeBankTransaction } from './ExcludeBankTransaction';
|
||||
|
||||
@Service()
|
||||
export class ExcludeBankTransactions {
|
||||
@Inject()
|
||||
private excludeBankTransaction: ExcludeBankTransaction;
|
||||
|
||||
/**
|
||||
* Exclude bank transactions in bulk.
|
||||
* @param {number} tenantId
|
||||
* @param {number} bankTransactionIds
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public async excludeBankTransactions(
|
||||
tenantId: number,
|
||||
bankTransactionIds: Array<number> | number
|
||||
) {
|
||||
const _bankTransactionIds = castArray(bankTransactionIds);
|
||||
|
||||
await PromisePool.withConcurrency(1)
|
||||
.for(_bankTransactionIds)
|
||||
.process((bankTransactionId: number) => {
|
||||
return this.excludeBankTransaction.excludeBankTransaction(
|
||||
tenantId,
|
||||
bankTransactionId
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,8 @@ import { ExcludeBankTransaction } from './ExcludeBankTransaction';
|
||||
import { UnexcludeBankTransaction } from './UnexcludeBankTransaction';
|
||||
import { GetExcludedBankTransactionsService } from './GetExcludedBankTransactions';
|
||||
import { ExcludedBankTransactionsQuery } from './_types';
|
||||
import { UnexcludeBankTransactions } from './UnexcludeBankTransactions';
|
||||
import { ExcludeBankTransactions } from './ExcludeBankTransactions';
|
||||
|
||||
@Service()
|
||||
export class ExcludeBankTransactionsApplication {
|
||||
@@ -15,6 +17,12 @@ export class ExcludeBankTransactionsApplication {
|
||||
@Inject()
|
||||
private getExcludedBankTransactionsService: GetExcludedBankTransactionsService;
|
||||
|
||||
@Inject()
|
||||
private excludeBankTransactionsService: ExcludeBankTransactions;
|
||||
|
||||
@Inject()
|
||||
private unexcludeBankTransactionsService: UnexcludeBankTransactions;
|
||||
|
||||
/**
|
||||
* Marks a bank transaction as excluded.
|
||||
* @param {number} tenantId - The ID of the tenant.
|
||||
@@ -56,4 +64,36 @@ export class ExcludeBankTransactionsApplication {
|
||||
filter
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude the given bank transactions in bulk.
|
||||
* @param {number} tenantId
|
||||
* @param {Array<number> | number} bankTransactionIds
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public excludeBankTransactions(
|
||||
tenantId: number,
|
||||
bankTransactionIds: Array<number> | number
|
||||
): Promise<void> {
|
||||
return this.excludeBankTransactionsService.excludeBankTransactions(
|
||||
tenantId,
|
||||
bankTransactionIds
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exclude the given bank transactions in bulk.
|
||||
* @param {number} tenantId
|
||||
* @param {Array<number> | number} bankTransactionIds
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public unexcludeBankTransactions(
|
||||
tenantId: number,
|
||||
bankTransactionIds: Array<number> | number
|
||||
): Promise<void> {
|
||||
return this.unexcludeBankTransactionsService.unexcludeBankTransactions(
|
||||
tenantId,
|
||||
bankTransactionIds
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import PromisePool from '@supercharge/promise-pool';
|
||||
import { UnexcludeBankTransaction } from './UnexcludeBankTransaction';
|
||||
import { castArray } from 'lodash';
|
||||
|
||||
@Service()
|
||||
export class UnexcludeBankTransactions {
|
||||
@Inject()
|
||||
private unexcludeBankTransaction: UnexcludeBankTransaction;
|
||||
|
||||
/**
|
||||
* Unexclude bank transactions in bulk.
|
||||
* @param {number} tenantId
|
||||
* @param {number} bankTransactionIds
|
||||
*/
|
||||
public async unexcludeBankTransactions(
|
||||
tenantId: number,
|
||||
bankTransactionIds: Array<number> | number
|
||||
) {
|
||||
const _bankTransactionIds = castArray(bankTransactionIds);
|
||||
|
||||
await PromisePool.withConcurrency(1)
|
||||
.for(_bankTransactionIds)
|
||||
.process((bankTransactionId: number) => {
|
||||
return this.unexcludeBankTransaction.unexcludeBankTransaction(
|
||||
tenantId,
|
||||
bankTransactionId
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -45,9 +45,9 @@ export class CustomersApplication {
|
||||
|
||||
/**
|
||||
* Creates a new customer.
|
||||
* @param {number} tenantId
|
||||
* @param {ICustomerNewDTO} customerDTO
|
||||
* @param {ISystemUser} authorizedUser
|
||||
* @param {number} tenantId
|
||||
* @param {ICustomerNewDTO} customerDTO
|
||||
* @param {ISystemUser} authorizedUser
|
||||
* @returns {Promise<ICustomer>}
|
||||
*/
|
||||
public createCustomer = (tenantId: number, customerDTO: ICustomerNewDTO) => {
|
||||
@@ -56,9 +56,9 @@ export class CustomersApplication {
|
||||
|
||||
/**
|
||||
* Edits details of the given customer.
|
||||
* @param {number} tenantId
|
||||
* @param {number} customerId
|
||||
* @param {ICustomerEditDTO} customerDTO
|
||||
* @param {number} tenantId
|
||||
* @param {number} customerId
|
||||
* @param {ICustomerEditDTO} customerDTO
|
||||
* @return {Promise<ICustomer>}
|
||||
*/
|
||||
public editCustomer = (
|
||||
@@ -75,9 +75,9 @@ export class CustomersApplication {
|
||||
|
||||
/**
|
||||
* Deletes the given customer and associated transactions.
|
||||
* @param {number} tenantId
|
||||
* @param {number} customerId
|
||||
* @param {ISystemUser} authorizedUser
|
||||
* @param {number} tenantId
|
||||
* @param {number} customerId
|
||||
* @param {ISystemUser} authorizedUser
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public deleteCustomer = (
|
||||
@@ -94,9 +94,9 @@ export class CustomersApplication {
|
||||
|
||||
/**
|
||||
* Changes the opening balance of the given customer.
|
||||
* @param {number} tenantId
|
||||
* @param {number} customerId
|
||||
* @param {Date|string} openingBalanceEditDTO
|
||||
* @param {number} tenantId
|
||||
* @param {number} customerId
|
||||
* @param {Date|string} openingBalanceEditDTO
|
||||
* @returns {Promise<ICustomer>}
|
||||
*/
|
||||
public editOpeningBalance = (
|
||||
|
||||
51
packages/server/src/services/Loops/LoopsEventsSubscriber.ts
Normal file
51
packages/server/src/services/Loops/LoopsEventsSubscriber.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
import axios from 'axios';
|
||||
import config from '@/config';
|
||||
import { IAuthSignUpVerifiedEventPayload } from '@/interfaces';
|
||||
import events from '@/subscribers/events';
|
||||
import { SystemUser } from '@/system/models';
|
||||
|
||||
export class LoopsEventsSubscriber {
|
||||
/**
|
||||
* Constructor method.
|
||||
*/
|
||||
public attach(bus) {
|
||||
bus.subscribe(
|
||||
events.auth.signUpConfirmed,
|
||||
this.triggerEventOnSignupVerified.bind(this)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Once the user verified sends the event to the Loops.
|
||||
* @param {IAuthSignUpVerifiedEventPayload} param0
|
||||
*/
|
||||
public async triggerEventOnSignupVerified({
|
||||
email,
|
||||
userId,
|
||||
}: IAuthSignUpVerifiedEventPayload) {
|
||||
// Can't continue since the Loops the api key is not configured.
|
||||
if (!config.loops.apiKey) {
|
||||
return;
|
||||
}
|
||||
const user = await SystemUser.query().findById(userId);
|
||||
|
||||
const options = {
|
||||
method: 'POST',
|
||||
url: 'https://app.loops.so/api/v1/events/send',
|
||||
headers: {
|
||||
Authorization: `Bearer ${config.loops.apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
data: {
|
||||
email,
|
||||
userId,
|
||||
firstName: user.firstName,
|
||||
lastName: user.lastName,
|
||||
eventName: 'USER_VERIFIED',
|
||||
eventProperties: {},
|
||||
mailingLists: {},
|
||||
},
|
||||
};
|
||||
await axios(options);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ import { omit, sumBy } from 'lodash';
|
||||
import { IBillPayment, IBillPaymentDTO, IVendor } from '@/interfaces';
|
||||
import { BranchTransactionDTOTransform } from '@/services/Branches/Integrations/BranchTransactionDTOTransform';
|
||||
import { formatDateFields } from '@/utils';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
|
||||
@Service()
|
||||
export class CommandBillPaymentDTOTransformer {
|
||||
@@ -23,11 +24,14 @@ export class CommandBillPaymentDTOTransformer {
|
||||
vendor: IVendor,
|
||||
oldBillPayment?: IBillPayment
|
||||
): Promise<IBillPayment> {
|
||||
const amount =
|
||||
billPaymentDTO.amount ?? sumBy(billPaymentDTO.entries, 'paymentAmount');
|
||||
|
||||
const initialDTO = {
|
||||
...formatDateFields(omit(billPaymentDTO, ['attachments']), [
|
||||
'paymentDate',
|
||||
]),
|
||||
amount: sumBy(billPaymentDTO.entries, 'paymentAmount'),
|
||||
amount,
|
||||
currencyCode: vendor.currencyCode,
|
||||
exchangeRate: billPaymentDTO.exchangeRate || 1,
|
||||
entries: billPaymentDTO.entries,
|
||||
|
||||
@@ -36,7 +36,9 @@ export class PaymentReceiveDTOTransformer {
|
||||
paymentReceiveDTO: IPaymentReceiveCreateDTO | IPaymentReceiveEditDTO,
|
||||
oldPaymentReceive?: IPaymentReceive
|
||||
): Promise<IPaymentReceive> {
|
||||
const paymentAmount = sumBy(paymentReceiveDTO.entries, 'paymentAmount');
|
||||
const amount =
|
||||
paymentReceiveDTO.amount ??
|
||||
sumBy(paymentReceiveDTO.entries, 'paymentAmount');
|
||||
|
||||
// Retreive the next invoice number.
|
||||
const autoNextNumber =
|
||||
@@ -54,7 +56,7 @@ export class PaymentReceiveDTOTransformer {
|
||||
...formatDateFields(omit(paymentReceiveDTO, ['entries', 'attachments']), [
|
||||
'paymentDate',
|
||||
]),
|
||||
amount: paymentAmount,
|
||||
amount,
|
||||
currencyCode: customer.currencyCode,
|
||||
...(paymentReceiveNo ? { paymentReceiveNo } : {}),
|
||||
exchangeRate: paymentReceiveDTO.exchangeRate || 1,
|
||||
|
||||
@@ -77,7 +77,12 @@ export default class HasTenancyService {
|
||||
const knex = this.knex(tenantId);
|
||||
const i18n = this.i18n(tenantId);
|
||||
|
||||
return tenantRepositoriesLoader(knex, cache, i18n);
|
||||
const repositories = tenantRepositoriesLoader(knex, cache, i18n);
|
||||
|
||||
Object.values(repositories).forEach((repository) => {
|
||||
repository.setTenantId(tenantId);
|
||||
});
|
||||
return repositories;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user