mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-09 22:57:26 +00:00
feat:integration brancjio dynamic links to junior qr code registration
This commit is contained in:
11
.env.example
11
.env.example
@ -28,4 +28,13 @@ MAIL_HOST=smtp.gmail.com
|
||||
MAIL_USER=aahalhmad@gmail.com
|
||||
MAIL_PASSWORD=
|
||||
MAIL_PORT=587
|
||||
MAIL_FROM=UBA
|
||||
MAIL_FROM=UBA
|
||||
|
||||
|
||||
BRANCH_IO_URL=https://api2.branch.io/v1/url
|
||||
BRANCH_IO_KEY=
|
||||
ZOD_BASE_URL=http://localhost:5001
|
||||
ANDROID_PACKAGE_NAME=com.zod
|
||||
IOS_PACKAGE_NAME=com.zod
|
||||
ANDRIOD_JUNIOR_DEEPLINK_PATH=zodbank://juniors/qr-code/validate
|
||||
IOS_JUNIOR_DEEPLINK_PATH=zodbank://juniors/qr-code/validate
|
@ -1,3 +1,4 @@
|
||||
import { HttpModule } from '@nestjs/axios';
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { CustomerModule } from '~/customer/customer.module';
|
||||
@ -5,12 +6,19 @@ import { UserModule } from '~/user/user.module';
|
||||
import { JuniorController } from './controllers';
|
||||
import { Junior, JuniorRegistrationToken, Theme } from './entities';
|
||||
import { JuniorRepository, JuniorTokenRepository } from './repositories';
|
||||
import { JuniorService, JuniorTokenService, QrcodeService } from './services';
|
||||
import { BranchIoService, JuniorService, JuniorTokenService, QrcodeService } from './services';
|
||||
|
||||
@Module({
|
||||
controllers: [JuniorController],
|
||||
providers: [JuniorService, JuniorRepository, JuniorTokenService, JuniorTokenRepository, QrcodeService],
|
||||
imports: [TypeOrmModule.forFeature([Junior, Theme, JuniorRegistrationToken]), UserModule, CustomerModule],
|
||||
providers: [
|
||||
JuniorService,
|
||||
JuniorRepository,
|
||||
JuniorTokenService,
|
||||
JuniorTokenRepository,
|
||||
QrcodeService,
|
||||
BranchIoService,
|
||||
],
|
||||
imports: [TypeOrmModule.forFeature([Junior, Theme, JuniorRegistrationToken]), UserModule, CustomerModule, HttpModule],
|
||||
exports: [JuniorService, JuniorTokenService],
|
||||
})
|
||||
export class JuniorModule {}
|
||||
|
43
src/junior/services/branch-io.service.ts
Normal file
43
src/junior/services/branch-io.service.ts
Normal file
@ -0,0 +1,43 @@
|
||||
import { HttpService } from '@nestjs/axios';
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
|
||||
@Injectable()
|
||||
export class BranchIoService {
|
||||
private readonly logger = new Logger(BranchIoService.name);
|
||||
private readonly branchIoKey = this.configService.getOrThrow<string>('BRANCH_IO_KEY');
|
||||
private readonly branchIoUrl = this.configService.getOrThrow<string>('BRANCH_IO_URL');
|
||||
private readonly zodBaseUrl = this.configService.getOrThrow<string>('ZOD_BASE_URL');
|
||||
private readonly andrioPackageName = this.configService.getOrThrow<string>('ANDROID_PACKAGE_NAME');
|
||||
private readonly iosPackageName = this.configService.getOrThrow<string>('IOS_PACKAGE_NAME');
|
||||
private readonly androidDeeplinkPath = this.configService.getOrThrow<string>('ANDRIOD_JUNIOR_DEEPLINK_PATH');
|
||||
private readonly iosDeeplinkPath = this.configService.getOrThrow<string>('IOS_JUNIOR_DEEPLINK_PATH');
|
||||
constructor(private readonly configService: ConfigService, private readonly httpService: HttpService) {}
|
||||
|
||||
async createBranchLink(token: string) {
|
||||
this.logger.log(`Creating branch link`);
|
||||
const payload = {
|
||||
branch_key: this.branchIoKey,
|
||||
channel: 'Website',
|
||||
feature: 'Share',
|
||||
alias: token,
|
||||
data: {
|
||||
$desktop_url: `${this.zodBaseUrl}/juniors/qr-code/${token}/validate`,
|
||||
$android_package: this.andrioPackageName,
|
||||
$ios_package: this.iosPackageName,
|
||||
$android_deeplink_path: this.androidDeeplinkPath,
|
||||
$ios_url: this.iosDeeplinkPath,
|
||||
token: token,
|
||||
},
|
||||
};
|
||||
const response = await this.httpService.axiosRef({
|
||||
url: this.branchIoUrl,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
data: payload,
|
||||
});
|
||||
return response.data.url;
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
export * from './branch-io.service';
|
||||
export * from './junior-token.service';
|
||||
export * from './junior.service';
|
||||
export * from './qrcode.service';
|
||||
|
@ -1,11 +1,16 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import * as qrcode from 'qrcode';
|
||||
import { BranchIoService } from './branch-io.service';
|
||||
|
||||
@Injectable()
|
||||
export class QrcodeService {
|
||||
constructor(private readonly branchIoService: BranchIoService) {}
|
||||
private readonly logger = new Logger(QrcodeService.name);
|
||||
generateQrCode(token: string): Promise<string> {
|
||||
async generateQrCode(token: string): Promise<string> {
|
||||
this.logger.log(`Generating QR code for token ${token}`);
|
||||
return qrcode.toDataURL(token);
|
||||
|
||||
const link = await this.branchIoService.createBranchLink(token);
|
||||
|
||||
return qrcode.toDataURL(link);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user