mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 12:20:31 +00:00
refactor(nestjs): loops module
This commit is contained in:
@@ -76,6 +76,7 @@ import { TenantDBManagerModule } from '../TenantDBManager/TenantDBManager.module
|
||||
import { PaymentServicesModule } from '../PaymentServices/PaymentServices.module';
|
||||
import { AuthModule } from '../Auth/Auth.module';
|
||||
import { TenancyModule } from '../Tenancy/Tenancy.module';
|
||||
import { LoopsModule } from '../Loops/Loops.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -187,6 +188,7 @@ import { TenancyModule } from '../Tenancy/Tenancy.module';
|
||||
OrganizationModule,
|
||||
TenantDBManagerModule,
|
||||
PaymentServicesModule,
|
||||
LoopsModule
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [
|
||||
|
||||
@@ -17,8 +17,8 @@ import { LocalAuthGuard } from './guards/local.guard';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import { AuthSigninService } from './commands/AuthSignin.service';
|
||||
|
||||
@ApiTags('Auth')
|
||||
@Controller('/auth')
|
||||
@ApiTags('Auth')
|
||||
@PublicRoute()
|
||||
export class AuthController {
|
||||
constructor(
|
||||
|
||||
7
packages/server-nest/src/modules/Loops/Loops.module.ts
Normal file
7
packages/server-nest/src/modules/Loops/Loops.module.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { LoopsEventsSubscriber } from './LoopsEvents.subscriber';
|
||||
|
||||
@Module({
|
||||
providers: [LoopsEventsSubscriber],
|
||||
})
|
||||
export class LoopsModule {}
|
||||
@@ -0,0 +1,56 @@
|
||||
import axios from 'axios';
|
||||
import { OnEvent } from '@nestjs/event-emitter';
|
||||
import { Inject, Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { IAuthSignUpVerifiedEventPayload } from '../Auth/Auth.interfaces';
|
||||
import { SystemUser } from '../System/models/SystemUser';
|
||||
import { events } from '@/common/events/events';
|
||||
|
||||
@Injectable()
|
||||
export class LoopsEventsSubscriber {
|
||||
|
||||
constructor(
|
||||
private readonly configService: ConfigService,
|
||||
|
||||
@Inject(SystemUser.name)
|
||||
private readonly systemUserModel: typeof SystemUser
|
||||
) {
|
||||
|
||||
}
|
||||
/**
|
||||
* Once the user verified sends the event to the Loops.
|
||||
* @param {IAuthSignUpVerifiedEventPayload} param0
|
||||
*/
|
||||
@OnEvent(events.auth.signUpConfirmed)
|
||||
public async triggerEventOnSignupVerified({
|
||||
email,
|
||||
userId,
|
||||
}: IAuthSignUpVerifiedEventPayload) {
|
||||
const apiKey = this.configService.get('loops.apiKey');
|
||||
|
||||
// Can't continue since the Loops the api key is not configured.
|
||||
if (!apiKey) {
|
||||
return;
|
||||
}
|
||||
const user = await this.systemUserModel.query().findById(userId);
|
||||
|
||||
const options = {
|
||||
method: 'POST',
|
||||
url: 'https://app.loops.so/api/v1/events/send',
|
||||
headers: {
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
data: {
|
||||
email,
|
||||
userId,
|
||||
firstName: user.firstName,
|
||||
lastName: user.lastName,
|
||||
eventName: 'USER_VERIFIED',
|
||||
eventProperties: {},
|
||||
mailingLists: {},
|
||||
},
|
||||
};
|
||||
await axios(options);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user