feat(nestjs): migrate to NestJS

This commit is contained in:
Ahmed Bouhuolia
2025-04-07 11:51:24 +02:00
parent f068218a16
commit 55fcc908ef
3779 changed files with 631 additions and 195332 deletions

View File

@@ -0,0 +1,7 @@
import { Module } from '@nestjs/common';
import { LoopsEventsSubscriber } from './LoopsEvents.subscriber';
@Module({
providers: [LoopsEventsSubscriber],
})
export class LoopsModule {}

View File

@@ -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);
}
}