mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
feat(nestjs): migrate to NestJS
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
import { CreateStripeAccountDTO } from './types';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
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 {
|
||||
constructor(
|
||||
private readonly stripePaymentService: StripePaymentService,
|
||||
private readonly eventPublisher: EventEmitter2,
|
||||
|
||||
@Inject(PaymentIntegration.name)
|
||||
private readonly paymentIntegrationModel: TenantModelProxy<
|
||||
typeof PaymentIntegration
|
||||
>,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Creates a new Stripe account.
|
||||
* @param {CreateStripeAccountDTO} stripeAccountDTO
|
||||
* @returns {Promise<string>}
|
||||
*/
|
||||
async createStripeAccount(
|
||||
stripeAccountDTO?: CreateStripeAccountDTO,
|
||||
): Promise<string> {
|
||||
const stripeAccount = await this.stripePaymentService.createAccount();
|
||||
const stripeAccountId = stripeAccount.id;
|
||||
|
||||
const parsedStripeAccountDTO = {
|
||||
name: 'Stripe',
|
||||
...stripeAccountDTO,
|
||||
};
|
||||
// Stores the details of the Stripe account.
|
||||
await this.paymentIntegrationModel().query().insert({
|
||||
name: parsedStripeAccountDTO.name,
|
||||
accountId: stripeAccountId,
|
||||
active: false, // Active will turn true after onboarding.
|
||||
service: 'Stripe',
|
||||
});
|
||||
// Triggers `onStripeIntegrationAccountCreated` event.
|
||||
await this.eventPublisher.emitAsync(
|
||||
events.stripeIntegration.onAccountCreated,
|
||||
{
|
||||
stripeAccountDTO,
|
||||
stripeAccountId,
|
||||
},
|
||||
);
|
||||
return stripeAccountId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user