refactor: tenant proxy providers

This commit is contained in:
Ahmed Bouhuolia
2025-02-15 23:52:12 +02:00
parent 36851d3209
commit 5c0bb52b59
302 changed files with 2396 additions and 1677 deletions

View File

@@ -4,6 +4,7 @@ import { EventEmitter2 } from '@nestjs/event-emitter';
import { StripePaymentService } from './StripePaymentService';
import { events } from '@/common/events/events';
import { PaymentIntegration } from './models/PaymentIntegration.model';
import { TenantModelProxy } from '../System/models/TenantBaseModel';
@Injectable()
export class CreateStripeAccountService {
@@ -12,7 +13,9 @@ export class CreateStripeAccountService {
private readonly eventPublisher: EventEmitter2,
@Inject(PaymentIntegration.name)
private readonly paymentIntegrationModel: typeof PaymentIntegration,
private readonly paymentIntegrationModel: TenantModelProxy<
typeof PaymentIntegration
>,
) {}
/**
@@ -31,7 +34,7 @@ export class CreateStripeAccountService {
...stripeAccountDTO,
};
// Stores the details of the Stripe account.
await this.paymentIntegrationModel.query().insert({
await this.paymentIntegrationModel().query().insert({
name: parsedStripeAccountDTO.name,
accountId: stripeAccountId,
active: false, // Active will turn true after onboarding.

View File

@@ -6,6 +6,7 @@ import { UnitOfWork } from '../Tenancy/TenancyDB/UnitOfWork.service';
import { EventEmitter2 } from '@nestjs/event-emitter';
import { PaymentIntegration } from './models/PaymentIntegration.model';
import { events } from '@/common/events/events';
import { TenantModelProxy } from '../System/models/TenantBaseModel';
@Injectable()
export class ExchangeStripeOAuthTokenService {
@@ -15,7 +16,9 @@ export class ExchangeStripeOAuthTokenService {
private readonly uow: UnitOfWork,
@Inject(PaymentIntegration.name)
private readonly paymentIntegrationModel: typeof PaymentIntegration,
private readonly paymentIntegrationModel: TenantModelProxy<
typeof PaymentIntegration
>,
) {}
/**
@@ -43,7 +46,7 @@ export class ExchangeStripeOAuthTokenService {
return this.uow.withTransaction(async (trx: Knex.Transaction) => {
// Stores the details of the Stripe account.
const paymentIntegration = await this.paymentIntegrationModel
const paymentIntegration = await this.paymentIntegrationModel()
.query(trx)
.insert({
name: companyName,

View File

@@ -4,14 +4,21 @@ import { events } from '@/common/events/events';
import { AccountRepository } from '@/modules/Accounts/repositories/Account.repository';
import { PaymentIntegration } from '../models/PaymentIntegration.model';
import { StripeOAuthCodeGrantedEventPayload } from '../types';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
@Injectable()
export class SeedStripeAccountsOnOAuthGrantedSubscriber {
/**
* @param {AccountRepository} accountRepository
* @param {TenantModelProxy<typeof PaymentIntegration>} paymentIntegrationModel
*/
constructor(
private readonly accountRepository: AccountRepository,
@Inject(PaymentIntegration.name)
private readonly paymentIntegrationModel: typeof PaymentIntegration,
private readonly paymentIntegrationModel: TenantModelProxy<
typeof PaymentIntegration
>,
) {}
/**
@@ -29,7 +36,7 @@ export class SeedStripeAccountsOnOAuthGrantedSubscriber {
const bankAccount = await this.accountRepository.findBySlug('bank-account');
// Patch the Stripe integration default settings.
await this.paymentIntegrationModel
await this.paymentIntegrationModel()
.query(trx)
.findById(paymentIntegrationId)
.patch({

View File

@@ -9,6 +9,7 @@ import { OnEvent } from '@nestjs/event-emitter';
import { Inject, Injectable } from '@nestjs/common';
import { events } from '@/common/events/events';
import { PaymentIntegration } from '../models/PaymentIntegration.model';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
@Injectable()
export class StripeWebhooksSubscriber {
@@ -16,7 +17,9 @@ export class StripeWebhooksSubscriber {
private readonly createPaymentReceiveStripePayment: CreatePaymentReceiveStripePayment,
@Inject(PaymentIntegration.name)
private readonly paymentIntegrationModel: typeof PaymentIntegration,
private readonly paymentIntegrationModel: TenantModelProxy<
typeof PaymentIntegration
>,
) {}
/**
@@ -65,7 +68,7 @@ export class StripeWebhooksSubscriber {
// Check if the account capabilities are active
if (account.capabilities.card_payments === 'active') {
// Marks the payment method integration as active.
await this.paymentIntegrationModel
await this.paymentIntegrationModel()
.query()
.findById(metadata?.paymentIntegrationId)
.patch({