mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2026-10-25 01:37:56 +00:00
feat: add neoleap service and mock create application api
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import { INeoleapHeaderRequest } from './neoleap-header.request.interface';
|
||||
|
||||
export interface ICreateApplicationRequest extends INeoleapHeaderRequest {
|
||||
CreateNewApplicationRequestDetails: {
|
||||
ApplicationRequestDetails: {
|
||||
InstitutionCode: string;
|
||||
ExternalApplicationNumber: string;
|
||||
ApplicationType: string;
|
||||
Product: string;
|
||||
ApplicationDate: string;
|
||||
BranchCode: '000';
|
||||
ApplicationSource: 'O';
|
||||
DeliveryMethod: 'V';
|
||||
};
|
||||
ApplicationProcessingDetails: {
|
||||
ProcessControl: string;
|
||||
RequestedLimit: number;
|
||||
SuggestedLimit: number;
|
||||
AssignedLimit: number;
|
||||
};
|
||||
|
||||
ApplicationCustomerDetails: {
|
||||
Title: string;
|
||||
FirstName: string;
|
||||
LastName: string;
|
||||
FullName: string;
|
||||
EmbossName: string;
|
||||
DateOfBirth: string;
|
||||
LocalizedDateOfBirth: string;
|
||||
Gender: string;
|
||||
Nationality: string;
|
||||
IdType: string;
|
||||
IdNumber: string;
|
||||
IdExpiryDate: string;
|
||||
};
|
||||
|
||||
ApplicationAddress: {
|
||||
AddressLine1: string;
|
||||
AddressLine2: string;
|
||||
City: string;
|
||||
Region: string;
|
||||
Country: string;
|
||||
CountryDetails: {
|
||||
DefaultCurrency: {};
|
||||
Description: [];
|
||||
};
|
||||
Phone1: string;
|
||||
Email: string;
|
||||
AddressRole: number;
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './create-application.request.interface';
|
||||
export * from './neoleap-header.request.interface';
|
||||
@@ -0,0 +1,9 @@
|
||||
export interface INeoleapHeaderRequest {
|
||||
RequestHeader: {
|
||||
Version: string;
|
||||
MsgUid: string;
|
||||
Source: 'FINTECH';
|
||||
ServiceId: string;
|
||||
ReqDateTime: Date;
|
||||
};
|
||||
}
|
||||
@@ -1,6 +1,99 @@
|
||||
import { HttpService } from '@nestjs/axios';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import moment from 'moment';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { CountriesNumericISO } from '~/common/constants';
|
||||
import { Customer } from '~/customer/entities';
|
||||
import { Gender } from '~/customer/enums';
|
||||
import { ICreateApplicationRequest, INeoleapHeaderRequest } from '../interfaces';
|
||||
@Injectable()
|
||||
export class NeoLeapService {
|
||||
createApplication() {}
|
||||
private readonly baseUrl: string;
|
||||
private readonly apiKey: string;
|
||||
private readonly useMock: boolean;
|
||||
private readonly institutionCode = '1100';
|
||||
constructor(private readonly httpService: HttpService, private readonly configService: ConfigService) {
|
||||
this.baseUrl = this.configService.getOrThrow<string>('NEOLEAP_BASE_URL');
|
||||
this.apiKey = this.configService.getOrThrow<string>('NEOLEAP_API_KEY');
|
||||
this.useMock = [true, 'true'].includes(this.configService.get<boolean>('USE_MOCK', false));
|
||||
}
|
||||
|
||||
async createApplication(customer: Customer) {
|
||||
if (this.useMock) {
|
||||
//@TODO return mock data
|
||||
return;
|
||||
}
|
||||
|
||||
const payload: ICreateApplicationRequest = {
|
||||
CreateNewApplicationRequestDetails: {
|
||||
ApplicationRequestDetails: {
|
||||
InstitutionCode: this.institutionCode,
|
||||
ExternalApplicationNumber: customer.waitingNumber.toString(),
|
||||
ApplicationType: 'New',
|
||||
Product: '3001',
|
||||
ApplicationDate: moment().format('YYYY-MM-DD'),
|
||||
BranchCode: '000',
|
||||
ApplicationSource: 'O',
|
||||
DeliveryMethod: 'V',
|
||||
},
|
||||
ApplicationProcessingDetails: {
|
||||
SuggestedLimit: 0,
|
||||
RequestedLimit: 0,
|
||||
AssignedLimit: 0,
|
||||
ProcessControl: 'STND',
|
||||
},
|
||||
ApplicationCustomerDetails: {
|
||||
FirstName: customer.firstName,
|
||||
LastName: customer.lastName,
|
||||
FullName: `${customer.firstName} ${customer.lastName}`,
|
||||
DateOfBirth: moment(customer.dateOfBirth).format('YYYY-MM-DD'),
|
||||
EmbossName: `${customer.firstName} ${customer.lastName}`, // TODO Enter Emboss Name
|
||||
IdType: '001',
|
||||
IdNumber: customer.nationalId,
|
||||
IdExpiryDate: moment(customer.nationalIdExpiry).format('YYYY-MM-DD'),
|
||||
Title: customer.gender === Gender.MALE ? 'Mr' : 'Ms',
|
||||
Gender: customer.gender === Gender.MALE ? 'M' : 'F',
|
||||
LocalizedDateOfBirth: moment(customer.dateOfBirth).format('YYYY-MM-DD'),
|
||||
Nationality: '682',
|
||||
},
|
||||
ApplicationAddress: {
|
||||
City: customer.city,
|
||||
Country: CountriesNumericISO[customer.countryOfResidence],
|
||||
Region: customer.region,
|
||||
AddressLine1: `${customer.street} ${customer.building}`,
|
||||
AddressLine2: customer.neighborhood,
|
||||
AddressRole: 0,
|
||||
Email: customer.user.email,
|
||||
Phone1: customer.user.phoneNumber,
|
||||
CountryDetails: {
|
||||
DefaultCurrency: {},
|
||||
Description: [],
|
||||
},
|
||||
},
|
||||
},
|
||||
...this.prepareHeaders('CreateNewApplication'),
|
||||
};
|
||||
|
||||
const response = await this.httpService.axiosRef.post(`${this.baseUrl}/create-application`, payload, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `${this.apiKey}`,
|
||||
},
|
||||
});
|
||||
|
||||
//@TODO handle response
|
||||
}
|
||||
|
||||
private prepareHeaders(serviceName: string): INeoleapHeaderRequest {
|
||||
return {
|
||||
RequestHeader: {
|
||||
Version: '1.0.0',
|
||||
MsgUid: uuid(),
|
||||
Source: 'FINTECH',
|
||||
ServiceId: serviceName,
|
||||
ReqDateTime: new Date(),
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user