mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-25 21:59:40 +00:00
Compare commits
146 Commits
feat/uploa
...
e775561a89
Author | SHA1 | Date | |
---|---|---|---|
e775561a89 | |||
241f1ce427 | |||
d883bd2d9a | |||
cd800ff8b8 | |||
05a9f04ac8 | |||
dcc9077392 | |||
681d1e5791 | |||
bf505a65bf | |||
6bf32d27c7 | |||
ac63d4cdc7 | |||
150027fb71 | |||
e8ee74d0d7 | |||
5f2e06edf9 | |||
99ad17f0f9 | |||
ee7b365527 | |||
275984954e | |||
6f7fb2bdcd | |||
1e2b859b92 | |||
4cc52a1c07 | |||
7461af20dd | |||
f65a7d2933 | |||
fce720237f | |||
5e0a4e6bd1 | |||
f9776e60cf | |||
7e63abb2fb | |||
a245545811 | |||
4cb5814cd3 | |||
9e06ea4d71 | |||
cff87c4ecd | |||
1541c374ed | |||
c493bd57e1 | |||
bf43e62b17 | |||
5a780eeb17 | |||
038b8ef6e3 | |||
3b3f8c0104 | |||
2770cf8774 | |||
bea3ccfbbc | |||
492e538eb8 | |||
d3057beb54 | |||
19fa53c981 | |||
d2cc02fb60 | |||
4cbbfd8136 | |||
6c859a25d2 | |||
d1a6d3e715 | |||
1ea1f42169 | |||
d4fe3b3fc3 | |||
b44bc5d5cc | |||
9aa6c487ed | |||
42e4d75d70 | |||
a358cd2e7a | |||
641a665beb | |||
49326e983f | |||
881d88c8d8 | |||
35ab3df7c1 | |||
cbade0a87d | |||
4c6ef17525 | |||
ffca6996fd | |||
a3f88c774c | |||
ec38b82a7b | |||
9b5f863577 | |||
54ce5b022d | |||
dae9cb6323 | |||
270753cfd7 | |||
6b1cb3a84e | |||
ebd4b293e9 | |||
87bb1a2709 | |||
663e8972c4 | |||
8ff9f921e8 | |||
6d2d2b558a | |||
5aa3d3774d | |||
221f3bae4f | |||
62621c1a15 | |||
756e947c8a | |||
db02a28b4d | |||
afc087ff08 | |||
ee433a5c8c | |||
3ab0f179d8 | |||
25ef549417 | |||
084d39096c | |||
eca84b4e75 | |||
aefa866ae7 | |||
557ef4cd33 | |||
eea6302dda | |||
c0fafd3f7c | |||
f7290419d2 | |||
0fd2066c4a | |||
cb54311a7b | |||
ca71632755 | |||
ebf335eabd | |||
f383f6d14d | |||
5663a287f9 | |||
a7028fa64c | |||
0750509a85 | |||
4d9ebe729e | |||
bb8cc33d53 | |||
e933cacdcf | |||
3719498c2f | |||
c7470302bd | |||
5e9e83cb74 | |||
4cef58580e | |||
0ba09cbf8b | |||
28a2cb5d75 | |||
4961a192ea | |||
8ab47f3835 | |||
8112fb81a2 | |||
2c3c862c4a | |||
93f5d83825 | |||
ea60ac3d7b | |||
0748695f23 | |||
a201692c0c | |||
fd6c1d1442 | |||
ed57ce6e91 | |||
33453b193f | |||
b0972f1a0a | |||
7437403756 | |||
4d2f6f57f4 | |||
24d990592d | |||
5b7b7ff689 | |||
6fccacd085 | |||
51fa61dbc6 | |||
4867a5f858 | |||
687b6a5c6d | |||
e6ed1772f7 | |||
1f0a14fee4 | |||
eb70828ae0 | |||
220a03cc46 | |||
39b1e76bb5 | |||
83fc634d25 | |||
35b434bc3d | |||
749ee5457f | |||
d539073f29 | |||
66e1bb0f28 | |||
577f91b796 | |||
7ed37c30e1 | |||
c2f63ccc72 | |||
970a41c895 | |||
3fd29b3905 | |||
7f7fef3f89 | |||
90ee8023e6 | |||
c486d558ad | |||
85569af770 | |||
f97bb08c5c | |||
6f6e3f7e7b | |||
26b2d153fd | |||
2577f2dcac | |||
e4b69a406f |
15
.env.example
15
.env.example
@ -8,6 +8,12 @@ DB_NAME=
|
||||
MIGRATIONS_RUN=true
|
||||
SWAGGER_API_DOCS_PATH="/api-docs"
|
||||
|
||||
JWT_ACCESS_TOKEN_SECRET=your_access_token_secret
|
||||
JWT_ACCESS_TOKEN_EXPIRY=1d
|
||||
JWT_REFRESH_TOKEN_SECRET=your_refresh_token_secret
|
||||
JWT_REFRESH_TOKEN_EXPIRY=1d
|
||||
USE_MOCK=true
|
||||
|
||||
|
||||
OCI_TENANCY_ID=
|
||||
OCI_USER_ID=
|
||||
@ -23,3 +29,12 @@ MAIL_USER=aahalhmad@gmail.com
|
||||
MAIL_PASSWORD=
|
||||
MAIL_PORT=587
|
||||
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
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -53,3 +53,5 @@ pids
|
||||
# Diagnostic reports (https://nodejs.org/api/report.html)
|
||||
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
|
||||
|
||||
|
||||
zod-certs
|
||||
|
@ -10,6 +10,8 @@
|
||||
"include": "config",
|
||||
"exclude": "**/*.md"
|
||||
},
|
||||
{ "include": "common/modules/**/templates/**/*", "watchAssets": true },
|
||||
{ "include": "common/modules/neoleap/zod-certs" },
|
||||
"i18n",
|
||||
"files"
|
||||
]
|
||||
|
7756
package-lock.json
generated
7756
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
35
package.json
35
package.json
@ -23,60 +23,87 @@
|
||||
"migration:generate": "npm run typeorm:cli-d migration:generate",
|
||||
"migration:create": "npm run typeorm:cli migration:create",
|
||||
"migration:up": "npm run typeorm:cli-d migration:run",
|
||||
"migration:down": "npm run typeorm:cli-d migration:revert"
|
||||
"migration:down": "npm run typeorm:cli-d migration:revert",
|
||||
"seed": "TS_NODE_PROJECT=tsconfig.json ts-node -r tsconfig-paths/register src/scripts/seed.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@abdalhamid/hello": "^2.0.0",
|
||||
"@hamid/hello": "file:../libraries/test-package",
|
||||
"@keyv/redis": "^4.0.2",
|
||||
"@nestjs-modules/mailer": "^2.0.2",
|
||||
"@nestjs/axios": "^3.1.2",
|
||||
"@nestjs/common": "^10.0.0",
|
||||
"@nestjs/config": "^3.3.0",
|
||||
"@nestjs/core": "^10.0.0",
|
||||
"@nestjs/event-emitter": "^2.1.1",
|
||||
"@nestjs/jwt": "^10.2.0",
|
||||
"@nestjs/microservices": "^10.4.7",
|
||||
"@nestjs/passport": "^10.0.3",
|
||||
"@nestjs/platform-express": "^10.4.8",
|
||||
"@nestjs/schedule": "^4.1.2",
|
||||
"@nestjs/swagger": "^8.0.5",
|
||||
"@nestjs/terminus": "^10.2.3",
|
||||
"@nestjs/throttler": "^6.2.1",
|
||||
"@nestjs/typeorm": "^10.0.2",
|
||||
"amqp-connection-manager": "^4.1.14",
|
||||
"amqplib": "^0.10.4",
|
||||
"bcrypt": "^5.1.1",
|
||||
"cacheable": "^1.8.5",
|
||||
"class-transformer": "^0.5.1",
|
||||
"class-validator": "^0.14.1",
|
||||
"decimal.js": "^10.6.0",
|
||||
"firebase-admin": "^13.0.2",
|
||||
"google-libphonenumber": "^3.2.39",
|
||||
"handlebars": "^4.7.8",
|
||||
"ioredis": "^5.4.1",
|
||||
"handlebars-layouts": "^3.1.4",
|
||||
"jwk-to-pem": "^2.0.7",
|
||||
"lodash": "^4.17.21",
|
||||
"moment": "^2.30.1",
|
||||
"nestjs-i18n": "^10.4.9",
|
||||
"nestjs-pino": "^4.1.0",
|
||||
"nestjs-twilio": "^4.4.0",
|
||||
"nodemailer": "^6.9.16",
|
||||
"oci-common": "^2.99.0",
|
||||
"oci-sdk": "^2.99.0",
|
||||
"passport": "^0.7.0",
|
||||
"passport-jwt": "^4.0.1",
|
||||
"pg": "^8.13.1",
|
||||
"pino-http": "^10.3.0",
|
||||
"pino-pretty": "^13.0.0",
|
||||
"reflect-metadata": "^0.2.0",
|
||||
"qrcode": "^1.5.4",
|
||||
"reflect-metadata": "^0.2.2",
|
||||
"rxjs": "^7.8.1",
|
||||
"typeorm": "^0.3.20"
|
||||
"typeorm": "^0.3.20",
|
||||
"typeorm-transactional": "^0.5.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@golevelup/ts-jest": "^0.6.0",
|
||||
"@nestjs/cli": "^10.0.0",
|
||||
"@nestjs/schematics": "^10.0.0",
|
||||
"@nestjs/testing": "^10.0.0",
|
||||
"@types/bcrypt": "^5.0.2",
|
||||
"@types/express": "^5.0.0",
|
||||
"@types/google-libphonenumber": "^7.4.30",
|
||||
"@types/jest": "^29.5.2",
|
||||
"@types/jwk-to-pem": "^2.0.3",
|
||||
"@types/lodash": "^4.17.13",
|
||||
"@types/multer": "^1.4.12",
|
||||
"@types/node": "^20.3.1",
|
||||
"@types/nodemailer": "^6.4.16",
|
||||
"@types/passport-jwt": "^4.0.1",
|
||||
"@types/qrcode": "^1.5.5",
|
||||
"@types/supertest": "^6.0.0",
|
||||
"@types/uuid": "^10.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^5.59.2",
|
||||
"@typescript-eslint/parser": "^5.59.2",
|
||||
"eslint": "^8.39.0",
|
||||
"eslint-config-prettier": "^8.8.0",
|
||||
"eslint-plugin-prettier": "^4.0.0",
|
||||
"eslint-plugin-security": "^1.7.1",
|
||||
"i": "^0.3.7",
|
||||
"jest": "^29.5.0",
|
||||
"lint-staged": "^13.2.2",
|
||||
"npm": "^10.9.2",
|
||||
"prettier": "^2.8.8",
|
||||
"source-map-support": "^0.5.21",
|
||||
"supertest": "^7.0.0",
|
||||
|
@ -1,16 +1,33 @@
|
||||
import { MiddlewareConsumer, Module } from '@nestjs/common';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { APP_FILTER, APP_PIPE } from '@nestjs/core';
|
||||
import { EventEmitterModule } from '@nestjs/event-emitter';
|
||||
import { ScheduleModule } from '@nestjs/schedule';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { I18nMiddleware, I18nModule } from 'nestjs-i18n';
|
||||
import { LoggerModule } from 'nestjs-pino';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { addTransactionalDataSource } from 'typeorm-transactional';
|
||||
import { AuthModule } from './auth/auth.module';
|
||||
import { CacheModule } from './common/modules/cache/cache.module';
|
||||
import { LookupModule } from './common/modules/lookup/lookup.module';
|
||||
import { NeoLeapModule } from './common/modules/neoleap/neoleap.module';
|
||||
import { NotificationModule } from './common/modules/notification/notification.module';
|
||||
import { OtpModule } from './common/modules/otp/otp.module';
|
||||
import { AllExceptionsFilter, buildI18nValidationExceptionFilter } from './core/filters';
|
||||
import { buildConfigOptions, buildLoggerOptions, buildTypeormOptions } from './core/module-options';
|
||||
import { buildI18nOptions } from './core/module-options/i18n-options';
|
||||
import { buildValidationPipe } from './core/pipes';
|
||||
import { CronModule } from './cron/cron.module';
|
||||
import { CustomerModule } from './customer/customer.module';
|
||||
import { migrations } from './db';
|
||||
import { DocumentModule } from './document/document.module';
|
||||
import { GuardianModule } from './guardian/guardian.module';
|
||||
import { HealthModule } from './health/health.module';
|
||||
import { JuniorModule } from './junior/junior.module';
|
||||
import { UserModule } from './user/user.module';
|
||||
import { CardModule } from './card/card.module';
|
||||
|
||||
@Module({
|
||||
controllers: [],
|
||||
imports: [
|
||||
@ -18,17 +35,43 @@ import { HealthModule } from './health/health.module';
|
||||
TypeOrmModule.forRootAsync({
|
||||
imports: [],
|
||||
inject: [ConfigService],
|
||||
useFactory: (config: ConfigService) => buildTypeormOptions(config, migrations),
|
||||
useFactory: (config: ConfigService) => {
|
||||
return buildTypeormOptions(config, migrations);
|
||||
},
|
||||
async dataSourceFactory(options) {
|
||||
if (!options) {
|
||||
throw new Error('Invalid options passed');
|
||||
}
|
||||
|
||||
return addTransactionalDataSource(new DataSource(options));
|
||||
},
|
||||
}),
|
||||
LoggerModule.forRootAsync({
|
||||
useFactory: (config: ConfigService) => buildLoggerOptions(config),
|
||||
inject: [ConfigService],
|
||||
}),
|
||||
I18nModule.forRoot(buildI18nOptions()),
|
||||
CacheModule,
|
||||
EventEmitterModule.forRoot(),
|
||||
ScheduleModule.forRoot(),
|
||||
// App modules
|
||||
AuthModule,
|
||||
UserModule,
|
||||
|
||||
CustomerModule,
|
||||
JuniorModule,
|
||||
GuardianModule,
|
||||
|
||||
NotificationModule,
|
||||
OtpModule,
|
||||
DocumentModule,
|
||||
LookupModule,
|
||||
|
||||
HealthModule,
|
||||
|
||||
// Application Modules
|
||||
DocumentModule,
|
||||
CronModule,
|
||||
NeoLeapModule,
|
||||
CardModule,
|
||||
],
|
||||
providers: [
|
||||
// Global Pipes
|
||||
|
16
src/auth/auth.module.ts
Normal file
16
src/auth/auth.module.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { HttpModule } from '@nestjs/axios';
|
||||
import { Module } from '@nestjs/common';
|
||||
import { JwtModule } from '@nestjs/jwt';
|
||||
import { JuniorModule } from '~/junior/junior.module';
|
||||
import { UserModule } from '~/user/user.module';
|
||||
import { AuthController } from './controllers';
|
||||
import { AuthService } from './services';
|
||||
import { AccessTokenStrategy } from './strategies';
|
||||
|
||||
@Module({
|
||||
imports: [JwtModule.register({}), UserModule, JuniorModule, HttpModule],
|
||||
providers: [AuthService, AccessTokenStrategy],
|
||||
controllers: [AuthController],
|
||||
exports: [],
|
||||
})
|
||||
export class AuthModule {}
|
1
src/auth/constants/country-code-regex.constant..ts
Normal file
1
src/auth/constants/country-code-regex.constant..ts
Normal file
@ -0,0 +1 @@
|
||||
export const COUNTRY_CODE_REGEX = /^\+\d{1,3}$/;
|
3
src/auth/constants/index.ts
Normal file
3
src/auth/constants/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export * from './country-code-regex.constant.';
|
||||
export * from './passcode-regext.constant';
|
||||
export * from './password-regex.constant';
|
1
src/auth/constants/passcode-regext.constant.ts
Normal file
1
src/auth/constants/passcode-regext.constant.ts
Normal file
@ -0,0 +1 @@
|
||||
export const PASSCODE_REGEX = /^\d{6}$/;
|
1
src/auth/constants/password-regex.constant.ts
Normal file
1
src/auth/constants/password-regex.constant.ts
Normal file
@ -0,0 +1 @@
|
||||
export const PASSWORD_REGEX = /^(?=.*[A-Z])(?=.*[a-z])(?=.*\d)(?=.*[@$!%*?&#\-_])[A-Za-z\d@$!%*?&#\-_]{8,}$/;
|
89
src/auth/controllers/auth.controller.ts
Normal file
89
src/auth/controllers/auth.controller.ts
Normal file
@ -0,0 +1,89 @@
|
||||
import { Body, Controller, HttpCode, HttpStatus, Post, Req, UseGuards } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { Request } from 'express';
|
||||
import { AuthenticatedUser, Public } from '~/common/decorators';
|
||||
import { AccessTokenGuard } from '~/common/guards';
|
||||
import { ApiDataResponse, ApiLangRequestHeader } from '~/core/decorators';
|
||||
import { ResponseFactory } from '~/core/utils';
|
||||
import {
|
||||
ChangePasswordRequestDto,
|
||||
CreateUnverifiedUserRequestDto,
|
||||
ForgetPasswordRequestDto,
|
||||
LoginRequestDto,
|
||||
RefreshTokenRequestDto,
|
||||
SendForgetPasswordOtpRequestDto,
|
||||
VerifyForgetPasswordOtpRequestDto,
|
||||
VerifyUserRequestDto,
|
||||
} from '../dtos/request';
|
||||
import { SendForgetPasswordOtpResponseDto, SendRegisterOtpResponseDto } from '../dtos/response';
|
||||
import { LoginResponseDto } from '../dtos/response/login.response.dto';
|
||||
import { VerifyForgetPasswordOtpResponseDto } from '../dtos/response/verify-forget-password-otp.response.dto';
|
||||
import { IJwtPayload } from '../interfaces';
|
||||
import { AuthService } from '../services';
|
||||
|
||||
@Controller('auth')
|
||||
@ApiTags('Auth')
|
||||
@ApiBearerAuth()
|
||||
@ApiLangRequestHeader()
|
||||
export class AuthController {
|
||||
constructor(private readonly authService: AuthService) {}
|
||||
@Post('register/otp')
|
||||
async register(@Body() createUnverifiedUserDto: CreateUnverifiedUserRequestDto) {
|
||||
const phoneNumber = await this.authService.sendRegisterOtp(createUnverifiedUserDto);
|
||||
return ResponseFactory.data(new SendRegisterOtpResponseDto(phoneNumber));
|
||||
}
|
||||
|
||||
@Post('register/verify')
|
||||
async verifyUser(@Body() verifyUserDto: VerifyUserRequestDto) {
|
||||
const [res, user] = await this.authService.verifyUser(verifyUserDto);
|
||||
return ResponseFactory.data(new LoginResponseDto(res, user));
|
||||
}
|
||||
|
||||
@Post('login')
|
||||
async login(@Body() verifyUserDto: LoginRequestDto) {
|
||||
const [res, user] = await this.authService.loginWithPassword(verifyUserDto);
|
||||
return ResponseFactory.data(new LoginResponseDto(res, user));
|
||||
}
|
||||
|
||||
@Post('forget-password/otp')
|
||||
async forgetPassword(@Body() sendForgetPasswordOtpDto: SendForgetPasswordOtpRequestDto) {
|
||||
const maskedNumber = await this.authService.sendForgetPasswordOtp(sendForgetPasswordOtpDto);
|
||||
return ResponseFactory.data(new SendForgetPasswordOtpResponseDto(maskedNumber));
|
||||
}
|
||||
|
||||
@Post('forget-password/verify')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
@ApiDataResponse(VerifyForgetPasswordOtpResponseDto)
|
||||
async verifyForgetPasswordOtp(@Body() forgetPasswordDto: VerifyForgetPasswordOtpRequestDto) {
|
||||
const { token, user } = await this.authService.verifyForgetPasswordOtp(forgetPasswordDto);
|
||||
|
||||
return ResponseFactory.data(new VerifyForgetPasswordOtpResponseDto(token, user));
|
||||
}
|
||||
|
||||
@Post('forget-password/reset')
|
||||
@HttpCode(HttpStatus.NO_CONTENT)
|
||||
resetPassword(@Body() forgetPasswordDto: ForgetPasswordRequestDto) {
|
||||
return this.authService.resetPassword(forgetPasswordDto);
|
||||
}
|
||||
|
||||
@Post('change-password')
|
||||
@HttpCode(HttpStatus.NO_CONTENT)
|
||||
@UseGuards(AccessTokenGuard)
|
||||
async changePassword(@AuthenticatedUser() { sub }: IJwtPayload, @Body() forgetPasswordDto: ChangePasswordRequestDto) {
|
||||
return this.authService.changePassword(sub, forgetPasswordDto);
|
||||
}
|
||||
|
||||
@Post('refresh-token')
|
||||
@Public()
|
||||
async refreshToken(@Body() { refreshToken }: RefreshTokenRequestDto) {
|
||||
const [res, user] = await this.authService.refreshToken(refreshToken);
|
||||
return ResponseFactory.data(new LoginResponseDto(res, user));
|
||||
}
|
||||
|
||||
@Post('logout')
|
||||
@HttpCode(HttpStatus.NO_CONTENT)
|
||||
@UseGuards(AccessTokenGuard)
|
||||
async logout(@Req() request: Request) {
|
||||
await this.authService.logout(request);
|
||||
}
|
||||
}
|
1
src/auth/controllers/index.ts
Normal file
1
src/auth/controllers/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './auth.controller';
|
23
src/auth/dtos/request/change-password.request.dto.ts
Normal file
23
src/auth/dtos/request/change-password.request.dto.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsNotEmpty, IsString, Matches } from 'class-validator';
|
||||
import { i18nValidationMessage as i18n } from 'nestjs-i18n';
|
||||
import { PASSWORD_REGEX } from '~/auth/constants';
|
||||
|
||||
export class ChangePasswordRequestDto {
|
||||
@ApiProperty({ example: 'currentPassword@123' })
|
||||
@IsString({ message: i18n('validation.IsString', { path: 'general', property: 'auth.currentPassword' }) })
|
||||
@IsNotEmpty({ message: i18n('validation.IsNotEmpty', { path: 'general', property: 'auth.currentPassword' }) })
|
||||
currentPassword!: string;
|
||||
|
||||
@ApiProperty({ example: 'Abcd1234@' })
|
||||
@Matches(PASSWORD_REGEX, {
|
||||
message: i18n('validation.Matches', { path: 'general', property: 'auth.newPassword' }),
|
||||
})
|
||||
newPassword!: string;
|
||||
|
||||
@ApiProperty({ example: 'Abcd1234@' })
|
||||
@Matches(PASSWORD_REGEX, {
|
||||
message: i18n('validation.Matches', { path: 'general', property: 'auth.confirmNewPassword' }),
|
||||
})
|
||||
confirmNewPassword!: string;
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
import { OmitType } from '@nestjs/swagger';
|
||||
import { VerifyUserRequestDto } from './verify-user.request.dto';
|
||||
|
||||
export class CreateUnverifiedUserRequestDto extends OmitType(VerifyUserRequestDto, ['otp']) {}
|
34
src/auth/dtos/request/forget-password.request.dto.ts
Normal file
34
src/auth/dtos/request/forget-password.request.dto.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsString, Matches } from 'class-validator';
|
||||
import { i18nValidationMessage as i18n } from 'nestjs-i18n';
|
||||
import { COUNTRY_CODE_REGEX, PASSWORD_REGEX } from '~/auth/constants';
|
||||
import { IsValidPhoneNumber } from '~/core/decorators/validations';
|
||||
export class ForgetPasswordRequestDto {
|
||||
@ApiProperty({ example: '+962' })
|
||||
@Matches(COUNTRY_CODE_REGEX, {
|
||||
message: i18n('validation.Matches', { path: 'general', property: 'auth.countryCode' }),
|
||||
})
|
||||
countryCode!: string;
|
||||
|
||||
@ApiProperty({ example: '787259134' })
|
||||
@IsValidPhoneNumber({
|
||||
message: i18n('validation.IsValidPhoneNumber', { path: 'general', property: 'auth.phoneNumber' }),
|
||||
})
|
||||
phoneNumber!: string;
|
||||
|
||||
@ApiProperty({ example: 'Abcd1234@' })
|
||||
@Matches(PASSWORD_REGEX, {
|
||||
message: i18n('validation.Matches', { path: 'general', property: 'auth.password' }),
|
||||
})
|
||||
password!: string;
|
||||
|
||||
@ApiProperty({ example: 'Abcd1234@' })
|
||||
@Matches(PASSWORD_REGEX, {
|
||||
message: i18n('validation.Matches', { path: 'general', property: 'auth.confirmPassword' }),
|
||||
})
|
||||
confirmPassword!: string;
|
||||
|
||||
@ApiProperty({ example: 'reset-token-32423123' })
|
||||
@IsString({ message: i18n('validation.IsString', { path: 'general', property: 'auth.resetPasswordToken' }) })
|
||||
resetPasswordToken!: string;
|
||||
}
|
11
src/auth/dtos/request/index.ts
Normal file
11
src/auth/dtos/request/index.ts
Normal file
@ -0,0 +1,11 @@
|
||||
export * from './change-password.request.dto';
|
||||
export * from './create-unverified-user.request.dto';
|
||||
export * from './forget-password.request.dto';
|
||||
export * from './login.request.dto';
|
||||
export * from './refresh-token.request.dto';
|
||||
export * from './send-forget-password-otp.request.dto';
|
||||
export * from './set-junior-password.request.dto';
|
||||
export * from './set-passcode.request.dto';
|
||||
export * from './verify-forget-password-otp.request.dto';
|
||||
export * from './verify-otp.request.dto';
|
||||
export * from './verify-user.request.dto';
|
24
src/auth/dtos/request/login.request.dto.ts
Normal file
24
src/auth/dtos/request/login.request.dto.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsEmail, IsEnum, IsNotEmpty, IsOptional, IsString, Matches, ValidateIf } from 'class-validator';
|
||||
import { i18nValidationMessage as i18n } from 'nestjs-i18n';
|
||||
import { COUNTRY_CODE_REGEX } from '~/auth/constants';
|
||||
import { GrantType } from '~/auth/enums';
|
||||
import { IsValidPhoneNumber } from '~/core/decorators/validations';
|
||||
export class LoginRequestDto {
|
||||
@ApiProperty({ example: '+962' })
|
||||
@Matches(COUNTRY_CODE_REGEX, {
|
||||
message: i18n('validation.Matches', { path: 'general', property: 'auth.countryCode' }),
|
||||
})
|
||||
countryCode!: string;
|
||||
|
||||
@ApiProperty({ example: '787259134' })
|
||||
@IsValidPhoneNumber({
|
||||
message: i18n('validation.IsValidPhoneNumber', { path: 'general', property: 'auth.phoneNumber' }),
|
||||
})
|
||||
phoneNumber!: string;
|
||||
|
||||
@ApiProperty({ example: 'Abcd1234@' })
|
||||
@IsString({ message: i18n('validation.IsString', { path: 'general', property: 'auth.password' }) })
|
||||
@ValidateIf((o) => o.grantType === GrantType.PASSWORD)
|
||||
password!: string;
|
||||
}
|
9
src/auth/dtos/request/refresh-token.request.dto.ts
Normal file
9
src/auth/dtos/request/refresh-token.request.dto.ts
Normal file
@ -0,0 +1,9 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
import { i18nValidationMessage as i18n } from 'nestjs-i18n';
|
||||
export class RefreshTokenRequestDto {
|
||||
@ApiProperty()
|
||||
@IsString({ message: i18n('validation.isString', { path: 'general', property: 'auth.refreshToken' }) })
|
||||
@IsNotEmpty({ message: i18n('validation.required', { path: 'general', property: 'auth.refreshToken' }) })
|
||||
refreshToken!: string;
|
||||
}
|
@ -0,0 +1,4 @@
|
||||
import { PickType } from '@nestjs/swagger';
|
||||
import { LoginRequestDto } from './login.request.dto';
|
||||
|
||||
export class SendForgetPasswordOtpRequestDto extends PickType(LoginRequestDto, ['countryCode', 'phoneNumber']) {}
|
10
src/auth/dtos/request/set-junior-password.request.dto.ts
Normal file
10
src/auth/dtos/request/set-junior-password.request.dto.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsNotEmpty, IsString } from 'class-validator';
|
||||
import { i18nValidationMessage as i18n } from 'nestjs-i18n';
|
||||
import { SetPasscodeRequestDto } from './set-passcode.request.dto';
|
||||
export class setJuniorPasswordRequestDto extends SetPasscodeRequestDto {
|
||||
@ApiProperty()
|
||||
@IsString({ message: i18n('validation.IsNumberString', { path: 'general', property: 'auth.qrToken' }) })
|
||||
@IsNotEmpty({ message: i18n('validation.IsNotEmpty', { path: 'general', property: 'auth.qrToken' }) })
|
||||
qrToken!: string;
|
||||
}
|
15
src/auth/dtos/request/set-passcode.request.dto.ts
Normal file
15
src/auth/dtos/request/set-passcode.request.dto.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsNumberString, MaxLength, MinLength } from 'class-validator';
|
||||
import { i18nValidationMessage as i18n } from 'nestjs-i18n';
|
||||
const PASSCODE_LENGTH = 6;
|
||||
|
||||
export class SetPasscodeRequestDto {
|
||||
@ApiProperty({ example: '123456' })
|
||||
@IsNumberString(
|
||||
{ no_symbols: true },
|
||||
{ message: i18n('validation.IsNumberString', { path: 'general', property: 'auth.passcode' }) },
|
||||
)
|
||||
@MinLength(PASSCODE_LENGTH, { message: i18n('validation.MinLength', { path: 'general', property: 'auth.passcode' }) })
|
||||
@MaxLength(PASSCODE_LENGTH, { message: i18n('validation.MaxLength', { path: 'general', property: 'auth.passcode' }) })
|
||||
passcode!: string;
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
import { ApiProperty, PickType } from '@nestjs/swagger';
|
||||
import { IsNumberString, MaxLength, MinLength } from 'class-validator';
|
||||
import { i18nValidationMessage as i18n } from 'nestjs-i18n';
|
||||
import { DEFAULT_OTP_LENGTH } from '~/common/modules/otp/constants';
|
||||
import { ForgetPasswordRequestDto } from './forget-password.request.dto';
|
||||
|
||||
export class VerifyForgetPasswordOtpRequestDto extends PickType(ForgetPasswordRequestDto, [
|
||||
'countryCode',
|
||||
'phoneNumber',
|
||||
]) {
|
||||
@ApiProperty({ example: '111111' })
|
||||
@IsNumberString(
|
||||
{ no_symbols: true },
|
||||
{ message: i18n('validation.IsNumberString', { path: 'general', property: 'auth.otp' }) },
|
||||
)
|
||||
@MaxLength(DEFAULT_OTP_LENGTH, {
|
||||
message: i18n('validation.MaxLength', { path: 'general', property: 'auth.otp', length: DEFAULT_OTP_LENGTH }),
|
||||
})
|
||||
@MinLength(DEFAULT_OTP_LENGTH, {
|
||||
message: i18n('validation.MinLength', { path: 'general', property: 'auth.otp', length: DEFAULT_OTP_LENGTH }),
|
||||
})
|
||||
otp!: string;
|
||||
}
|
19
src/auth/dtos/request/verify-otp.request.dto.ts
Normal file
19
src/auth/dtos/request/verify-otp.request.dto.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { IsNumberString, MaxLength, MinLength } from 'class-validator';
|
||||
import { i18nValidationMessage as i18n } from 'nestjs-i18n';
|
||||
import { DEFAULT_OTP_LENGTH } from '~/common/modules/otp/constants';
|
||||
|
||||
export class VerifyOtpRequestDto {
|
||||
@ApiProperty({ example: '111111' })
|
||||
@IsNumberString(
|
||||
{ no_symbols: true },
|
||||
{ message: i18n('validation.IsNumberString', { path: 'general', property: 'auth.otp' }) },
|
||||
)
|
||||
@MaxLength(DEFAULT_OTP_LENGTH, {
|
||||
message: i18n('validation.MaxLength', { path: 'general', property: 'auth.otp', length: DEFAULT_OTP_LENGTH }),
|
||||
})
|
||||
@MinLength(DEFAULT_OTP_LENGTH, {
|
||||
message: i18n('validation.MinLength', { path: 'general', property: 'auth.otp', length: DEFAULT_OTP_LENGTH }),
|
||||
})
|
||||
otp!: string;
|
||||
}
|
83
src/auth/dtos/request/verify-user.request.dto.ts
Normal file
83
src/auth/dtos/request/verify-user.request.dto.ts
Normal file
@ -0,0 +1,83 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import {
|
||||
IsDateString,
|
||||
IsEmail,
|
||||
IsEnum,
|
||||
IsNotEmpty,
|
||||
IsNumberString,
|
||||
IsOptional,
|
||||
IsString,
|
||||
Matches,
|
||||
MaxLength,
|
||||
MinLength,
|
||||
} from 'class-validator';
|
||||
import { i18nValidationMessage as i18n } from 'nestjs-i18n';
|
||||
import { COUNTRY_CODE_REGEX, PASSWORD_REGEX } from '~/auth/constants';
|
||||
import { CountryIso } from '~/common/enums';
|
||||
import { DEFAULT_OTP_LENGTH } from '~/common/modules/otp/constants';
|
||||
import { IsAbove18, IsValidPhoneNumber } from '~/core/decorators/validations';
|
||||
|
||||
export class VerifyUserRequestDto {
|
||||
@ApiProperty({ example: '+962' })
|
||||
@Matches(COUNTRY_CODE_REGEX, {
|
||||
message: i18n('validation.Matches', { path: 'general', property: 'auth.countryCode' }),
|
||||
})
|
||||
countryCode!: string;
|
||||
|
||||
@ApiProperty({ example: '787259134' })
|
||||
@IsValidPhoneNumber({
|
||||
message: i18n('validation.IsValidPhoneNumber', { path: 'general', property: 'auth.phoneNumber' }),
|
||||
})
|
||||
phoneNumber!: string;
|
||||
@ApiProperty({ example: 'John' })
|
||||
@IsString({ message: i18n('validation.IsString', { path: 'general', property: 'customer.firstName' }) })
|
||||
@IsNotEmpty({ message: i18n('validation.IsNotEmpty', { path: 'general', property: 'customer.firstName' }) })
|
||||
firstName!: string;
|
||||
|
||||
@ApiProperty({ example: 'Doe' })
|
||||
@IsString({ message: i18n('validation.IsString', { path: 'general', property: 'customer.lastName' }) })
|
||||
@IsNotEmpty({ message: i18n('validation.IsNotEmpty', { path: 'general', property: 'customer.lastName' }) })
|
||||
lastName!: string;
|
||||
|
||||
@ApiProperty({ example: '2001-01-01' })
|
||||
@IsDateString({}, { message: i18n('validation.IsDateString', { path: 'general', property: 'customer.dateOfBirth' }) })
|
||||
@IsAbove18({ message: i18n('validation.IsAbove18', { path: 'general', property: 'customer.dateOfBirth' }) })
|
||||
dateOfBirth!: Date;
|
||||
|
||||
@ApiProperty({ example: 'JO' })
|
||||
@IsEnum(CountryIso, {
|
||||
message: i18n('validation.IsEnum', { path: 'general', property: 'customer.countryOfResidence' }),
|
||||
})
|
||||
@IsOptional()
|
||||
countryOfResidence: CountryIso = CountryIso.SAUDI_ARABIA;
|
||||
|
||||
@ApiProperty({ example: 'test@test.com' })
|
||||
@IsEmail({}, { message: i18n('validation.IsEmail', { path: 'general', property: 'auth.email' }) })
|
||||
@IsOptional()
|
||||
email!: string;
|
||||
|
||||
@ApiProperty({ example: 'Abcd1234@' })
|
||||
@Matches(PASSWORD_REGEX, {
|
||||
message: i18n('validation.Matches', { path: 'general', property: 'auth.password' }),
|
||||
})
|
||||
password!: string;
|
||||
|
||||
@ApiProperty({ example: 'Abcd1234@' })
|
||||
@Matches(PASSWORD_REGEX, {
|
||||
message: i18n('validation.Matches', { path: 'general', property: 'auth.confirmPassword' }),
|
||||
})
|
||||
confirmPassword!: string;
|
||||
|
||||
@ApiProperty({ example: '111111' })
|
||||
@IsNumberString(
|
||||
{ no_symbols: true },
|
||||
{ message: i18n('validation.IsNumberString', { path: 'general', property: 'auth.otp' }) },
|
||||
)
|
||||
@MaxLength(DEFAULT_OTP_LENGTH, {
|
||||
message: i18n('validation.MaxLength', { path: 'general', property: 'auth.otp', length: DEFAULT_OTP_LENGTH }),
|
||||
})
|
||||
@MinLength(DEFAULT_OTP_LENGTH, {
|
||||
message: i18n('validation.MinLength', { path: 'general', property: 'auth.otp', length: DEFAULT_OTP_LENGTH }),
|
||||
})
|
||||
otp!: string;
|
||||
}
|
4
src/auth/dtos/response/index.ts
Normal file
4
src/auth/dtos/response/index.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export * from './send-forget-password.response.dto';
|
||||
export * from './send-register-otp.response.dto';
|
||||
export * from './user.response.dto';
|
||||
export * from './verify-user.response.dto';
|
30
src/auth/dtos/response/login.response.dto.ts
Normal file
30
src/auth/dtos/response/login.response.dto.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { ILoginResponse } from '~/auth/interfaces';
|
||||
import { CustomerResponseDto } from '~/customer/dtos/response';
|
||||
import { User } from '~/user/entities';
|
||||
import { UserResponseDto } from './user.response.dto';
|
||||
|
||||
export class LoginResponseDto {
|
||||
@ApiProperty()
|
||||
accessToken!: string;
|
||||
|
||||
@ApiProperty()
|
||||
refreshToken!: string;
|
||||
|
||||
@ApiProperty()
|
||||
expiresAt!: Date;
|
||||
|
||||
@ApiProperty({ example: UserResponseDto })
|
||||
user!: UserResponseDto;
|
||||
|
||||
@ApiProperty({ type: CustomerResponseDto })
|
||||
customer!: CustomerResponseDto | null;
|
||||
|
||||
constructor(IVerifyUserResponse: ILoginResponse, user: User) {
|
||||
this.user = new UserResponseDto(user);
|
||||
this.customer = user.customer ? new CustomerResponseDto(user.customer) : null;
|
||||
this.accessToken = IVerifyUserResponse.accessToken;
|
||||
this.refreshToken = IVerifyUserResponse.refreshToken;
|
||||
this.expiresAt = IVerifyUserResponse.expiresAt;
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
export class SendForgetPasswordOtpResponseDto {
|
||||
maskedNumber!: string;
|
||||
|
||||
constructor(maskedNumber: string) {
|
||||
this.maskedNumber = maskedNumber;
|
||||
}
|
||||
}
|
10
src/auth/dtos/response/send-register-otp.response.dto.ts
Normal file
10
src/auth/dtos/response/send-register-otp.response.dto.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class SendRegisterOtpResponseDto {
|
||||
@ApiProperty()
|
||||
maskedNumber!: string;
|
||||
|
||||
constructor(maskedNumber: string) {
|
||||
this.maskedNumber = maskedNumber;
|
||||
}
|
||||
}
|
10
src/auth/dtos/response/send-register-otp.v2.response.dto.ts
Normal file
10
src/auth/dtos/response/send-register-otp.v2.response.dto.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
|
||||
export class SendRegisterOtpV2ResponseDto {
|
||||
@ApiProperty()
|
||||
maskedNumber!: string;
|
||||
|
||||
constructor(maskedNumber: string) {
|
||||
this.maskedNumber = maskedNumber;
|
||||
}
|
||||
}
|
48
src/auth/dtos/response/user.response.dto.ts
Normal file
48
src/auth/dtos/response/user.response.dto.ts
Normal file
@ -0,0 +1,48 @@
|
||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { DocumentMetaResponseDto } from '~/document/dtos/response';
|
||||
import { User } from '~/user/entities';
|
||||
|
||||
export class UserResponseDto {
|
||||
@ApiProperty()
|
||||
id!: string;
|
||||
|
||||
@ApiProperty()
|
||||
countryCode!: string;
|
||||
|
||||
@ApiProperty()
|
||||
phoneNumber!: string;
|
||||
|
||||
@ApiProperty()
|
||||
email!: string;
|
||||
|
||||
@ApiProperty()
|
||||
firstName!: string;
|
||||
|
||||
@ApiProperty()
|
||||
lastName!: string;
|
||||
|
||||
@ApiProperty()
|
||||
dateOfBirth!: Date;
|
||||
|
||||
@ApiPropertyOptional({ type: DocumentMetaResponseDto, nullable: true })
|
||||
profilePicture!: DocumentMetaResponseDto | null;
|
||||
|
||||
@ApiProperty()
|
||||
isPhoneVerified!: boolean;
|
||||
|
||||
@ApiProperty()
|
||||
isEmailVerified!: boolean;
|
||||
|
||||
constructor(user: User) {
|
||||
this.id = user.id;
|
||||
this.countryCode = user.countryCode;
|
||||
this.phoneNumber = user.phoneNumber;
|
||||
this.dateOfBirth = user.customer?.dateOfBirth;
|
||||
this.email = user.email;
|
||||
this.firstName = user.firstName;
|
||||
this.lastName = user.lastName;
|
||||
this.profilePicture = user.profilePicture ? new DocumentMetaResponseDto(user.profilePicture) : null;
|
||||
this.isEmailVerified = user.isEmailVerified;
|
||||
this.isPhoneVerified = user.isPhoneVerified;
|
||||
}
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { User } from '~/user/entities';
|
||||
|
||||
export class VerifyForgetPasswordOtpResponseDto {
|
||||
@ApiProperty()
|
||||
phoneNumber!: string;
|
||||
|
||||
@ApiProperty()
|
||||
countryCode!: string;
|
||||
|
||||
@ApiProperty()
|
||||
resetPasswordToken!: string;
|
||||
|
||||
constructor(token: string, user: User) {
|
||||
this.phoneNumber = user.phoneNumber;
|
||||
this.countryCode = user.countryCode;
|
||||
this.resetPasswordToken = token;
|
||||
}
|
||||
}
|
24
src/auth/dtos/response/verify-user.response.dto.ts
Normal file
24
src/auth/dtos/response/verify-user.response.dto.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { ILoginResponse } from '~/auth/interfaces';
|
||||
import { User } from '~/user/entities';
|
||||
|
||||
export class VerifyUserResponseDto {
|
||||
@ApiProperty()
|
||||
accessToken!: string;
|
||||
|
||||
@ApiProperty()
|
||||
refreshToken!: string;
|
||||
|
||||
@ApiProperty()
|
||||
expiresAt!: Date;
|
||||
|
||||
@ApiProperty()
|
||||
user!: User;
|
||||
|
||||
constructor(data: ILoginResponse, user: User) {
|
||||
this.accessToken = data.accessToken;
|
||||
this.refreshToken = data.refreshToken;
|
||||
this.expiresAt = data.expiresAt;
|
||||
this.user = user;
|
||||
}
|
||||
}
|
4
src/auth/enums/grant-type.enum.ts
Normal file
4
src/auth/enums/grant-type.enum.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export enum GrantType {
|
||||
PASSWORD = 'PASSWORD',
|
||||
BIOMETRIC = 'BIOMETRIC',
|
||||
}
|
2
src/auth/enums/index.ts
Normal file
2
src/auth/enums/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './grant-type.enum';
|
||||
export * from './roles.enum';
|
6
src/auth/enums/roles.enum.ts
Normal file
6
src/auth/enums/roles.enum.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export enum Roles {
|
||||
JUNIOR = 'JUNIOR',
|
||||
GUARDIAN = 'GUARDIAN',
|
||||
CHECKER = 'CHECKER',
|
||||
SUPER_ADMIN = 'SUPER_ADMIN',
|
||||
}
|
2
src/auth/interfaces/index.ts
Normal file
2
src/auth/interfaces/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './jwt-payload.interface';
|
||||
export * from './login-response.interface';
|
6
src/auth/interfaces/jwt-payload.interface.ts
Normal file
6
src/auth/interfaces/jwt-payload.interface.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { Roles } from '../enums';
|
||||
|
||||
export interface IJwtPayload {
|
||||
sub: string;
|
||||
roles: Roles[];
|
||||
}
|
5
src/auth/interfaces/login-response.interface.ts
Normal file
5
src/auth/interfaces/login-response.interface.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export interface ILoginResponse {
|
||||
accessToken: string;
|
||||
refreshToken: string;
|
||||
expiresAt: Date;
|
||||
}
|
303
src/auth/services/auth.service.ts
Normal file
303
src/auth/services/auth.service.ts
Normal file
@ -0,0 +1,303 @@
|
||||
import { BadRequestException, Injectable, Logger, UnauthorizedException } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { JwtService } from '@nestjs/jwt';
|
||||
import * as bcrypt from 'bcrypt';
|
||||
import { Request } from 'express';
|
||||
import moment from 'moment';
|
||||
import { CacheService } from '~/common/modules/cache/services';
|
||||
import { OtpScope, OtpType } from '~/common/modules/otp/enums';
|
||||
import { OtpService } from '~/common/modules/otp/services';
|
||||
import { UserType } from '~/user/enums';
|
||||
import { DeviceService, UserService, UserTokenService } from '~/user/services';
|
||||
import { User } from '../../user/entities';
|
||||
import {
|
||||
ChangePasswordRequestDto,
|
||||
CreateUnverifiedUserRequestDto,
|
||||
ForgetPasswordRequestDto,
|
||||
LoginRequestDto,
|
||||
SendForgetPasswordOtpRequestDto,
|
||||
setJuniorPasswordRequestDto,
|
||||
VerifyForgetPasswordOtpRequestDto,
|
||||
VerifyUserRequestDto,
|
||||
} from '../dtos/request';
|
||||
import { Roles } from '../enums';
|
||||
import { IJwtPayload, ILoginResponse } from '../interfaces';
|
||||
|
||||
const ONE_THOUSAND = 1000;
|
||||
const SALT_ROUNDS = 10;
|
||||
@Injectable()
|
||||
export class AuthService {
|
||||
private readonly logger = new Logger(AuthService.name);
|
||||
|
||||
constructor(
|
||||
private readonly otpService: OtpService,
|
||||
private readonly jwtService: JwtService,
|
||||
private readonly configService: ConfigService,
|
||||
private readonly userService: UserService,
|
||||
private readonly deviceService: DeviceService,
|
||||
private readonly userTokenService: UserTokenService,
|
||||
private readonly cacheService: CacheService,
|
||||
) {}
|
||||
|
||||
async sendRegisterOtp(body: CreateUnverifiedUserRequestDto) {
|
||||
if (body.email) {
|
||||
const isEmailUsed = await this.userService.findUser({ email: body.email, isEmailVerified: true });
|
||||
if (isEmailUsed) {
|
||||
this.logger.error(`Email ${body.email} is already used`);
|
||||
throw new BadRequestException('USER.EMAIL_ALREADY_TAKEN');
|
||||
}
|
||||
}
|
||||
|
||||
if (body.password !== body.confirmPassword) {
|
||||
this.logger.error('Password and confirm password do not match');
|
||||
throw new BadRequestException('AUTH.PASSWORD_MISMATCH');
|
||||
}
|
||||
|
||||
this.logger.log(`Sending OTP to ${body.countryCode + body.phoneNumber}`);
|
||||
const user = await this.userService.findOrCreateUser(body);
|
||||
return this.otpService.generateAndSendOtp({
|
||||
userId: user.id,
|
||||
recipient: user.fullPhoneNumber,
|
||||
scope: OtpScope.VERIFY_PHONE,
|
||||
otpType: OtpType.SMS,
|
||||
});
|
||||
}
|
||||
|
||||
async verifyUser(verifyUserDto: VerifyUserRequestDto): Promise<[ILoginResponse, User]> {
|
||||
this.logger.log(`Verifying user with phone number ${verifyUserDto.countryCode + verifyUserDto.phoneNumber}`);
|
||||
const user = await this.userService.findUserOrThrow({
|
||||
phoneNumber: verifyUserDto.phoneNumber,
|
||||
countryCode: verifyUserDto.countryCode,
|
||||
});
|
||||
|
||||
if (user.isPhoneVerified) {
|
||||
this.logger.error(`User with phone number ${user.fullPhoneNumber} already verified`);
|
||||
throw new BadRequestException('USER.PHONE_NUMBER_ALREADY_VERIFIED');
|
||||
}
|
||||
|
||||
const isOtpValid = await this.otpService.verifyOtp({
|
||||
userId: user.id,
|
||||
scope: OtpScope.VERIFY_PHONE,
|
||||
otpType: OtpType.SMS,
|
||||
value: verifyUserDto.otp,
|
||||
});
|
||||
|
||||
if (!isOtpValid) {
|
||||
this.logger.error(`Invalid OTP for user with phone number ${user.fullPhoneNumber}`);
|
||||
throw new BadRequestException('OTP.INVALID_OTP');
|
||||
}
|
||||
|
||||
await this.userService.verifyUser(user.id, verifyUserDto);
|
||||
|
||||
await user.reload();
|
||||
|
||||
const tokens = await this.generateAuthToken(user);
|
||||
this.logger.log(`User with phone number ${user.fullPhoneNumber} verified successfully`);
|
||||
return [tokens, user];
|
||||
}
|
||||
|
||||
async sendForgetPasswordOtp({ countryCode, phoneNumber }: SendForgetPasswordOtpRequestDto) {
|
||||
this.logger.log(`Sending forget password OTP to ${countryCode + phoneNumber}`);
|
||||
const user = await this.userService.findUserOrThrow({ countryCode, phoneNumber });
|
||||
|
||||
return this.otpService.generateAndSendOtp({
|
||||
userId: user.id,
|
||||
recipient: user.fullPhoneNumber,
|
||||
scope: OtpScope.FORGET_PASSWORD,
|
||||
otpType: OtpType.SMS,
|
||||
});
|
||||
}
|
||||
|
||||
async verifyForgetPasswordOtp({ countryCode, phoneNumber, otp }: VerifyForgetPasswordOtpRequestDto) {
|
||||
const user = await this.userService.findUserOrThrow({ countryCode, phoneNumber });
|
||||
|
||||
const isOtpValid = await this.otpService.verifyOtp({
|
||||
userId: user.id,
|
||||
scope: OtpScope.FORGET_PASSWORD,
|
||||
otpType: OtpType.SMS,
|
||||
value: otp,
|
||||
});
|
||||
|
||||
if (!isOtpValid) {
|
||||
this.logger.error(`Invalid OTP for user with phone number ${user.fullPhoneNumber}`);
|
||||
throw new BadRequestException('OTP.INVALID_OTP');
|
||||
}
|
||||
|
||||
// generate a token for the user to reset password
|
||||
const token = await this.userTokenService.generateToken(user.id, moment().add(5, 'minutes').toDate());
|
||||
|
||||
return { token, user };
|
||||
}
|
||||
|
||||
async resetPassword({
|
||||
countryCode,
|
||||
phoneNumber,
|
||||
resetPasswordToken,
|
||||
password,
|
||||
confirmPassword,
|
||||
}: ForgetPasswordRequestDto) {
|
||||
this.logger.log(`Verifying forget password OTP for ${countryCode + phoneNumber}`);
|
||||
const user = await this.userService.findUserOrThrow({ countryCode, phoneNumber });
|
||||
await this.userTokenService.validateToken(
|
||||
resetPasswordToken,
|
||||
user.roles.includes(Roles.GUARDIAN) ? UserType.GUARDIAN : UserType.JUNIOR,
|
||||
);
|
||||
|
||||
if (password !== confirmPassword) {
|
||||
this.logger.error('Password and confirm password do not match');
|
||||
throw new BadRequestException('AUTH.PASSWORD_MISMATCH');
|
||||
}
|
||||
|
||||
const isOldPassword = bcrypt.compareSync(password, user.password);
|
||||
|
||||
if (isOldPassword) {
|
||||
this.logger.error(
|
||||
`New password cannot be the same as the current password for user with phone number ${user.fullPhoneNumber}`,
|
||||
);
|
||||
throw new BadRequestException('AUTH.PASSWORD_SAME_AS_CURRENT');
|
||||
}
|
||||
|
||||
const hashedPassword = bcrypt.hashSync(password, user.salt);
|
||||
|
||||
await this.userService.setPassword(user.id, hashedPassword, user.salt);
|
||||
await this.userTokenService.invalidateToken(resetPasswordToken);
|
||||
this.logger.log(`Passcode updated successfully for user with phone number ${user.fullPhoneNumber}`);
|
||||
}
|
||||
|
||||
async changePassword(userId: string, { currentPassword, newPassword, confirmNewPassword }: ChangePasswordRequestDto) {
|
||||
const user = await this.userService.findUserOrThrow({ id: userId });
|
||||
|
||||
if (!user.isPasswordSet) {
|
||||
this.logger.error(`Password not set for user with id ${userId}`);
|
||||
throw new BadRequestException('AUTH.PASSWORD_NOT_SET');
|
||||
}
|
||||
|
||||
if (currentPassword === newPassword) {
|
||||
this.logger.error('New password cannot be the same as current password');
|
||||
throw new BadRequestException('AUTH.PASSWORD_SAME_AS_CURRENT');
|
||||
}
|
||||
|
||||
if (newPassword !== confirmNewPassword) {
|
||||
this.logger.error('New password and confirm new password do not match');
|
||||
throw new BadRequestException('AUTH.PASSWORD_MISMATCH');
|
||||
}
|
||||
|
||||
this.logger.log(`Validating current password for user with id ${userId}`);
|
||||
const isCurrentPasswordValid = bcrypt.compareSync(currentPassword, user.password);
|
||||
|
||||
if (!isCurrentPasswordValid) {
|
||||
this.logger.error(`Invalid current password for user with id ${userId}`);
|
||||
throw new UnauthorizedException('AUTH.INVALID_CURRENT_PASSWORD');
|
||||
}
|
||||
|
||||
const salt = bcrypt.genSaltSync(SALT_ROUNDS);
|
||||
const hashedNewPassword = bcrypt.hashSync(newPassword, salt);
|
||||
await this.userService.setPassword(user.id, hashedNewPassword, salt);
|
||||
this.logger.log(`Password changed successfully for user with id ${userId}`);
|
||||
}
|
||||
|
||||
async setJuniorPasscode(body: setJuniorPasswordRequestDto) {
|
||||
this.logger.log(`Setting passcode for junior with qrToken ${body.qrToken}`);
|
||||
const juniorId = await this.userTokenService.validateToken(body.qrToken, UserType.JUNIOR);
|
||||
const salt = bcrypt.genSaltSync(SALT_ROUNDS);
|
||||
const hashedPasscode = bcrypt.hashSync(body.passcode, salt);
|
||||
await this.userService.setPassword(juniorId!, hashedPasscode, salt);
|
||||
await this.userTokenService.invalidateToken(body.qrToken);
|
||||
this.logger.log(`Passcode set successfully for junior with id ${juniorId}`);
|
||||
}
|
||||
|
||||
async refreshToken(refreshToken: string): Promise<[ILoginResponse, User]> {
|
||||
this.logger.log('Refreshing token');
|
||||
|
||||
const isBlackListed = await this.cacheService.get(refreshToken);
|
||||
|
||||
if (isBlackListed) {
|
||||
this.logger.error('Refresh token is blacklisted');
|
||||
throw new BadRequestException('AUTH.INVALID_REFRESH_TOKEN');
|
||||
}
|
||||
|
||||
try {
|
||||
const isValid = await this.jwtService.verifyAsync<IJwtPayload>(refreshToken, {
|
||||
secret: this.configService.getOrThrow('JWT_REFRESH_TOKEN_SECRET'),
|
||||
});
|
||||
|
||||
this.logger.log(`Refreshing token for user with id ${isValid.sub}`);
|
||||
|
||||
const user = await this.userService.findUserOrThrow({ id: isValid.sub });
|
||||
|
||||
const tokens = await this.generateAuthToken(user);
|
||||
|
||||
this.logger.log(`Blacklisting old tokens for user with id ${isValid.sub}`);
|
||||
|
||||
const refreshTokenExpiry = this.jwtService.decode(refreshToken).exp - Date.now() / ONE_THOUSAND;
|
||||
|
||||
await this.cacheService.set(refreshToken, 'BLACKLISTED', refreshTokenExpiry);
|
||||
|
||||
this.logger.log(`Token refreshed successfully for user with id ${isValid.sub}`);
|
||||
|
||||
return [tokens, user];
|
||||
} catch (error) {
|
||||
this.logger.error('Invalid refresh token');
|
||||
throw new BadRequestException('AUTH.INVALID_REFRESH_TOKEN');
|
||||
}
|
||||
}
|
||||
|
||||
logout(req: Request) {
|
||||
this.logger.log('Logging out');
|
||||
const accessToken = req.headers.authorization?.split(' ')[1] as string;
|
||||
const expiryInTtl = this.jwtService.decode(accessToken).exp - Date.now() / ONE_THOUSAND;
|
||||
return this.cacheService.set(accessToken, 'BLACKLISTED', expiryInTtl);
|
||||
}
|
||||
|
||||
async loginWithPassword(loginDto: LoginRequestDto): Promise<[ILoginResponse, User]> {
|
||||
const user = await this.userService.findUser({
|
||||
countryCode: loginDto.countryCode,
|
||||
phoneNumber: loginDto.phoneNumber,
|
||||
});
|
||||
|
||||
if (!user) {
|
||||
this.logger.error(`User not found with phone number ${loginDto.countryCode + loginDto.phoneNumber}`);
|
||||
throw new UnauthorizedException('AUTH.INVALID_CREDENTIALS');
|
||||
}
|
||||
|
||||
if (!user.password) {
|
||||
this.logger.error(`Password not set for user with phone number ${loginDto.countryCode + loginDto.phoneNumber}`);
|
||||
throw new UnauthorizedException('AUTH.PHONE_NUMBER_NOT_VERIFIED');
|
||||
}
|
||||
|
||||
this.logger.log(`validating password for user with phone ${loginDto.countryCode + loginDto.phoneNumber}`);
|
||||
const isPasswordValid = bcrypt.compareSync(loginDto.password, user.password);
|
||||
|
||||
if (!isPasswordValid) {
|
||||
this.logger.error(`Invalid password for user with phone ${loginDto.countryCode + loginDto.phoneNumber}`);
|
||||
throw new UnauthorizedException('AUTH.INVALID_CREDENTIALS');
|
||||
}
|
||||
|
||||
const tokens = await this.generateAuthToken(user);
|
||||
this.logger.log(`Password validated successfully for user`);
|
||||
return [tokens, user];
|
||||
}
|
||||
|
||||
private async generateAuthToken(user: User) {
|
||||
this.logger.log(`Generating auth token for user with id ${user.id}`);
|
||||
const [accessToken, refreshToken] = await Promise.all([
|
||||
this.jwtService.sign(
|
||||
{ sub: user.id, roles: user.roles },
|
||||
{
|
||||
expiresIn: this.configService.getOrThrow('JWT_ACCESS_TOKEN_EXPIRY'),
|
||||
secret: this.configService.getOrThrow('JWT_ACCESS_TOKEN_SECRET'),
|
||||
},
|
||||
),
|
||||
this.jwtService.sign(
|
||||
{ sub: user.id, roles: user.roles },
|
||||
{
|
||||
expiresIn: this.configService.getOrThrow('JWT_REFRESH_TOKEN_EXPIRY'),
|
||||
secret: this.configService.getOrThrow('JWT_REFRESH_TOKEN_SECRET'),
|
||||
},
|
||||
),
|
||||
]);
|
||||
|
||||
this.logger.log(`Auth token generated successfully for user with id ${user.id}`);
|
||||
return { accessToken, refreshToken, expiresAt: new Date(this.jwtService.decode(accessToken).exp * ONE_THOUSAND) };
|
||||
}
|
||||
}
|
1
src/auth/services/index.ts
Normal file
1
src/auth/services/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './auth.service';
|
27
src/auth/strategies/access-token.strategy.ts
Normal file
27
src/auth/strategies/access-token.strategy.ts
Normal file
@ -0,0 +1,27 @@
|
||||
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { PassportStrategy } from '@nestjs/passport';
|
||||
import { ExtractJwt, Strategy } from 'passport-jwt';
|
||||
import { UserService } from '~/user/services';
|
||||
import { IJwtPayload } from '../interfaces';
|
||||
|
||||
@Injectable()
|
||||
export class AccessTokenStrategy extends PassportStrategy(Strategy, 'access-token') {
|
||||
constructor(configService: ConfigService, private userService: UserService) {
|
||||
super({
|
||||
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
|
||||
ignoreExpiration: false,
|
||||
secretOrKey: configService.get<string>('JWT_ACCESS_TOKEN_SECRET'),
|
||||
});
|
||||
}
|
||||
|
||||
async validate(payload: IJwtPayload) {
|
||||
const user = await this.userService.findUser({ id: payload.sub });
|
||||
|
||||
if (!user) {
|
||||
throw new UnauthorizedException();
|
||||
}
|
||||
|
||||
return payload;
|
||||
}
|
||||
}
|
1
src/auth/strategies/index.ts
Normal file
1
src/auth/strategies/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './access-token.strategy';
|
26
src/auth/utils/crypt.ts
Normal file
26
src/auth/utils/crypt.ts
Normal file
@ -0,0 +1,26 @@
|
||||
import * as crypto from 'crypto';
|
||||
|
||||
export function verifySignature(
|
||||
publicKeyBase64: string,
|
||||
signatureBase64: string,
|
||||
message: string,
|
||||
algorithm: 'SHA1' | 'SHA384',
|
||||
) {
|
||||
const signatureBuffer = Buffer.from(signatureBase64, 'base64');
|
||||
|
||||
const publicKeyPEM = '-----BEGIN PUBLIC KEY-----\n' + publicKeyBase64 + '\n-----END PUBLIC KEY-----';
|
||||
const verifier = crypto.createVerify(algorithm);
|
||||
verifier.update(message, 'utf8');
|
||||
return verifier.verify(
|
||||
{
|
||||
key: publicKeyPEM,
|
||||
padding: crypto.constants.RSA_PKCS1_PADDING,
|
||||
},
|
||||
signatureBuffer,
|
||||
);
|
||||
}
|
||||
|
||||
export function removePadding(originalSignature: string) {
|
||||
const buffer = Buffer.from(originalSignature, 'base64');
|
||||
return buffer.toString('base64');
|
||||
}
|
1
src/auth/utils/index.ts
Normal file
1
src/auth/utils/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './crypt';
|
25
src/card/card.module.ts
Normal file
25
src/card/card.module.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { Card } from './entities';
|
||||
import { Account } from './entities/account.entity';
|
||||
import { Transaction } from './entities/transaction.entity';
|
||||
import { CardRepository } from './repositories';
|
||||
import { AccountRepository } from './repositories/account.repository';
|
||||
import { TransactionRepository } from './repositories/transaction.repository';
|
||||
import { CardService } from './services';
|
||||
import { AccountService } from './services/account.service';
|
||||
import { TransactionService } from './services/transaction.service';
|
||||
|
||||
@Module({
|
||||
imports: [TypeOrmModule.forFeature([Card, Account, Transaction])],
|
||||
providers: [
|
||||
CardService,
|
||||
CardRepository,
|
||||
TransactionService,
|
||||
TransactionRepository,
|
||||
AccountService,
|
||||
AccountRepository,
|
||||
],
|
||||
exports: [CardService, TransactionService],
|
||||
})
|
||||
export class CardModule {}
|
39
src/card/entities/account.entity.ts
Normal file
39
src/card/entities/account.entity.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import { Column, CreateDateColumn, Entity, Index, OneToMany, PrimaryGeneratedColumn, UpdateDateColumn } from 'typeorm';
|
||||
import { Card } from './card.entity';
|
||||
import { Transaction } from './transaction.entity';
|
||||
|
||||
@Entity('accounts')
|
||||
export class Account {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id!: string;
|
||||
|
||||
@Column('varchar', { length: 255, nullable: false, unique: true, name: 'account_reference' })
|
||||
@Index({ unique: true })
|
||||
accountReference!: string;
|
||||
|
||||
@Index({ unique: true })
|
||||
@Column('varchar', { length: 255, nullable: false, name: 'account_number' })
|
||||
accountNumber!: string;
|
||||
|
||||
@Index({ unique: true })
|
||||
@Column('varchar', { length: 255, nullable: false, name: 'iban' })
|
||||
iban!: string;
|
||||
|
||||
@Column('varchar', { length: 255, nullable: false, name: 'currency' })
|
||||
currency!: string;
|
||||
|
||||
@Column('decimal', { precision: 10, scale: 2, default: 0.0, name: 'balance' })
|
||||
balance!: number;
|
||||
|
||||
@OneToMany(() => Card, (card) => card.account, { cascade: true })
|
||||
cards!: Card[];
|
||||
|
||||
@OneToMany(() => Transaction, (transaction) => transaction.account, { cascade: true })
|
||||
transactions!: Transaction[];
|
||||
|
||||
@CreateDateColumn({ name: 'created_at', type: 'timestamp with time zone' })
|
||||
createdAt!: Date;
|
||||
|
||||
@UpdateDateColumn({ name: 'updated_at', type: 'timestamp with time zone' })
|
||||
updatedAt!: Date;
|
||||
}
|
89
src/card/entities/card.entity.ts
Normal file
89
src/card/entities/card.entity.ts
Normal file
@ -0,0 +1,89 @@
|
||||
import {
|
||||
Column,
|
||||
CreateDateColumn,
|
||||
Entity,
|
||||
Index,
|
||||
JoinColumn,
|
||||
ManyToOne,
|
||||
OneToMany,
|
||||
PrimaryGeneratedColumn,
|
||||
UpdateDateColumn,
|
||||
} from 'typeorm';
|
||||
import { Customer } from '~/customer/entities';
|
||||
import { CardColors, CardIssuers, CardScheme, CardStatus, CardStatusDescription, CustomerType } from '../enums';
|
||||
import { Account } from './account.entity';
|
||||
import { Transaction } from './transaction.entity';
|
||||
|
||||
@Entity('cards')
|
||||
export class Card {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id!: string;
|
||||
|
||||
@Index({ unique: true })
|
||||
@Column({ name: 'card_reference', nullable: false, type: 'varchar' })
|
||||
cardReference!: string;
|
||||
|
||||
@Index({ unique: true })
|
||||
@Column({ name: 'vpan', nullable: false, type: 'varchar' })
|
||||
vpan!: string;
|
||||
|
||||
@Column({ length: 6, name: 'first_six_digits', nullable: false, type: 'varchar' })
|
||||
firstSixDigits!: string;
|
||||
|
||||
@Column({ length: 4, name: 'last_four_digits', nullable: false, type: 'varchar' })
|
||||
lastFourDigits!: string;
|
||||
|
||||
@Column({ type: 'varchar', nullable: false })
|
||||
expiry!: string;
|
||||
|
||||
@Column({ type: 'varchar', nullable: false, name: 'customer_type' })
|
||||
customerType!: CustomerType;
|
||||
|
||||
@Column({ type: 'varchar', nullable: false, default: CardColors.BLUE })
|
||||
color!: CardColors;
|
||||
|
||||
@Column({ type: 'varchar', nullable: false, default: CardStatus.PENDING })
|
||||
status!: CardStatus;
|
||||
|
||||
@Column({ type: 'varchar', nullable: false, default: CardStatusDescription.PENDING_ACTIVATION })
|
||||
statusDescription!: CardStatusDescription;
|
||||
|
||||
@Column({ type: 'decimal', precision: 10, scale: 2, default: 0.0, name: 'limit' })
|
||||
limit!: number;
|
||||
|
||||
@Column({ type: 'varchar', nullable: false, default: CardScheme.VISA })
|
||||
scheme!: CardScheme;
|
||||
|
||||
@Column({ type: 'varchar', nullable: false })
|
||||
issuer!: CardIssuers;
|
||||
|
||||
@Column({ type: 'uuid', name: 'customer_id', nullable: false })
|
||||
customerId!: string;
|
||||
|
||||
@Column({ type: 'uuid', name: 'parent_id', nullable: true })
|
||||
parentId?: string;
|
||||
|
||||
@Column({ type: 'uuid', name: 'account_id', nullable: false })
|
||||
accountId!: string;
|
||||
|
||||
@ManyToOne(() => Customer, (customer) => customer.childCards)
|
||||
@JoinColumn({ name: 'parent_id' })
|
||||
parentCustomer?: Customer;
|
||||
|
||||
@ManyToOne(() => Customer, (customer) => customer.cards, { onDelete: 'CASCADE' })
|
||||
@JoinColumn({ name: 'customer_id' })
|
||||
customer!: Customer;
|
||||
|
||||
@ManyToOne(() => Account, (account) => account.cards, { onDelete: 'CASCADE' })
|
||||
@JoinColumn({ name: 'account_id' })
|
||||
account!: Account;
|
||||
|
||||
@OneToMany(() => Transaction, (transaction) => transaction.card, { cascade: true })
|
||||
transactions!: Transaction[];
|
||||
|
||||
@CreateDateColumn({ name: 'created_at', type: 'timestamp with time zone' })
|
||||
createdAt!: Date;
|
||||
|
||||
@UpdateDateColumn({ type: 'timestamp with time zone', name: 'updated_at' })
|
||||
updatedAt!: Date;
|
||||
}
|
1
src/card/entities/index.ts
Normal file
1
src/card/entities/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './card.entity';
|
69
src/card/entities/transaction.entity.ts
Normal file
69
src/card/entities/transaction.entity.ts
Normal file
@ -0,0 +1,69 @@
|
||||
import { Column, CreateDateColumn, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn } from 'typeorm';
|
||||
import { TransactionScope, TransactionType } from '../enums';
|
||||
import { Account } from './account.entity';
|
||||
import { Card } from './card.entity';
|
||||
|
||||
@Entity('transactions')
|
||||
export class Transaction {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id!: string;
|
||||
|
||||
@Column({ name: 'transaction_scope', type: 'varchar', nullable: false })
|
||||
transactionScope!: TransactionScope;
|
||||
|
||||
@Column({ name: 'transaction_type', type: 'varchar', default: TransactionType.EXTERNAL })
|
||||
transactionType!: TransactionType;
|
||||
|
||||
@Column({ name: 'card_reference', nullable: true, type: 'varchar' })
|
||||
cardReference!: string;
|
||||
|
||||
@Column({ name: 'account_reference', nullable: true, type: 'varchar' })
|
||||
accountReference!: string;
|
||||
|
||||
@Column({ name: 'transaction_id', unique: true, nullable: true, type: 'varchar' })
|
||||
transactionId!: string;
|
||||
|
||||
@Column({ name: 'card_masked_number', nullable: true, type: 'varchar' })
|
||||
cardMaskedNumber!: string;
|
||||
|
||||
@Column({ type: 'timestamp with time zone', name: 'transaction_date', nullable: true })
|
||||
transactionDate!: Date;
|
||||
|
||||
@Column({ name: 'rrn', nullable: true, type: 'varchar' })
|
||||
rrn!: string;
|
||||
|
||||
@Column({ type: 'decimal', precision: 12, scale: 2, name: 'transaction_amount' })
|
||||
transactionAmount!: number;
|
||||
|
||||
@Column({ type: 'varchar', name: 'transaction_currency' })
|
||||
transactionCurrency!: string;
|
||||
|
||||
@Column({ type: 'decimal', name: 'billing_amount', precision: 12, scale: 2 })
|
||||
billingAmount!: number;
|
||||
|
||||
@Column({ type: 'decimal', name: 'settlement_amount', precision: 12, scale: 2 })
|
||||
settlementAmount!: number;
|
||||
|
||||
@Column({ type: 'decimal', name: 'fees', precision: 12, scale: 2 })
|
||||
fees!: number;
|
||||
|
||||
@Column({ type: 'decimal', name: 'vat_on_fees', precision: 12, scale: 2, default: 0.0 })
|
||||
vatOnFees!: number;
|
||||
|
||||
@Column({ name: 'card_id', type: 'uuid', nullable: true })
|
||||
cardId!: string;
|
||||
|
||||
@Column({ name: 'account_id', type: 'uuid', nullable: true })
|
||||
accountId!: string;
|
||||
|
||||
@ManyToOne(() => Card, (card) => card.transactions, { onDelete: 'CASCADE', nullable: true })
|
||||
@JoinColumn({ name: 'card_id' })
|
||||
card!: Card;
|
||||
|
||||
@ManyToOne(() => Account, (account) => account.transactions, { onDelete: 'CASCADE', nullable: true })
|
||||
@JoinColumn({ name: 'account_id' })
|
||||
account!: Account;
|
||||
|
||||
@CreateDateColumn({ name: 'created_at', type: 'timestamp with time zone' })
|
||||
createdAt!: Date;
|
||||
}
|
4
src/card/enums/card-colors.enum.ts
Normal file
4
src/card/enums/card-colors.enum.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export enum CardColors {
|
||||
RED = 'RED',
|
||||
BLUE = 'BLUE',
|
||||
}
|
3
src/card/enums/card-issuers.enum.ts
Normal file
3
src/card/enums/card-issuers.enum.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export enum CardIssuers {
|
||||
NEOLEAP = 'NEOLEAP',
|
||||
}
|
4
src/card/enums/card-scheme.enum.ts
Normal file
4
src/card/enums/card-scheme.enum.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export enum CardScheme {
|
||||
VISA = 'VISA',
|
||||
MASTERCARD = 'MASTERCARD',
|
||||
}
|
68
src/card/enums/card-status-description.enum.ts
Normal file
68
src/card/enums/card-status-description.enum.ts
Normal file
@ -0,0 +1,68 @@
|
||||
/**
|
||||
* import { CardStatus, CardStatusDescription } from '../enums';
|
||||
|
||||
export const CardStatusMapper: Record<string, { description: CardStatusDescription; status: CardStatus }> = {
|
||||
//ACTIVE
|
||||
'00': { description: 'NORMAL', status: CardStatus.ACTIVE },
|
||||
|
||||
//PENDING
|
||||
'02': { description: 'NOT_YET_ISSUED', status: CardStatus.PENDING },
|
||||
'20': { description: 'PENDING_ISSUANCE', status: CardStatus.PENDING },
|
||||
'21': { description: 'CARD_EXTRACTED', status: CardStatus.PENDING },
|
||||
'22': { description: 'EXTRACTION_FAILED', status: CardStatus.PENDING },
|
||||
'23': { description: 'FAILED_PRINTING_BULK', status: CardStatus.PENDING },
|
||||
'24': { description: 'FAILED_PRINTING_INST', status: CardStatus.PENDING },
|
||||
'30': { description: 'PENDING_ACTIVATION', status: CardStatus.PENDING },
|
||||
'27': { description: 'PENDING_PIN', status: CardStatus.PENDING },
|
||||
'16': { description: 'PREPARE_TO_CLOSE', status: CardStatus.PENDING },
|
||||
|
||||
//BLOCKED
|
||||
'01': { description: 'PIN_TRIES_EXCEEDED', status: CardStatus.BLOCKED },
|
||||
'03': { description: 'CARD_EXPIRED', status: CardStatus.BLOCKED },
|
||||
'04': { description: 'LOST', status: CardStatus.BLOCKED },
|
||||
'05': { description: 'STOLEN', status: CardStatus.BLOCKED },
|
||||
'06': { description: 'CUSTOMER_CLOSE', status: CardStatus.BLOCKED },
|
||||
'07': { description: 'BANK_CANCELLED', status: CardStatus.BLOCKED },
|
||||
'08': { description: 'FRAUD', status: CardStatus.BLOCKED },
|
||||
'09': { description: 'DAMAGED', status: CardStatus.BLOCKED },
|
||||
'50': { description: 'SAFE_BLOCK', status: CardStatus.BLOCKED },
|
||||
'51': { description: 'TEMPORARY_BLOCK', status: CardStatus.BLOCKED },
|
||||
'52': { description: 'RISK_BLOCK', status: CardStatus.BLOCKED },
|
||||
'53': { description: 'OVERDRAFT', status: CardStatus.BLOCKED },
|
||||
'54': { description: 'BLOCKED_FOR_FEES', status: CardStatus.BLOCKED },
|
||||
'67': { description: 'CLOSED_CUSTOMER_DEAD', status: CardStatus.BLOCKED },
|
||||
'75': { description: 'RETURN_CARD', status: CardStatus.BLOCKED },
|
||||
|
||||
//Fallback
|
||||
'99': { description: 'UNKNOWN', status: CardStatus.PENDING },
|
||||
};
|
||||
|
||||
*/
|
||||
export enum CardStatusDescription {
|
||||
NORMAL = 'NORMAL',
|
||||
NOT_YET_ISSUED = 'NOT_YET_ISSUED',
|
||||
PENDING_ISSUANCE = 'PENDING_ISSUANCE',
|
||||
CARD_EXTRACTED = 'CARD_EXTRACTED',
|
||||
EXTRACTION_FAILED = 'EXTRACTION_FAILED',
|
||||
FAILED_PRINTING_BULK = 'FAILED_PRINTING_BULK',
|
||||
FAILED_PRINTING_INST = 'FAILED_PRINTING_INST',
|
||||
PENDING_ACTIVATION = 'PENDING_ACTIVATION',
|
||||
PENDING_PIN = 'PENDING_PIN',
|
||||
PREPARE_TO_CLOSE = 'PREPARE_TO_CLOSE',
|
||||
PIN_TRIES_EXCEEDED = 'PIN_TRIES_EXCEEDED',
|
||||
CARD_EXPIRED = 'CARD_EXPIRED',
|
||||
LOST = 'LOST',
|
||||
STOLEN = 'STOLEN',
|
||||
CUSTOMER_CLOSE = 'CUSTOMER_CLOSE',
|
||||
BANK_CANCELLED = 'BANK_CANCELLED',
|
||||
FRAUD = 'FRAUD',
|
||||
DAMAGED = 'DAMAGED',
|
||||
SAFE_BLOCK = 'SAFE_BLOCK',
|
||||
TEMPORARY_BLOCK = 'TEMPORARY_BLOCK',
|
||||
RISK_BLOCK = 'RISK_BLOCK',
|
||||
OVERDRAFT = 'OVERDRAFT',
|
||||
BLOCKED_FOR_FEES = 'BLOCKED_FOR_FEES',
|
||||
CLOSED_CUSTOMER_DEAD = 'CLOSED_CUSTOMER_DEAD',
|
||||
RETURN_CARD = 'RETURN_CARD',
|
||||
UNKNOWN = 'UNKNOWN',
|
||||
}
|
6
src/card/enums/card-status.enum.ts
Normal file
6
src/card/enums/card-status.enum.ts
Normal file
@ -0,0 +1,6 @@
|
||||
export enum CardStatus {
|
||||
ACTIVE = 'ACTIVE',
|
||||
CANCELED = 'CANCELED',
|
||||
BLOCKED = 'BLOCKED',
|
||||
PENDING = 'PENDING',
|
||||
}
|
4
src/card/enums/customer-type.enum.ts
Normal file
4
src/card/enums/customer-type.enum.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export enum CustomerType {
|
||||
PARENT = 'PARENT',
|
||||
CHILD = 'CHILD',
|
||||
}
|
8
src/card/enums/index.ts
Normal file
8
src/card/enums/index.ts
Normal file
@ -0,0 +1,8 @@
|
||||
export * from './card-colors.enum';
|
||||
export * from './card-issuers.enum';
|
||||
export * from './card-scheme.enum';
|
||||
export * from './card-status-description.enum';
|
||||
export * from './card-status.enum';
|
||||
export * from './customer-type.enum';
|
||||
export * from './transaction-scope.enum';
|
||||
export * from './transaction-type.enum';
|
4
src/card/enums/transaction-scope.enum.ts
Normal file
4
src/card/enums/transaction-scope.enum.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export enum TransactionScope {
|
||||
CARD = 'CARD',
|
||||
ACCOUNT = 'ACCOUNT',
|
||||
}
|
4
src/card/enums/transaction-type.enum.ts
Normal file
4
src/card/enums/transaction-type.enum.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export enum TransactionType {
|
||||
INTERNAL = 'INTERNAL',
|
||||
EXTERNAL = 'EXTERNAL',
|
||||
}
|
109
src/card/mappers/card-status-description.mapper.ts
Normal file
109
src/card/mappers/card-status-description.mapper.ts
Normal file
@ -0,0 +1,109 @@
|
||||
import { UserLocale } from '~/core/enums';
|
||||
import { CardStatusDescription } from '../enums';
|
||||
|
||||
export const CardStatusMapper: Record<CardStatusDescription, { [key in UserLocale]: { description: string } }> = {
|
||||
[CardStatusDescription.NORMAL]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card is active' },
|
||||
[UserLocale.ARABIC]: { description: 'البطاقة نشطة' },
|
||||
},
|
||||
[CardStatusDescription.NOT_YET_ISSUED]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card is not yet issued' },
|
||||
[UserLocale.ARABIC]: { description: 'البطاقة لم تصدر بعد' },
|
||||
},
|
||||
[CardStatusDescription.PENDING_ISSUANCE]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card is pending issuance' },
|
||||
[UserLocale.ARABIC]: { description: 'البطاقة قيد الإصدار' },
|
||||
},
|
||||
[CardStatusDescription.CARD_EXTRACTED]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card has been extracted' },
|
||||
[UserLocale.ARABIC]: { description: 'تم استخراج البطاقة' },
|
||||
},
|
||||
[CardStatusDescription.EXTRACTION_FAILED]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card extraction has failed' },
|
||||
[UserLocale.ARABIC]: { description: 'فشل استخراج البطاقة' },
|
||||
},
|
||||
[CardStatusDescription.FAILED_PRINTING_BULK]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card printing in bulk has failed' },
|
||||
[UserLocale.ARABIC]: { description: 'فشل الطباعة بالجملة للبطاقة' },
|
||||
},
|
||||
[CardStatusDescription.FAILED_PRINTING_INST]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card printing in institution has failed' },
|
||||
[UserLocale.ARABIC]: { description: 'فشل الطباعة في المؤسسة للبطاقة' },
|
||||
},
|
||||
[CardStatusDescription.PENDING_ACTIVATION]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card is pending activation' },
|
||||
[UserLocale.ARABIC]: { description: 'البطاقة قيد التفعيل' },
|
||||
},
|
||||
[CardStatusDescription.PENDING_PIN]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card is pending PIN' },
|
||||
[UserLocale.ARABIC]: { description: 'البطاقة قيد الانتظار لرقم التعريف الشخصي' },
|
||||
},
|
||||
[CardStatusDescription.PREPARE_TO_CLOSE]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card is being prepared for closure' },
|
||||
[UserLocale.ARABIC]: { description: 'البطاقة قيد التحضير للإغلاق' },
|
||||
},
|
||||
[CardStatusDescription.PIN_TRIES_EXCEEDED]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card PIN tries have been exceeded' },
|
||||
[UserLocale.ARABIC]: { description: 'تم تجاوز محاولات رقم التعريف الشخصي للبطاقة' },
|
||||
},
|
||||
[CardStatusDescription.CARD_EXPIRED]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card has expired' },
|
||||
[UserLocale.ARABIC]: { description: 'انتهت صلاحية البطاقة' },
|
||||
},
|
||||
[CardStatusDescription.LOST]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card is lost' },
|
||||
[UserLocale.ARABIC]: { description: 'البطاقة ضائعة' },
|
||||
},
|
||||
[CardStatusDescription.STOLEN]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card is stolen' },
|
||||
[UserLocale.ARABIC]: { description: 'البطاقة مسروقة' },
|
||||
},
|
||||
[CardStatusDescription.CUSTOMER_CLOSE]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card is being closed by the customer' },
|
||||
[UserLocale.ARABIC]: { description: 'البطاقة قيد الإغلاق من قبل العميل' },
|
||||
},
|
||||
[CardStatusDescription.BANK_CANCELLED]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card has been cancelled by the bank' },
|
||||
[UserLocale.ARABIC]: { description: 'البطاقة ألغيت من قبل البنك' },
|
||||
},
|
||||
[CardStatusDescription.FRAUD]: {
|
||||
[UserLocale.ENGLISH]: { description: 'Fraud' },
|
||||
[UserLocale.ARABIC]: { description: 'احتيال' },
|
||||
},
|
||||
[CardStatusDescription.DAMAGED]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card is damaged' },
|
||||
[UserLocale.ARABIC]: { description: 'البطاقة تالفة' },
|
||||
},
|
||||
[CardStatusDescription.SAFE_BLOCK]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card is in a safe block' },
|
||||
[UserLocale.ARABIC]: { description: 'البطاقة في حظر آمن' },
|
||||
},
|
||||
[CardStatusDescription.TEMPORARY_BLOCK]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card is in a temporary block' },
|
||||
[UserLocale.ARABIC]: { description: 'البطاقة في حظر مؤقت' },
|
||||
},
|
||||
[CardStatusDescription.RISK_BLOCK]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card is in a risk block' },
|
||||
[UserLocale.ARABIC]: { description: 'البطاقة في حظر المخاطر' },
|
||||
},
|
||||
[CardStatusDescription.OVERDRAFT]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card is in overdraft' },
|
||||
[UserLocale.ARABIC]: { description: 'البطاقة في السحب على المكشوف' },
|
||||
},
|
||||
[CardStatusDescription.BLOCKED_FOR_FEES]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card is blocked for fees' },
|
||||
[UserLocale.ARABIC]: { description: 'البطاقة محظورة للرسوم' },
|
||||
},
|
||||
[CardStatusDescription.CLOSED_CUSTOMER_DEAD]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card is closed because the customer is dead' },
|
||||
[UserLocale.ARABIC]: { description: 'البطاقة مغلقة لأن العميل متوفى' },
|
||||
},
|
||||
[CardStatusDescription.RETURN_CARD]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card is being returned' },
|
||||
[UserLocale.ARABIC]: { description: 'البطاقة قيد الإرجاع' },
|
||||
},
|
||||
[CardStatusDescription.UNKNOWN]: {
|
||||
[UserLocale.ENGLISH]: { description: 'The card status is unknown' },
|
||||
[UserLocale.ARABIC]: { description: 'حالة البطاقة غير معروفة' },
|
||||
},
|
||||
};
|
37
src/card/mappers/card-status.mapper.ts
Normal file
37
src/card/mappers/card-status.mapper.ts
Normal file
@ -0,0 +1,37 @@
|
||||
import { CardStatus, CardStatusDescription } from '../enums';
|
||||
|
||||
export const CardStatusMapper: Record<string, { description: CardStatusDescription; status: CardStatus }> = {
|
||||
//ACTIVE
|
||||
'00': { description: CardStatusDescription.NORMAL, status: CardStatus.ACTIVE },
|
||||
|
||||
//PENDING
|
||||
'02': { description: CardStatusDescription.NOT_YET_ISSUED, status: CardStatus.PENDING },
|
||||
'20': { description: CardStatusDescription.PENDING_ISSUANCE, status: CardStatus.PENDING },
|
||||
'21': { description: CardStatusDescription.CARD_EXTRACTED, status: CardStatus.PENDING },
|
||||
'22': { description: CardStatusDescription.EXTRACTION_FAILED, status: CardStatus.PENDING },
|
||||
'23': { description: CardStatusDescription.FAILED_PRINTING_BULK, status: CardStatus.PENDING },
|
||||
'24': { description: CardStatusDescription.FAILED_PRINTING_INST, status: CardStatus.PENDING },
|
||||
'30': { description: CardStatusDescription.PENDING_ACTIVATION, status: CardStatus.PENDING },
|
||||
'27': { description: CardStatusDescription.PENDING_PIN, status: CardStatus.PENDING },
|
||||
'16': { description: CardStatusDescription.PREPARE_TO_CLOSE, status: CardStatus.PENDING },
|
||||
|
||||
//BLOCKED
|
||||
'01': { description: CardStatusDescription.PIN_TRIES_EXCEEDED, status: CardStatus.BLOCKED },
|
||||
'03': { description: CardStatusDescription.CARD_EXPIRED, status: CardStatus.BLOCKED },
|
||||
'04': { description: CardStatusDescription.LOST, status: CardStatus.BLOCKED },
|
||||
'05': { description: CardStatusDescription.STOLEN, status: CardStatus.BLOCKED },
|
||||
'06': { description: CardStatusDescription.CUSTOMER_CLOSE, status: CardStatus.BLOCKED },
|
||||
'07': { description: CardStatusDescription.BANK_CANCELLED, status: CardStatus.BLOCKED },
|
||||
'08': { description: CardStatusDescription.FRAUD, status: CardStatus.BLOCKED },
|
||||
'09': { description: CardStatusDescription.DAMAGED, status: CardStatus.BLOCKED },
|
||||
'50': { description: CardStatusDescription.SAFE_BLOCK, status: CardStatus.BLOCKED },
|
||||
'51': { description: CardStatusDescription.TEMPORARY_BLOCK, status: CardStatus.BLOCKED },
|
||||
'52': { description: CardStatusDescription.RISK_BLOCK, status: CardStatus.BLOCKED },
|
||||
'53': { description: CardStatusDescription.OVERDRAFT, status: CardStatus.BLOCKED },
|
||||
'54': { description: CardStatusDescription.BLOCKED_FOR_FEES, status: CardStatus.BLOCKED },
|
||||
'67': { description: CardStatusDescription.CLOSED_CUSTOMER_DEAD, status: CardStatus.BLOCKED },
|
||||
'75': { description: CardStatusDescription.RETURN_CARD, status: CardStatus.BLOCKED },
|
||||
|
||||
//Fallback
|
||||
'99': { description: CardStatusDescription.UNKNOWN, status: CardStatus.PENDING },
|
||||
};
|
44
src/card/repositories/account.repository.ts
Normal file
44
src/card/repositories/account.repository.ts
Normal file
@ -0,0 +1,44 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { CreateApplicationResponse } from '~/common/modules/neoleap/dtos/response';
|
||||
import { Account } from '../entities/account.entity';
|
||||
|
||||
@Injectable()
|
||||
export class AccountRepository {
|
||||
constructor(@InjectRepository(Account) private readonly accountRepository: Repository<Account>) {}
|
||||
|
||||
createAccount(data: CreateApplicationResponse): Promise<Account> {
|
||||
return this.accountRepository.save(
|
||||
this.accountRepository.create({
|
||||
accountReference: data.accountId,
|
||||
accountNumber: data.accountNumber,
|
||||
iban: data.iBan,
|
||||
balance: 0,
|
||||
currency: '682',
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
getAccountByReferenceNumber(accountReference: string): Promise<Account | null> {
|
||||
return this.accountRepository.findOne({
|
||||
where: { accountReference },
|
||||
relations: ['cards'],
|
||||
});
|
||||
}
|
||||
|
||||
getAccountByAccountNumber(accountNumber: string): Promise<Account | null> {
|
||||
return this.accountRepository.findOne({
|
||||
where: { accountNumber },
|
||||
relations: ['cards'],
|
||||
});
|
||||
}
|
||||
|
||||
topUpAccountBalance(accountReference: string, amount: number) {
|
||||
return this.accountRepository.increment({ accountReference }, 'balance', amount);
|
||||
}
|
||||
|
||||
decreaseAccountBalance(accountReference: string, amount: number) {
|
||||
return this.accountRepository.decrement({ accountReference }, 'balance', amount);
|
||||
}
|
||||
}
|
57
src/card/repositories/card.repository.ts
Normal file
57
src/card/repositories/card.repository.ts
Normal file
@ -0,0 +1,57 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { CreateApplicationResponse } from '~/common/modules/neoleap/dtos/response';
|
||||
import { Card } from '../entities';
|
||||
import { CardColors, CardIssuers, CardScheme, CardStatus, CardStatusDescription, CustomerType } from '../enums';
|
||||
|
||||
@Injectable()
|
||||
export class CardRepository {
|
||||
constructor(@InjectRepository(Card) private readonly cardRepository: Repository<Card>) {}
|
||||
|
||||
createCard(customerId: string, accountId: string, card: CreateApplicationResponse): Promise<Card> {
|
||||
return this.cardRepository.save(
|
||||
this.cardRepository.create({
|
||||
customerId: customerId,
|
||||
expiry: card.expiryDate,
|
||||
cardReference: card.cardId,
|
||||
customerType: CustomerType.PARENT,
|
||||
firstSixDigits: card.firstSixDigits,
|
||||
lastFourDigits: card.lastFourDigits,
|
||||
color: CardColors.BLUE,
|
||||
scheme: CardScheme.VISA,
|
||||
issuer: CardIssuers.NEOLEAP,
|
||||
accountId: accountId,
|
||||
vpan: card.vpan,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
getCardById(id: string): Promise<Card | null> {
|
||||
return this.cardRepository.findOne({ where: { id } });
|
||||
}
|
||||
|
||||
getCardByReferenceNumber(referenceNumber: string): Promise<Card | null> {
|
||||
return this.cardRepository.findOne({ where: { cardReference: referenceNumber }, relations: ['account'] });
|
||||
}
|
||||
|
||||
getCardByVpan(vpan: string): Promise<Card | null> {
|
||||
return this.cardRepository.findOne({
|
||||
where: { vpan },
|
||||
relations: ['account'],
|
||||
});
|
||||
}
|
||||
|
||||
getActiveCardForCustomer(customerId: string): Promise<Card | null> {
|
||||
return this.cardRepository.findOne({
|
||||
where: { customerId, status: CardStatus.ACTIVE },
|
||||
});
|
||||
}
|
||||
|
||||
updateCardStatus(id: string, status: CardStatus, statusDescription: CardStatusDescription) {
|
||||
return this.cardRepository.update(id, {
|
||||
status: status,
|
||||
statusDescription: statusDescription,
|
||||
});
|
||||
}
|
||||
}
|
1
src/card/repositories/index.ts
Normal file
1
src/card/repositories/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './card.repository';
|
65
src/card/repositories/transaction.repository.ts
Normal file
65
src/card/repositories/transaction.repository.ts
Normal file
@ -0,0 +1,65 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import moment from 'moment';
|
||||
import { Repository } from 'typeorm';
|
||||
import {
|
||||
AccountTransactionWebhookRequest,
|
||||
CardTransactionWebhookRequest,
|
||||
} from '~/common/modules/neoleap/dtos/requests';
|
||||
import { Card } from '../entities';
|
||||
import { Account } from '../entities/account.entity';
|
||||
import { Transaction } from '../entities/transaction.entity';
|
||||
import { TransactionScope, TransactionType } from '../enums';
|
||||
|
||||
@Injectable()
|
||||
export class TransactionRepository {
|
||||
constructor(@InjectRepository(Transaction) private transactionRepository: Repository<Transaction>) {}
|
||||
|
||||
createCardTransaction(card: Card, transactionData: CardTransactionWebhookRequest): Promise<Transaction> {
|
||||
return this.transactionRepository.save(
|
||||
this.transactionRepository.create({
|
||||
transactionId: transactionData.transactionId,
|
||||
cardReference: transactionData.cardId,
|
||||
transactionAmount: transactionData.transactionAmount,
|
||||
transactionCurrency: transactionData.transactionCurrency,
|
||||
billingAmount: transactionData.billingAmount,
|
||||
settlementAmount: transactionData.settlementAmount,
|
||||
transactionDate: moment(transactionData.date + transactionData.time, 'YYYYMMDDHHmmss').toDate(),
|
||||
rrn: transactionData.rrn,
|
||||
cardMaskedNumber: transactionData.cardMaskedNumber,
|
||||
fees: transactionData.fees,
|
||||
cardId: card.id,
|
||||
accountId: card.account!.id,
|
||||
transactionType: TransactionType.EXTERNAL,
|
||||
accountReference: card.account!.accountReference,
|
||||
transactionScope: TransactionScope.CARD,
|
||||
vatOnFees: transactionData.vatOnFees,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
createAccountTransaction(account: Account, transactionData: AccountTransactionWebhookRequest): Promise<Transaction> {
|
||||
return this.transactionRepository.save(
|
||||
this.transactionRepository.create({
|
||||
transactionId: transactionData.transactionId,
|
||||
transactionAmount: transactionData.amount,
|
||||
transactionCurrency: transactionData.currency,
|
||||
billingAmount: 0,
|
||||
settlementAmount: 0,
|
||||
transactionDate: moment(transactionData.date + transactionData.time, 'YYYYMMDDHHmmss').toDate(),
|
||||
fees: 0,
|
||||
accountReference: account.accountReference,
|
||||
accountId: account.id,
|
||||
transactionType: TransactionType.EXTERNAL,
|
||||
transactionScope: TransactionScope.ACCOUNT,
|
||||
vatOnFees: 0,
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
findTransactionByReference(transactionId: string, accountReference: string): Promise<Transaction | null> {
|
||||
return this.transactionRepository.findOne({
|
||||
where: { transactionId, accountReference },
|
||||
});
|
||||
}
|
||||
}
|
47
src/card/services/account.service.ts
Normal file
47
src/card/services/account.service.ts
Normal file
@ -0,0 +1,47 @@
|
||||
import { Injectable, UnprocessableEntityException } from '@nestjs/common';
|
||||
import { CreateApplicationResponse } from '~/common/modules/neoleap/dtos/response';
|
||||
import { Account } from '../entities/account.entity';
|
||||
import { AccountRepository } from '../repositories/account.repository';
|
||||
|
||||
@Injectable()
|
||||
export class AccountService {
|
||||
constructor(private readonly accountRepository: AccountRepository) {}
|
||||
|
||||
createAccount(data: CreateApplicationResponse): Promise<Account> {
|
||||
return this.accountRepository.createAccount(data);
|
||||
}
|
||||
|
||||
async getAccountByReferenceNumber(accountReference: string): Promise<Account> {
|
||||
const account = await this.accountRepository.getAccountByReferenceNumber(accountReference);
|
||||
if (!account) {
|
||||
throw new UnprocessableEntityException('ACCOUNT.NOT_FOUND');
|
||||
}
|
||||
return account;
|
||||
}
|
||||
|
||||
async getAccountByAccountNumber(accountNumber: string): Promise<Account> {
|
||||
const account = await this.accountRepository.getAccountByAccountNumber(accountNumber);
|
||||
if (!account) {
|
||||
throw new UnprocessableEntityException('ACCOUNT.NOT_FOUND');
|
||||
}
|
||||
return account;
|
||||
}
|
||||
|
||||
async creditAccountBalance(accountReference: string, amount: number) {
|
||||
return this.accountRepository.topUpAccountBalance(accountReference, amount);
|
||||
}
|
||||
|
||||
async decreaseAccountBalance(accountReference: string, amount: number) {
|
||||
const account = await this.getAccountByReferenceNumber(accountReference);
|
||||
/**
|
||||
* While there is no need to check for insufficient balance because this is a webhook handler,
|
||||
* I just added this check to ensure we don't have corruption in our data especially if this service is used elsewhere.
|
||||
*/
|
||||
|
||||
if (account.balance < amount) {
|
||||
throw new UnprocessableEntityException('ACCOUNT.INSUFFICIENT_BALANCE');
|
||||
}
|
||||
|
||||
return this.accountRepository.decreaseAccountBalance(accountReference, amount);
|
||||
}
|
||||
}
|
63
src/card/services/card.service.ts
Normal file
63
src/card/services/card.service.ts
Normal file
@ -0,0 +1,63 @@
|
||||
import { BadRequestException, Injectable } from '@nestjs/common';
|
||||
import { Transactional } from 'typeorm-transactional';
|
||||
import { AccountCardStatusChangedWebhookRequest } from '~/common/modules/neoleap/dtos/requests';
|
||||
import { CreateApplicationResponse } from '~/common/modules/neoleap/dtos/response';
|
||||
import { Card } from '../entities';
|
||||
import { CardStatusMapper } from '../mappers/card-status.mapper';
|
||||
import { CardRepository } from '../repositories';
|
||||
import { AccountService } from './account.service';
|
||||
|
||||
@Injectable()
|
||||
export class CardService {
|
||||
constructor(private readonly cardRepository: CardRepository, private readonly accountService: AccountService) {}
|
||||
|
||||
@Transactional()
|
||||
async createCard(customerId: string, cardData: CreateApplicationResponse): Promise<Card> {
|
||||
const account = await this.accountService.createAccount(cardData);
|
||||
return this.cardRepository.createCard(customerId, account.id, cardData);
|
||||
}
|
||||
|
||||
async getCardById(id: string): Promise<Card> {
|
||||
const card = await this.cardRepository.getCardById(id);
|
||||
|
||||
if (!card) {
|
||||
throw new BadRequestException('CARD.NOT_FOUND');
|
||||
}
|
||||
|
||||
return card;
|
||||
}
|
||||
|
||||
async getCardByReferenceNumber(referenceNumber: string): Promise<Card> {
|
||||
const card = await this.cardRepository.getCardByReferenceNumber(referenceNumber);
|
||||
|
||||
if (!card) {
|
||||
throw new BadRequestException('CARD.NOT_FOUND');
|
||||
}
|
||||
|
||||
return card;
|
||||
}
|
||||
|
||||
async getCardByVpan(vpan: string): Promise<Card> {
|
||||
const card = await this.cardRepository.getCardByVpan(vpan);
|
||||
|
||||
if (!card) {
|
||||
throw new BadRequestException('CARD.NOT_FOUND');
|
||||
}
|
||||
return card;
|
||||
}
|
||||
|
||||
async getActiveCardForCustomer(customerId: string): Promise<Card> {
|
||||
const card = await this.cardRepository.getActiveCardForCustomer(customerId);
|
||||
if (!card) {
|
||||
throw new BadRequestException('CARD.NOT_FOUND');
|
||||
}
|
||||
return card;
|
||||
}
|
||||
|
||||
async updateCardStatus(body: AccountCardStatusChangedWebhookRequest) {
|
||||
const card = await this.getCardByVpan(body.cardId);
|
||||
const { description, status } = CardStatusMapper[body.newStatus] || CardStatusMapper['99'];
|
||||
|
||||
return this.cardRepository.updateCardStatus(card.id, status, description);
|
||||
}
|
||||
}
|
1
src/card/services/index.ts
Normal file
1
src/card/services/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './card.service';
|
62
src/card/services/transaction.service.ts
Normal file
62
src/card/services/transaction.service.ts
Normal file
@ -0,0 +1,62 @@
|
||||
import { Injectable, UnprocessableEntityException } from '@nestjs/common';
|
||||
import Decimal from 'decimal.js';
|
||||
import { Transactional } from 'typeorm-transactional';
|
||||
import {
|
||||
AccountTransactionWebhookRequest,
|
||||
CardTransactionWebhookRequest,
|
||||
} from '~/common/modules/neoleap/dtos/requests';
|
||||
import { Transaction } from '../entities/transaction.entity';
|
||||
import { TransactionRepository } from '../repositories/transaction.repository';
|
||||
import { AccountService } from './account.service';
|
||||
import { CardService } from './card.service';
|
||||
|
||||
@Injectable()
|
||||
export class TransactionService {
|
||||
constructor(
|
||||
private readonly transactionRepository: TransactionRepository,
|
||||
private readonly cardService: CardService,
|
||||
private readonly accountService: AccountService,
|
||||
) {}
|
||||
|
||||
@Transactional()
|
||||
async createCardTransaction(body: CardTransactionWebhookRequest) {
|
||||
const card = await this.cardService.getCardByVpan(body.cardId);
|
||||
const existingTransaction = await this.findExistingTransaction(body.transactionId, card.account.accountReference);
|
||||
|
||||
if (existingTransaction) {
|
||||
throw new UnprocessableEntityException('TRANSACTION.ALREADY_EXISTS');
|
||||
}
|
||||
|
||||
const transaction = await this.transactionRepository.createCardTransaction(card, body);
|
||||
const total = new Decimal(body.transactionAmount).plus(body.billingAmount).plus(body.fees).plus(body.vatOnFees);
|
||||
|
||||
await this.accountService.decreaseAccountBalance(card.account.accountReference, total.toNumber());
|
||||
|
||||
return transaction;
|
||||
}
|
||||
|
||||
@Transactional()
|
||||
async createAccountTransaction(body: AccountTransactionWebhookRequest) {
|
||||
const account = await this.accountService.getAccountByAccountNumber(body.accountId);
|
||||
|
||||
const existingTransaction = await this.findExistingTransaction(body.transactionId, account.accountReference);
|
||||
|
||||
if (existingTransaction) {
|
||||
throw new UnprocessableEntityException('TRANSACTION.ALREADY_EXISTS');
|
||||
}
|
||||
|
||||
const transaction = await this.transactionRepository.createAccountTransaction(account, body);
|
||||
await this.accountService.creditAccountBalance(account.accountReference, body.amount);
|
||||
|
||||
return transaction;
|
||||
}
|
||||
|
||||
private async findExistingTransaction(transactionId: string, accountReference: string): Promise<Transaction | null> {
|
||||
const existingTransaction = await this.transactionRepository.findTransactionByReference(
|
||||
transactionId,
|
||||
accountReference,
|
||||
);
|
||||
|
||||
return existingTransaction;
|
||||
}
|
||||
}
|
253
src/common/constants/countries-numeric-iso.constant.ts
Normal file
253
src/common/constants/countries-numeric-iso.constant.ts
Normal file
@ -0,0 +1,253 @@
|
||||
import { CountryIso } from '../enums';
|
||||
|
||||
export const CountriesNumericISO: Record<CountryIso, string> = {
|
||||
[CountryIso.ARUBA]: '533',
|
||||
[CountryIso.AFGHANISTAN]: '004',
|
||||
[CountryIso.ANGOLA]: '024',
|
||||
[CountryIso.ANGUILLA]: '660',
|
||||
[CountryIso.ALAND_ISLANDS]: '248',
|
||||
[CountryIso.ALBANIA]: '008',
|
||||
[CountryIso.ANDORRA]: '020',
|
||||
[CountryIso.UNITED_ARAB_EMIRATES]: '784',
|
||||
[CountryIso.ARGENTINA]: '032',
|
||||
[CountryIso.ARMENIA]: '051',
|
||||
[CountryIso.AMERICAN_SAMOA]: '016',
|
||||
[CountryIso.ANTARCTICA]: '010',
|
||||
[CountryIso.FRENCH_SOUTHERN_TERRITORIES]: '260',
|
||||
[CountryIso.ANTIGUA_AND_BARBUDA]: '028',
|
||||
[CountryIso.AUSTRALIA]: '036',
|
||||
[CountryIso.AUSTRIA]: '040',
|
||||
[CountryIso.AZERBAIJAN]: '031',
|
||||
[CountryIso.BURUNDI]: '108',
|
||||
[CountryIso.BELGIUM]: '056',
|
||||
[CountryIso.BENIN]: '204',
|
||||
[CountryIso.BONAIRE_SINT_EUSTATIUS_AND_SABA]: '535',
|
||||
[CountryIso.BURKINA_FASO]: '854',
|
||||
[CountryIso.BANGLADESH]: '050',
|
||||
[CountryIso.BULGARIA]: '100',
|
||||
[CountryIso.BAHRAIN]: '048',
|
||||
[CountryIso.BAHAMAS]: '044',
|
||||
[CountryIso.BOSNIA_AND_HERZEGOVINA]: '070',
|
||||
[CountryIso.SAINT_BARTHÉLEMY]: '652',
|
||||
[CountryIso.BELARUS]: '112',
|
||||
[CountryIso.BELIZE]: '084',
|
||||
[CountryIso.BERMUDA]: '060',
|
||||
[CountryIso.BOLIVIA_PLURINATIONAL_STATE_OF]: '068',
|
||||
[CountryIso.BRAZIL]: '076',
|
||||
[CountryIso.BARBADOS]: '052',
|
||||
[CountryIso.BRUNEI_DARUSSALAM]: '096',
|
||||
[CountryIso.BHUTAN]: '064',
|
||||
[CountryIso.BOUVET_ISLAND]: '074',
|
||||
[CountryIso.BOTSWANA]: '072',
|
||||
[CountryIso.CENTRAL_AFRICAN_REPUBLIC]: '140',
|
||||
[CountryIso.CANADA]: '124',
|
||||
[CountryIso.COCOS_KEELING_ISLANDS]: '166',
|
||||
[CountryIso.SWITZERLAND]: '756',
|
||||
[CountryIso.CHILE]: '152',
|
||||
[CountryIso.CHINA]: '156',
|
||||
[CountryIso.COTE_DIVOIRE]: '384',
|
||||
[CountryIso.CAMEROON]: '120',
|
||||
[CountryIso.CONGO_THE_DEMOCRATIC_REPUBLIC_OF_THE]: '180',
|
||||
[CountryIso.CONGO]: '178',
|
||||
[CountryIso.COOK_ISLANDS]: '184',
|
||||
[CountryIso.COLOMBIA]: '170',
|
||||
[CountryIso.COMOROS]: '174',
|
||||
[CountryIso.CABO_VERDE]: '132',
|
||||
[CountryIso.COSTA_RICA]: '188',
|
||||
[CountryIso.CUBA]: '192',
|
||||
[CountryIso.CURAÇAO]: '531',
|
||||
[CountryIso.CHRISTMAS_ISLAND]: '162',
|
||||
[CountryIso.CAYMAN_ISLANDS]: '136',
|
||||
[CountryIso.CYPRUS]: '196',
|
||||
[CountryIso.CZECHIA]: '203',
|
||||
[CountryIso.GERMANY]: '276',
|
||||
[CountryIso.DJIBOUTI]: '262',
|
||||
[CountryIso.DOMINICA]: '212',
|
||||
[CountryIso.DENMARK]: '208',
|
||||
[CountryIso.DOMINICAN_REPUBLIC]: '214',
|
||||
[CountryIso.ALGERIA]: '012',
|
||||
[CountryIso.ECUADOR]: '218',
|
||||
[CountryIso.EGYPT]: '818',
|
||||
[CountryIso.ERITREA]: '232',
|
||||
[CountryIso.WESTERN_SAHARA]: '732',
|
||||
[CountryIso.SPAIN]: '724',
|
||||
[CountryIso.ESTONIA]: '233',
|
||||
[CountryIso.ETHIOPIA]: '231',
|
||||
[CountryIso.FINLAND]: '246',
|
||||
[CountryIso.FIJI]: '242',
|
||||
[CountryIso.FALKLAND_ISLANDS_MALVINAS]: '238',
|
||||
[CountryIso.FRANCE]: '250',
|
||||
[CountryIso.FAROE_ISLANDS]: '234',
|
||||
[CountryIso.MICRONESIA_FEDERATED_STATES_OF]: '583',
|
||||
[CountryIso.GABON]: '266',
|
||||
[CountryIso.UNITED_KINGDOM]: '826',
|
||||
[CountryIso.GEORGIA]: '268',
|
||||
[CountryIso.GUERNSEY]: '831',
|
||||
[CountryIso.GHANA]: '288',
|
||||
[CountryIso.GIBRALTAR]: '292',
|
||||
[CountryIso.GUINEA]: '324',
|
||||
[CountryIso.GUADELOUPE]: '312',
|
||||
[CountryIso.GAMBIA]: '270',
|
||||
[CountryIso.GUINEA_BISSAU]: '624',
|
||||
[CountryIso.EQUATORIAL_GUINEA]: '226',
|
||||
[CountryIso.GREECE]: '300',
|
||||
[CountryIso.GRENADA]: '308',
|
||||
[CountryIso.GREENLAND]: '304',
|
||||
[CountryIso.GUATEMALA]: '320',
|
||||
[CountryIso.FRENCH_GUIANA]: '254',
|
||||
[CountryIso.GUAM]: '316',
|
||||
[CountryIso.GUYANA]: '328',
|
||||
[CountryIso.HONG_KONG]: '344',
|
||||
[CountryIso.HEARD_ISLAND_AND_MCDONALD_ISLANDS]: '334',
|
||||
[CountryIso.HONDURAS]: '340',
|
||||
[CountryIso.CROATIA]: '191',
|
||||
[CountryIso.HAITI]: '332',
|
||||
[CountryIso.HUNGARY]: '348',
|
||||
[CountryIso.INDONESIA]: '360',
|
||||
[CountryIso.ISLE_OF_MAN]: '833',
|
||||
[CountryIso.INDIA]: '356',
|
||||
[CountryIso.BRITISH_INDIAN_OCEAN_TERRITORY]: '086',
|
||||
[CountryIso.IRELAND]: '372',
|
||||
[CountryIso.IRAN_ISLAMIC_REPUBLIC_OF]: '364',
|
||||
[CountryIso.IRAQ]: '368',
|
||||
[CountryIso.ICELAND]: '352',
|
||||
[CountryIso.ISRAEL]: '376',
|
||||
[CountryIso.ITALY]: '380',
|
||||
[CountryIso.JAMAICA]: '388',
|
||||
[CountryIso.JERSEY]: '832',
|
||||
[CountryIso.JORDAN]: '400',
|
||||
[CountryIso.JAPAN]: '392',
|
||||
[CountryIso.KAZAKHSTAN]: '398',
|
||||
[CountryIso.KENYA]: '404',
|
||||
[CountryIso.KYRGYZSTAN]: '417',
|
||||
[CountryIso.CAMBODIA]: '116',
|
||||
[CountryIso.KIRIBATI]: '296',
|
||||
[CountryIso.SAINT_KITTS_AND_NEVIS]: '659',
|
||||
[CountryIso.KOREA_REPUBLIC_OF]: '410',
|
||||
[CountryIso.KUWAIT]: '414',
|
||||
[CountryIso.LAO_PEOPLES_DEMOCRATIC_REPUBLIC]: '418',
|
||||
[CountryIso.LEBANON]: '422',
|
||||
[CountryIso.LIBERIA]: '430',
|
||||
[CountryIso.LIBYA]: '434',
|
||||
[CountryIso.SAINT_LUCIA]: '662',
|
||||
[CountryIso.LIECHTENSTEIN]: '438',
|
||||
[CountryIso.SRI_LANKA]: '144',
|
||||
[CountryIso.LESOTHO]: '426',
|
||||
[CountryIso.LITHUANIA]: '440',
|
||||
[CountryIso.LUXEMBOURG]: '442',
|
||||
[CountryIso.LATVIA]: '428',
|
||||
[CountryIso.MACAO]: '446',
|
||||
[CountryIso.SAINT_MARTIN_FRENCH_PART]: '663',
|
||||
[CountryIso.MOROCCO]: '504',
|
||||
[CountryIso.MONACO]: '492',
|
||||
[CountryIso.MOLDOVA_REPUBLIC_OF]: '498',
|
||||
[CountryIso.MADAGASCAR]: '450',
|
||||
[CountryIso.MALDIVES]: '462',
|
||||
[CountryIso.MEXICO]: '484',
|
||||
[CountryIso.MARSHALL_ISLANDS]: '584',
|
||||
[CountryIso.NORTH_MACEDONIA]: '807',
|
||||
[CountryIso.MALI]: '466',
|
||||
[CountryIso.MALTA]: '470',
|
||||
[CountryIso.MYANMAR]: '104',
|
||||
[CountryIso.MONTENEGRO]: '499',
|
||||
[CountryIso.MONGOLIA]: '496',
|
||||
[CountryIso.NORTHERN_MARIANA_ISLANDS]: '580',
|
||||
[CountryIso.MOZAMBIQUE]: '508',
|
||||
[CountryIso.MAURITANIA]: '478',
|
||||
[CountryIso.MONTSERRAT]: '500',
|
||||
[CountryIso.MARTINIQUE]: '474',
|
||||
[CountryIso.MAURITIUS]: '480',
|
||||
[CountryIso.MALAWI]: '454',
|
||||
[CountryIso.MALAYSIA]: '458',
|
||||
[CountryIso.MAYOTTE]: '175',
|
||||
[CountryIso.NAMIBIA]: '516',
|
||||
[CountryIso.NEW_CALEDONIA]: '540',
|
||||
[CountryIso.NIGER]: '562',
|
||||
[CountryIso.NORFOLK_ISLAND]: '574',
|
||||
[CountryIso.NIGERIA]: '566',
|
||||
[CountryIso.NICARAGUA]: '558',
|
||||
[CountryIso.NIUE]: '570',
|
||||
[CountryIso.NETHERLANDS]: '528',
|
||||
[CountryIso.NORWAY]: '578',
|
||||
[CountryIso.NEPAL]: '524',
|
||||
[CountryIso.NAURU]: '520',
|
||||
[CountryIso.NEW_ZEALAND]: '554',
|
||||
[CountryIso.OMAN]: '512',
|
||||
[CountryIso.PAKISTAN]: '586',
|
||||
[CountryIso.PANAMA]: '591',
|
||||
[CountryIso.PITCAIRN]: '612',
|
||||
[CountryIso.PERU]: '604',
|
||||
[CountryIso.PHILIPPINES]: '608',
|
||||
[CountryIso.PALAU]: '585',
|
||||
[CountryIso.PAPUA_NEW_GUINEA]: '598',
|
||||
[CountryIso.POLAND]: '616',
|
||||
[CountryIso.PUERTO_RICO]: '630',
|
||||
[CountryIso.KOREA_DEMOCRATIC_PEOPLES_REPUBLIC_OF]: '408',
|
||||
[CountryIso.PORTUGAL]: '620',
|
||||
[CountryIso.PARAGUAY]: '600',
|
||||
[CountryIso.PALESTINE_STATE_OF]: '275',
|
||||
[CountryIso.FRENCH_POLYNESIA]: '258',
|
||||
[CountryIso.QATAR]: '634',
|
||||
[CountryIso.REUNION]: '638',
|
||||
[CountryIso.ROMANIA]: '642',
|
||||
[CountryIso.RUSSIAN_FEDERATION]: '643',
|
||||
[CountryIso.RWANDA]: '646',
|
||||
[CountryIso.SAUDI_ARABIA]: '682',
|
||||
[CountryIso.SUDAN]: '729',
|
||||
[CountryIso.SENEGAL]: '686',
|
||||
[CountryIso.SINGAPORE]: '702',
|
||||
[CountryIso.SOUTH_GEORGIA_AND_THE_SOUTH_SANDWICH_ISLANDS]: '239',
|
||||
[CountryIso.SAINT_HELENA_ASCENSION_AND_TRISTAN_DA_CUNHA]: '654',
|
||||
[CountryIso.SVALBARD_AND_JAN_MAYEN]: '744',
|
||||
[CountryIso.SOLOMON_ISLANDS]: '090',
|
||||
[CountryIso.SIERRA_LEONE]: '694',
|
||||
[CountryIso.EL_SALVADOR]: '222',
|
||||
[CountryIso.SAN_MARINO]: '674',
|
||||
[CountryIso.SOMALIA]: '706',
|
||||
[CountryIso.SAINT_PIERRE_AND_MIQUELON]: '666',
|
||||
[CountryIso.SERBIA]: '688',
|
||||
[CountryIso.SOUTH_SUDAN]: '728',
|
||||
[CountryIso.SAO_TOME_AND_PRINCIPE]: '678',
|
||||
[CountryIso.SURINAME]: '740',
|
||||
[CountryIso.SLOVAKIA]: '703',
|
||||
[CountryIso.SLOVENIA]: '705',
|
||||
[CountryIso.SWEDEN]: '752',
|
||||
[CountryIso.ESWATINI]: '748',
|
||||
[CountryIso.SINT_MAARTEN_DUTCH_PART]: '534',
|
||||
[CountryIso.SEYCHELLES]: '690',
|
||||
[CountryIso.SYRIAN_ARAB_REPUBLIC]: '760',
|
||||
[CountryIso.TURKS_AND_CAICOS_ISLANDS]: '796',
|
||||
[CountryIso.CHAD]: '148',
|
||||
[CountryIso.TOGO]: '768',
|
||||
[CountryIso.THAILAND]: '764',
|
||||
[CountryIso.TAJIKISTAN]: '762',
|
||||
[CountryIso.TOKELAU]: '772',
|
||||
[CountryIso.TURKMENISTAN]: '795',
|
||||
[CountryIso.TIMOR_LESTE]: '626',
|
||||
[CountryIso.TONGA]: '776',
|
||||
[CountryIso.TRINIDAD_AND_TOBAGO]: '780',
|
||||
[CountryIso.TUNISIA]: '788',
|
||||
[CountryIso.TURKEY]: '792',
|
||||
[CountryIso.TUVALU]: '798',
|
||||
[CountryIso.TAIWAN_PROVINCE_OF_CHINA]: '158',
|
||||
[CountryIso.TANZANIA_UNITED_REPUBLIC_OF]: '834',
|
||||
[CountryIso.UGANDA]: '800',
|
||||
[CountryIso.UKRAINE]: '804',
|
||||
[CountryIso.UNITED_STATES_MINOR_OUTLYING_ISLANDS]: '581',
|
||||
[CountryIso.URUGUAY]: '858',
|
||||
[CountryIso.UNITED_STATES]: '840',
|
||||
[CountryIso.UZBEKISTAN]: '860',
|
||||
[CountryIso.HOLY_SEE_VATICAN_CITY_STATE]: '336',
|
||||
[CountryIso.SAINT_VINCENT_AND_THE_GRENADINES]: '670',
|
||||
[CountryIso.VENEZUELA_BOLIVARIAN_REPUBLIC_OF]: '862',
|
||||
[CountryIso.VIRGIN_ISLANDS_BRITISH]: '092',
|
||||
[CountryIso.VIRGIN_ISLANDS_US]: '850',
|
||||
[CountryIso.VIET_NAM]: '704',
|
||||
[CountryIso.VANUATU]: '548',
|
||||
[CountryIso.WALLIS_AND_FUTUNA]: '876',
|
||||
[CountryIso.SAMOA]: '882',
|
||||
[CountryIso.YEMEN]: '887',
|
||||
[CountryIso.SOUTH_AFRICA]: '710',
|
||||
[CountryIso.ZAMBIA]: '894',
|
||||
[CountryIso.ZIMBABWE]: '716',
|
||||
};
|
1
src/common/constants/global.constant.ts
Normal file
1
src/common/constants/global.constant.ts
Normal file
@ -0,0 +1 @@
|
||||
export const DEVICE_ID_HEADER = 'x-client-id';
|
2
src/common/constants/index.ts
Normal file
2
src/common/constants/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './countries-numeric-iso.constant';
|
||||
export * from './global.constant';
|
5
src/common/decorators/allowed-roles.decorator.ts
Normal file
5
src/common/decorators/allowed-roles.decorator.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { SetMetadata } from '@nestjs/common';
|
||||
import { Roles } from '~/auth/enums';
|
||||
|
||||
export const ROLE_METADATA_KEY = 'roles';
|
||||
export const AllowedRoles = (...roles: Roles[]) => SetMetadata(ROLE_METADATA_KEY, roles);
|
3
src/common/decorators/index.ts
Normal file
3
src/common/decorators/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export * from './allowed-roles.decorator';
|
||||
export * from './public.decorator';
|
||||
export * from './user.decorator';
|
4
src/common/decorators/public.decorator.ts
Normal file
4
src/common/decorators/public.decorator.ts
Normal file
@ -0,0 +1,4 @@
|
||||
import { SetMetadata } from '@nestjs/common';
|
||||
|
||||
export const IS_PUBLIC_KEY = 'isPublic';
|
||||
export const Public = () => SetMetadata(IS_PUBLIC_KEY, true);
|
6
src/common/decorators/user.decorator.ts
Normal file
6
src/common/decorators/user.decorator.ts
Normal file
@ -0,0 +1,6 @@
|
||||
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
|
||||
|
||||
export const AuthenticatedUser = createParamDecorator((data: unknown, ctx: ExecutionContext) => {
|
||||
const req = ctx.switchToHttp().getRequest();
|
||||
return req.user;
|
||||
});
|
251
src/common/enums/countries-iso.enum.ts
Normal file
251
src/common/enums/countries-iso.enum.ts
Normal file
@ -0,0 +1,251 @@
|
||||
export enum CountryIso {
|
||||
ARUBA = 'AW',
|
||||
AFGHANISTAN = 'AF',
|
||||
ANGOLA = 'AO',
|
||||
ANGUILLA = 'AI',
|
||||
ALAND_ISLANDS = 'AX',
|
||||
ALBANIA = 'AL',
|
||||
ANDORRA = 'AD',
|
||||
UNITED_ARAB_EMIRATES = 'AE',
|
||||
ARGENTINA = 'AR',
|
||||
ARMENIA = 'AM',
|
||||
AMERICAN_SAMOA = 'AS',
|
||||
ANTARCTICA = 'AQ',
|
||||
FRENCH_SOUTHERN_TERRITORIES = 'TF',
|
||||
ANTIGUA_AND_BARBUDA = 'AG',
|
||||
AUSTRALIA = 'AU',
|
||||
AUSTRIA = 'AT',
|
||||
AZERBAIJAN = 'AZ',
|
||||
BURUNDI = 'BI',
|
||||
BELGIUM = 'BE',
|
||||
BENIN = 'BJ',
|
||||
BONAIRE_SINT_EUSTATIUS_AND_SABA = 'BQ',
|
||||
BURKINA_FASO = 'BF',
|
||||
BANGLADESH = 'BD',
|
||||
BULGARIA = 'BG',
|
||||
BAHRAIN = 'BH',
|
||||
BAHAMAS = 'BS',
|
||||
BOSNIA_AND_HERZEGOVINA = 'BA',
|
||||
SAINT_BARTHÉLEMY = 'BL',
|
||||
BELARUS = 'BY',
|
||||
BELIZE = 'BZ',
|
||||
BERMUDA = 'BM',
|
||||
BOLIVIA_PLURINATIONAL_STATE_OF = 'BO',
|
||||
BRAZIL = 'BR',
|
||||
BARBADOS = 'BB',
|
||||
BRUNEI_DARUSSALAM = 'BN',
|
||||
BHUTAN = 'BT',
|
||||
BOUVET_ISLAND = 'BV',
|
||||
BOTSWANA = 'BW',
|
||||
CENTRAL_AFRICAN_REPUBLIC = 'CF',
|
||||
CANADA = 'CA',
|
||||
COCOS_KEELING_ISLANDS = 'CC',
|
||||
SWITZERLAND = 'CH',
|
||||
CHILE = 'CL',
|
||||
CHINA = 'CN',
|
||||
COTE_DIVOIRE = 'CI',
|
||||
CAMEROON = 'CM',
|
||||
CONGO_THE_DEMOCRATIC_REPUBLIC_OF_THE = 'CD',
|
||||
CONGO = 'CG',
|
||||
COOK_ISLANDS = 'CK',
|
||||
COLOMBIA = 'CO',
|
||||
COMOROS = 'KM',
|
||||
CABO_VERDE = 'CV',
|
||||
COSTA_RICA = 'CR',
|
||||
CUBA = 'CU',
|
||||
CURAÇAO = 'CW',
|
||||
CHRISTMAS_ISLAND = 'CX',
|
||||
CAYMAN_ISLANDS = 'KY',
|
||||
CYPRUS = 'CY',
|
||||
CZECHIA = 'CZ',
|
||||
GERMANY = 'DE',
|
||||
DJIBOUTI = 'DJ',
|
||||
DOMINICA = 'DM',
|
||||
DENMARK = 'DK',
|
||||
DOMINICAN_REPUBLIC = 'DO',
|
||||
ALGERIA = 'DZ',
|
||||
ECUADOR = 'EC',
|
||||
EGYPT = 'EG',
|
||||
ERITREA = 'ER',
|
||||
WESTERN_SAHARA = 'EH',
|
||||
SPAIN = 'ES',
|
||||
ESTONIA = 'EE',
|
||||
ETHIOPIA = 'ET',
|
||||
FINLAND = 'FI',
|
||||
FIJI = 'FJ',
|
||||
FALKLAND_ISLANDS_MALVINAS = 'FK',
|
||||
FRANCE = 'FR',
|
||||
FAROE_ISLANDS = 'FO',
|
||||
MICRONESIA_FEDERATED_STATES_OF = 'FM',
|
||||
GABON = 'GA',
|
||||
UNITED_KINGDOM = 'GB',
|
||||
GEORGIA = 'GE',
|
||||
GUERNSEY = 'GG',
|
||||
GHANA = 'GH',
|
||||
GIBRALTAR = 'GI',
|
||||
GUINEA = 'GN',
|
||||
GUADELOUPE = 'GP',
|
||||
GAMBIA = 'GM',
|
||||
GUINEA_BISSAU = 'GW',
|
||||
EQUATORIAL_GUINEA = 'GQ',
|
||||
GREECE = 'GR',
|
||||
GRENADA = 'GD',
|
||||
GREENLAND = 'GL',
|
||||
GUATEMALA = 'GT',
|
||||
FRENCH_GUIANA = 'GF',
|
||||
GUAM = 'GU',
|
||||
GUYANA = 'GY',
|
||||
HONG_KONG = 'HK',
|
||||
HEARD_ISLAND_AND_MCDONALD_ISLANDS = 'HM',
|
||||
HONDURAS = 'HN',
|
||||
CROATIA = 'HR',
|
||||
HAITI = 'HT',
|
||||
HUNGARY = 'HU',
|
||||
INDONESIA = 'ID',
|
||||
ISLE_OF_MAN = 'IM',
|
||||
INDIA = 'IN',
|
||||
BRITISH_INDIAN_OCEAN_TERRITORY = 'IO',
|
||||
IRELAND = 'IE',
|
||||
IRAN_ISLAMIC_REPUBLIC_OF = 'IR',
|
||||
IRAQ = 'IQ',
|
||||
ICELAND = 'IS',
|
||||
ISRAEL = 'IL',
|
||||
ITALY = 'IT',
|
||||
JAMAICA = 'JM',
|
||||
JERSEY = 'JE',
|
||||
JORDAN = 'JO',
|
||||
JAPAN = 'JP',
|
||||
KAZAKHSTAN = 'KZ',
|
||||
KENYA = 'KE',
|
||||
KYRGYZSTAN = 'KG',
|
||||
CAMBODIA = 'KH',
|
||||
KIRIBATI = 'KI',
|
||||
SAINT_KITTS_AND_NEVIS = 'KN',
|
||||
KOREA_REPUBLIC_OF = 'KR',
|
||||
KUWAIT = 'KW',
|
||||
LAO_PEOPLES_DEMOCRATIC_REPUBLIC = 'LA',
|
||||
LEBANON = 'LB',
|
||||
LIBERIA = 'LR',
|
||||
LIBYA = 'LY',
|
||||
SAINT_LUCIA = 'LC',
|
||||
LIECHTENSTEIN = 'LI',
|
||||
SRI_LANKA = 'LK',
|
||||
LESOTHO = 'LS',
|
||||
LITHUANIA = 'LT',
|
||||
LUXEMBOURG = 'LU',
|
||||
LATVIA = 'LV',
|
||||
MACAO = 'MO',
|
||||
SAINT_MARTIN_FRENCH_PART = 'MF',
|
||||
MOROCCO = 'MA',
|
||||
MONACO = 'MC',
|
||||
MOLDOVA_REPUBLIC_OF = 'MD',
|
||||
MADAGASCAR = 'MG',
|
||||
MALDIVES = 'MV',
|
||||
MEXICO = 'MX',
|
||||
MARSHALL_ISLANDS = 'MH',
|
||||
NORTH_MACEDONIA = 'MK',
|
||||
MALI = 'ML',
|
||||
MALTA = 'MT',
|
||||
MYANMAR = 'MM',
|
||||
MONTENEGRO = 'ME',
|
||||
MONGOLIA = 'MN',
|
||||
NORTHERN_MARIANA_ISLANDS = 'MP',
|
||||
MOZAMBIQUE = 'MZ',
|
||||
MAURITANIA = 'MR',
|
||||
MONTSERRAT = 'MS',
|
||||
MARTINIQUE = 'MQ',
|
||||
MAURITIUS = 'MU',
|
||||
MALAWI = 'MW',
|
||||
MALAYSIA = 'MY',
|
||||
MAYOTTE = 'YT',
|
||||
NAMIBIA = 'NA',
|
||||
NEW_CALEDONIA = 'NC',
|
||||
NIGER = 'NE',
|
||||
NORFOLK_ISLAND = 'NF',
|
||||
NIGERIA = 'NG',
|
||||
NICARAGUA = 'NI',
|
||||
NIUE = 'NU',
|
||||
NETHERLANDS = 'NL',
|
||||
NORWAY = 'NO',
|
||||
NEPAL = 'NP',
|
||||
NAURU = 'NR',
|
||||
NEW_ZEALAND = 'NZ',
|
||||
OMAN = 'OM',
|
||||
PAKISTAN = 'PK',
|
||||
PANAMA = 'PA',
|
||||
PITCAIRN = 'PN',
|
||||
PERU = 'PE',
|
||||
PHILIPPINES = 'PH',
|
||||
PALAU = 'PW',
|
||||
PAPUA_NEW_GUINEA = 'PG',
|
||||
POLAND = 'PL',
|
||||
PUERTO_RICO = 'PR',
|
||||
KOREA_DEMOCRATIC_PEOPLES_REPUBLIC_OF = 'KP',
|
||||
PORTUGAL = 'PT',
|
||||
PARAGUAY = 'PY',
|
||||
PALESTINE_STATE_OF = 'PS',
|
||||
FRENCH_POLYNESIA = 'PF',
|
||||
QATAR = 'QA',
|
||||
REUNION = 'RE',
|
||||
ROMANIA = 'RO',
|
||||
RUSSIAN_FEDERATION = 'RU',
|
||||
RWANDA = 'RW',
|
||||
SAUDI_ARABIA = 'SA',
|
||||
SUDAN = 'SD',
|
||||
SENEGAL = 'SN',
|
||||
SINGAPORE = 'SG',
|
||||
SOUTH_GEORGIA_AND_THE_SOUTH_SANDWICH_ISLANDS = 'GS',
|
||||
SAINT_HELENA_ASCENSION_AND_TRISTAN_DA_CUNHA = 'SH',
|
||||
SVALBARD_AND_JAN_MAYEN = 'SJ',
|
||||
SOLOMON_ISLANDS = 'SB',
|
||||
SIERRA_LEONE = 'SL',
|
||||
EL_SALVADOR = 'SV',
|
||||
SAN_MARINO = 'SM',
|
||||
SOMALIA = 'SO',
|
||||
SAINT_PIERRE_AND_MIQUELON = 'PM',
|
||||
SERBIA = 'RS',
|
||||
SOUTH_SUDAN = 'SS',
|
||||
SAO_TOME_AND_PRINCIPE = 'ST',
|
||||
SURINAME = 'SR',
|
||||
SLOVAKIA = 'SK',
|
||||
SLOVENIA = 'SI',
|
||||
SWEDEN = 'SE',
|
||||
ESWATINI = 'SZ',
|
||||
SINT_MAARTEN_DUTCH_PART = 'SX',
|
||||
SEYCHELLES = 'SC',
|
||||
SYRIAN_ARAB_REPUBLIC = 'SY',
|
||||
TURKS_AND_CAICOS_ISLANDS = 'TC',
|
||||
CHAD = 'TD',
|
||||
TOGO = 'TG',
|
||||
THAILAND = 'TH',
|
||||
TAJIKISTAN = 'TJ',
|
||||
TOKELAU = 'TK',
|
||||
TURKMENISTAN = 'TM',
|
||||
TIMOR_LESTE = 'TL',
|
||||
TONGA = 'TO',
|
||||
TRINIDAD_AND_TOBAGO = 'TT',
|
||||
TUNISIA = 'TN',
|
||||
TURKEY = 'TR',
|
||||
TUVALU = 'TV',
|
||||
TAIWAN_PROVINCE_OF_CHINA = 'TW',
|
||||
TANZANIA_UNITED_REPUBLIC_OF = 'TZ',
|
||||
UGANDA = 'UG',
|
||||
UKRAINE = 'UA',
|
||||
UNITED_STATES_MINOR_OUTLYING_ISLANDS = 'UM',
|
||||
URUGUAY = 'UY',
|
||||
UNITED_STATES = 'US',
|
||||
UZBEKISTAN = 'UZ',
|
||||
HOLY_SEE_VATICAN_CITY_STATE = 'VA',
|
||||
SAINT_VINCENT_AND_THE_GRENADINES = 'VC',
|
||||
VENEZUELA_BOLIVARIAN_REPUBLIC_OF = 'VE',
|
||||
VIRGIN_ISLANDS_BRITISH = 'VG',
|
||||
VIRGIN_ISLANDS_US = 'VI',
|
||||
VIET_NAM = 'VN',
|
||||
VANUATU = 'VU',
|
||||
WALLIS_AND_FUTUNA = 'WF',
|
||||
SAMOA = 'WS',
|
||||
YEMEN = 'YE',
|
||||
SOUTH_AFRICA = 'ZA',
|
||||
ZAMBIA = 'ZM',
|
||||
ZIMBABWE = 'ZW',
|
||||
}
|
1
src/common/enums/index.ts
Normal file
1
src/common/enums/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './countries-iso.enum';
|
34
src/common/guards/access-token.guard.ts
Normal file
34
src/common/guards/access-token.guard.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { ExecutionContext, Injectable, UnauthorizedException } from '@nestjs/common';
|
||||
import { Reflector } from '@nestjs/core';
|
||||
import { AuthGuard } from '@nestjs/passport';
|
||||
import { IS_PUBLIC_KEY } from '../decorators';
|
||||
import { CacheService } from '../modules/cache/services';
|
||||
|
||||
@Injectable()
|
||||
export class AccessTokenGuard extends AuthGuard('access-token') {
|
||||
constructor(protected reflector: Reflector, private readonly cacheService: CacheService) {
|
||||
super();
|
||||
}
|
||||
async canActivate(context: ExecutionContext) {
|
||||
const isPublic = this.reflector.getAllAndOverride<boolean>(IS_PUBLIC_KEY, [
|
||||
context.getHandler(),
|
||||
context.getClass(),
|
||||
]);
|
||||
|
||||
if (isPublic) {
|
||||
return true;
|
||||
}
|
||||
|
||||
await super.canActivate(context);
|
||||
|
||||
const token = context.switchToHttp().getRequest().headers['authorization']?.split(' ')[1];
|
||||
|
||||
const isRevoked = await this.cacheService.get(token);
|
||||
|
||||
if (isRevoked) {
|
||||
throw new UnauthorizedException();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
2
src/common/guards/index.ts
Normal file
2
src/common/guards/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './access-token.guard';
|
||||
export * from './roles-guard';
|
28
src/common/guards/roles-guard.ts
Normal file
28
src/common/guards/roles-guard.ts
Normal file
@ -0,0 +1,28 @@
|
||||
import { ExecutionContext, Injectable } from '@nestjs/common';
|
||||
import { Roles } from '~/auth/enums';
|
||||
import { ROLE_METADATA_KEY } from '../decorators';
|
||||
import { AccessTokenGuard } from './access-token.guard';
|
||||
|
||||
@Injectable()
|
||||
export class RolesGuard extends AccessTokenGuard {
|
||||
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||
await super.canActivate(context);
|
||||
|
||||
const request = context.switchToHttp().getRequest();
|
||||
const user = request.user;
|
||||
|
||||
if (!user) {
|
||||
return false;
|
||||
}
|
||||
const allowedRoles = this.reflector.getAllAndOverride<Roles[]>(ROLE_METADATA_KEY, [
|
||||
context.getHandler(),
|
||||
context.getClass(),
|
||||
]);
|
||||
|
||||
if (!allowedRoles) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return allowedRoles.some((role) => user.roles.includes(role));
|
||||
}
|
||||
}
|
1
src/common/mappers/index.ts
Normal file
1
src/common/mappers/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './numeric-to-iso.mapper';
|
11
src/common/mappers/numeric-to-iso.mapper.ts
Normal file
11
src/common/mappers/numeric-to-iso.mapper.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { CountriesNumericISO } from '../constants';
|
||||
import { CountryIso } from '../enums';
|
||||
|
||||
// At module top-level
|
||||
export const NumericToCountryIso: Record<string, CountryIso> = Object.entries(CountriesNumericISO).reduce(
|
||||
(acc, [isoKey, numeric]) => {
|
||||
acc[numeric] = isoKey as CountryIso;
|
||||
return acc;
|
||||
},
|
||||
{} as Record<string, CountryIso>,
|
||||
);
|
18
src/common/modules/cache/cache.module.ts
vendored
Normal file
18
src/common/modules/cache/cache.module.ts
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
import { Global, Module } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { buildKeyvOptions } from '~/core/module-options';
|
||||
import { CacheService } from './services';
|
||||
|
||||
@Module({
|
||||
providers: [
|
||||
{
|
||||
provide: 'CACHE_INSTANCE',
|
||||
useFactory: (config: ConfigService) => buildKeyvOptions(config),
|
||||
inject: [ConfigService],
|
||||
},
|
||||
CacheService,
|
||||
],
|
||||
exports: ['CACHE_INSTANCE', CacheService],
|
||||
})
|
||||
@Global()
|
||||
export class CacheModule {}
|
23
src/common/modules/cache/services/cache.services.ts
vendored
Normal file
23
src/common/modules/cache/services/cache.services.ts
vendored
Normal file
@ -0,0 +1,23 @@
|
||||
import { Inject, Injectable, Logger } from '@nestjs/common';
|
||||
import { Cacheable } from 'cacheable';
|
||||
|
||||
@Injectable()
|
||||
export class CacheService {
|
||||
private readonly logger = new Logger(CacheService.name);
|
||||
constructor(@Inject('CACHE_INSTANCE') private readonly cache: Cacheable) {}
|
||||
|
||||
get<T>(key: string): Promise<T | undefined> {
|
||||
this.logger.log(`Getting value for key ${key}`);
|
||||
return this.cache.get(key);
|
||||
}
|
||||
|
||||
async set<T>(key: string, value: T, ttl?: number | string): Promise<void> {
|
||||
this.logger.log(`Setting value for key ${key}`);
|
||||
await this.cache.set(key, value, ttl);
|
||||
}
|
||||
|
||||
async delete(key: string): Promise<void> {
|
||||
this.logger.log(`Deleting value for key ${key}`);
|
||||
await this.cache.delete(key);
|
||||
}
|
||||
}
|
1
src/common/modules/cache/services/index.ts
vendored
Normal file
1
src/common/modules/cache/services/index.ts
vendored
Normal file
@ -0,0 +1 @@
|
||||
export * from './cache.services';
|
1
src/common/modules/lookup/controllers/index.ts
Normal file
1
src/common/modules/lookup/controllers/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './lookup.controller';
|
32
src/common/modules/lookup/controllers/lookup.controller.ts
Normal file
32
src/common/modules/lookup/controllers/lookup.controller.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { Controller, Get, UseGuards } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { AccessTokenGuard } from '~/common/guards';
|
||||
import { ApiDataArrayResponse } from '~/core/decorators';
|
||||
import { ResponseFactory } from '~/core/utils';
|
||||
import { DocumentMetaResponseDto } from '~/document/dtos/response';
|
||||
import { LookupService } from '../services';
|
||||
|
||||
@Controller('lookup')
|
||||
@ApiTags('Lookups')
|
||||
@ApiBearerAuth()
|
||||
export class LookupController {
|
||||
constructor(private readonly lookupService: LookupService) {}
|
||||
|
||||
@UseGuards(AccessTokenGuard)
|
||||
@Get('default-avatars')
|
||||
@ApiDataArrayResponse(DocumentMetaResponseDto)
|
||||
async findDefaultAvatars() {
|
||||
const avatars = await this.lookupService.findDefaultAvatar();
|
||||
|
||||
return ResponseFactory.dataArray(avatars.map((avatar) => new DocumentMetaResponseDto(avatar)));
|
||||
}
|
||||
|
||||
@UseGuards(AccessTokenGuard)
|
||||
@Get('default-task-logos')
|
||||
@ApiDataArrayResponse(DocumentMetaResponseDto)
|
||||
async findDefaultTaskLogos() {
|
||||
const avatars = await this.lookupService.findDefaultTasksLogo();
|
||||
|
||||
return ResponseFactory.dataArray(avatars.map((avatar) => new DocumentMetaResponseDto(avatar)));
|
||||
}
|
||||
}
|
11
src/common/modules/lookup/lookup.module.ts
Normal file
11
src/common/modules/lookup/lookup.module.ts
Normal file
@ -0,0 +1,11 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { DocumentModule } from '~/document/document.module';
|
||||
import { LookupController } from './controllers';
|
||||
import { LookupService } from './services';
|
||||
|
||||
@Module({
|
||||
controllers: [LookupController],
|
||||
providers: [LookupService],
|
||||
imports: [DocumentModule],
|
||||
})
|
||||
export class LookupModule {}
|
1
src/common/modules/lookup/services/index.ts
Normal file
1
src/common/modules/lookup/services/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './lookup.service';
|
36
src/common/modules/lookup/services/lookup.service.ts
Normal file
36
src/common/modules/lookup/services/lookup.service.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { Injectable, Logger } from '@nestjs/common';
|
||||
import { DocumentType } from '~/document/enums';
|
||||
import { DocumentService, OciService } from '~/document/services';
|
||||
|
||||
@Injectable()
|
||||
export class LookupService {
|
||||
private readonly logger = new Logger(LookupService.name);
|
||||
constructor(private readonly documentService: DocumentService, private readonly ociService: OciService) {}
|
||||
async findDefaultAvatar() {
|
||||
this.logger.log(`Finding default avatar`);
|
||||
const documents = await this.documentService.findDocuments({ documentType: DocumentType.DEFAULT_AVATAR });
|
||||
await Promise.all(
|
||||
documents.map(async (document) => {
|
||||
document.url = await this.ociService.generatePreSignedUrl(document);
|
||||
}),
|
||||
);
|
||||
|
||||
this.logger.log(`Default avatar returned successfully`);
|
||||
|
||||
return documents;
|
||||
}
|
||||
|
||||
async findDefaultTasksLogo() {
|
||||
this.logger.log(`Finding default tasks logos`);
|
||||
const documents = await this.documentService.findDocuments({ documentType: DocumentType.DEFAULT_TASKS_LOGO });
|
||||
|
||||
await Promise.all(
|
||||
documents.map(async (document) => {
|
||||
document.url = await this.ociService.generatePreSignedUrl(document);
|
||||
}),
|
||||
);
|
||||
|
||||
this.logger.log(`Default tasks logos returned successfully`);
|
||||
return documents;
|
||||
}
|
||||
}
|
750
src/common/modules/neoleap/__mocks__/create-application.mock.ts
Normal file
750
src/common/modules/neoleap/__mocks__/create-application.mock.ts
Normal file
@ -0,0 +1,750 @@
|
||||
export const CREATE_APPLICATION_MOCK = {
|
||||
ResponseHeader: {
|
||||
Version: '1.0.0',
|
||||
MsgUid: 'adaa1893-9f95-48a8-b7a1-0422bcf629b5',
|
||||
Source: 'ZOD',
|
||||
ServiceId: 'CreateNewApplication',
|
||||
ReqDateTime: '2025-06-03T07:32:16.304Z',
|
||||
RspDateTime: '2025-06-03T08:21:15.662',
|
||||
ResponseCode: '000',
|
||||
ResponseType: 'Success',
|
||||
ProcessingTime: 1665,
|
||||
EncryptionKey: null,
|
||||
ResponseDescription: 'Operation Successful',
|
||||
LocalizedResponseDescription: null,
|
||||
CustomerSpecificResponseDescriptionList: null,
|
||||
HeaderUserDataList: null,
|
||||
},
|
||||
|
||||
CreateNewApplicationResponseDetails: {
|
||||
InstitutionCode: '1100',
|
||||
ApplicationTypeDetails: {
|
||||
TypeCode: '01',
|
||||
Description: 'Normal Primary',
|
||||
Additional: false,
|
||||
Corporate: false,
|
||||
UserData: null,
|
||||
},
|
||||
ApplicationDetails: {
|
||||
cif: null,
|
||||
ApplicationNumber: '3300000000073',
|
||||
ExternalApplicationNumber: '3',
|
||||
ApplicationStatus: '04',
|
||||
Organization: 0,
|
||||
Product: '1101',
|
||||
ApplicatonDate: '2025-05-29',
|
||||
ApplicationSource: 'O',
|
||||
SalesSource: null,
|
||||
DeliveryMethod: 'V',
|
||||
ProgramCode: null,
|
||||
Campaign: null,
|
||||
Plastic: null,
|
||||
Design: null,
|
||||
ProcessStage: '99',
|
||||
ProcessStageStatus: 'S',
|
||||
Score: null,
|
||||
ExternalScore: null,
|
||||
RequestedLimit: 0,
|
||||
SuggestedLimit: null,
|
||||
AssignedLimit: 0,
|
||||
AllowedLimitList: null,
|
||||
EligibilityCheckResult: '00',
|
||||
EligibilityCheckDescription: null,
|
||||
Title: 'Mr.',
|
||||
FirstName: 'Abdalhamid',
|
||||
SecondName: null,
|
||||
ThirdName: null,
|
||||
LastName: ' Ahmad',
|
||||
FullName: 'Abdalhamid Ahmad',
|
||||
EmbossName: 'ABDALHAMID AHMAD',
|
||||
PlaceOfBirth: null,
|
||||
DateOfBirth: '1999-01-07',
|
||||
LocalizedDateOfBirth: '1999-01-07',
|
||||
Age: 26,
|
||||
Gender: 'M',
|
||||
Married: 'U',
|
||||
Nationality: '682',
|
||||
IdType: '01',
|
||||
IdNumber: '1089055972',
|
||||
IdExpiryDate: '2031-09-17',
|
||||
EducationLevel: null,
|
||||
ProfessionCode: 0,
|
||||
NumberOfDependents: 0,
|
||||
EmployerName: 'N/A',
|
||||
EmploymentYears: 0,
|
||||
EmploymentMonths: 0,
|
||||
EmployerPhoneArea: null,
|
||||
EmployerPhoneNumber: null,
|
||||
EmployerPhoneExtension: null,
|
||||
EmployerMobile: null,
|
||||
EmployerFaxArea: null,
|
||||
EmployerFax: null,
|
||||
EmployerCity: null,
|
||||
EmployerAddress: null,
|
||||
EmploymentActivity: null,
|
||||
EmploymentStatus: null,
|
||||
CIF: null,
|
||||
BankAccountNumber: ' ',
|
||||
Currency: {
|
||||
CurrCode: '682',
|
||||
AlphaCode: 'SAR',
|
||||
},
|
||||
RequestedCurrencyList: null,
|
||||
CreditAccountNumber: '6000000000000000',
|
||||
AccountType: '30',
|
||||
OpenDate: null,
|
||||
Income: 0,
|
||||
AdditionalIncome: 0,
|
||||
TotalIncome: 0,
|
||||
CurrentBalance: 0,
|
||||
AverageBalance: 0,
|
||||
AssetsBalance: 0,
|
||||
InsuranceBalance: 0,
|
||||
DepositAmount: 0,
|
||||
GuarenteeAccountNumber: null,
|
||||
GuarenteeAmount: 0,
|
||||
InstalmentAmount: 0,
|
||||
AutoDebit: 'N',
|
||||
PaymentMethod: '2',
|
||||
BillingCycle: 'C1',
|
||||
OldIssueDate: null,
|
||||
OtherPaymentsDate: null,
|
||||
MaximumDelinquency: null,
|
||||
CreditBureauDecision: null,
|
||||
CreditBureauUserData: null,
|
||||
ECommerce: 'N',
|
||||
NumberOfCards: 0,
|
||||
OtherBank: null,
|
||||
OtherBankDescription: null,
|
||||
InsuranceProduct: null,
|
||||
SocialCode: '000',
|
||||
JobGrade: 0,
|
||||
Flags: [
|
||||
{
|
||||
Position: 1,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 2,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 3,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 4,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 5,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 6,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 7,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 8,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 9,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 10,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 11,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 12,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 13,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 14,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 15,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 16,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 17,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 18,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 19,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 20,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 21,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 22,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 23,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 24,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 25,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 26,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 27,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 28,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 29,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 30,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 31,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 32,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 33,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 34,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 35,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 36,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 37,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 38,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 39,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 40,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 41,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 42,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 43,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 44,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 45,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 46,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 47,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 48,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 49,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 50,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 51,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 52,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 53,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 54,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 55,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 56,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 57,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 58,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 59,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 60,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 61,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 62,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 63,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 64,
|
||||
Value: '0',
|
||||
},
|
||||
],
|
||||
CheckFlags: [
|
||||
{
|
||||
Position: 1,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 2,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 3,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 4,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 5,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 6,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 7,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 8,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 9,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 10,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 11,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 12,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 13,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 14,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 15,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 16,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 17,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 18,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 19,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 20,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 21,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 22,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 23,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 24,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 25,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 26,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 27,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 28,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 29,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 30,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 31,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 32,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 33,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 34,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 35,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 36,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 37,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 38,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 39,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 40,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 41,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 42,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 43,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 44,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 45,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 46,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 47,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 48,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 49,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 50,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 51,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 52,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 53,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 54,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 55,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 56,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 57,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 58,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 59,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 60,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 61,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 62,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 63,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 64,
|
||||
Value: '0',
|
||||
},
|
||||
],
|
||||
Maker: null,
|
||||
Checker: null,
|
||||
ReferredTo: null,
|
||||
ReferralReason: null,
|
||||
UserData1: null,
|
||||
UserData2: null,
|
||||
UserData3: null,
|
||||
UserData4: null,
|
||||
UserData5: null,
|
||||
AdditionalFields: [],
|
||||
},
|
||||
ApplicationStatusDetails: {
|
||||
StatusCode: '04',
|
||||
Description: 'Approved',
|
||||
Canceled: false,
|
||||
},
|
||||
CorporateDetails: null,
|
||||
CustomerDetails: {
|
||||
Id: 115158,
|
||||
CustomerCode: '100000024619',
|
||||
IdNumber: ' ',
|
||||
TypeId: 0,
|
||||
PreferredLanguage: 'EN',
|
||||
ExternalCustomerCode: null,
|
||||
Title: ' ',
|
||||
FirstName: ' ',
|
||||
LastName: ' ',
|
||||
DateOfBirth: null,
|
||||
UserData1: '2031-09-17',
|
||||
UserData2: '01',
|
||||
UserData3: null,
|
||||
UserData4: '682',
|
||||
CustomerSegment: null,
|
||||
Gender: 'U',
|
||||
Married: 'U',
|
||||
},
|
||||
AccountDetailsList: [
|
||||
{
|
||||
Id: 21017,
|
||||
InstitutionCode: '1100',
|
||||
AccountNumber: '6899999999999999',
|
||||
Currency: {
|
||||
CurrCode: '682',
|
||||
AlphaCode: 'SAR',
|
||||
},
|
||||
AccountTypeCode: '30',
|
||||
ClassId: '2',
|
||||
AccountStatus: '00',
|
||||
VipFlag: '0',
|
||||
BlockedAmount: 0,
|
||||
EquivalentBlockedAmount: null,
|
||||
UnclearCredit: 0,
|
||||
EquivalentUnclearCredit: null,
|
||||
AvailableBalance: 0,
|
||||
EquivalentAvailableBalance: null,
|
||||
AvailableBalanceToSpend: 0,
|
||||
CreditLimit: 0,
|
||||
RemainingCashLimit: null,
|
||||
UserData1: 'D36407C9AE4C28D2185',
|
||||
UserData2: null,
|
||||
UserData3: 'D36407C9AE4C28D2185',
|
||||
UserData4: null,
|
||||
UserData5: 'SA2380900000752991120011',
|
||||
},
|
||||
],
|
||||
CardDetailsList: [
|
||||
{
|
||||
pvv: null,
|
||||
ResponseCardIdentifier: {
|
||||
Id: 28595,
|
||||
Pan: 'DDDDDDDDDDDDDDDDDDD',
|
||||
MaskedPan: '999999_9999',
|
||||
VPan: '1100000000000000',
|
||||
Seqno: 0,
|
||||
},
|
||||
ExpiryDate: '2031-09-30',
|
||||
EffectiveDate: '2025-06-02',
|
||||
CardStatus: '30',
|
||||
OldPlasticExpiryDate: null,
|
||||
OldPlasticCardStatus: null,
|
||||
EmbossingName: 'ABDALHAMID AHMAD',
|
||||
Title: 'Mr.',
|
||||
FirstName: 'Abdalhamid',
|
||||
LastName: ' Ahmad',
|
||||
Additional: false,
|
||||
BatchNumber: 8849,
|
||||
ServiceCode: '226',
|
||||
Kinship: null,
|
||||
DateOfBirth: '1999-01-07',
|
||||
LastActivity: null,
|
||||
LastStatusChangeDate: '2025-06-03',
|
||||
ActivationDate: null,
|
||||
DateLastIssued: null,
|
||||
PVV: null,
|
||||
UserData: '4',
|
||||
UserData1: '3',
|
||||
UserData2: null,
|
||||
UserData3: null,
|
||||
UserData4: null,
|
||||
UserData5: null,
|
||||
Memo: null,
|
||||
CardAuthorizationParameters: null,
|
||||
L10NTitle: null,
|
||||
L10NFirstName: null,
|
||||
L10NLastName: null,
|
||||
PinStatus: '40',
|
||||
OldPinStatus: '0',
|
||||
CustomerIdNumber: '1089055972',
|
||||
Language: 0,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
3
src/common/modules/neoleap/__mocks__/index.ts
Normal file
3
src/common/modules/neoleap/__mocks__/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export * from './create-application.mock';
|
||||
export * from './initiate-kyc.mock';
|
||||
export * from './inquire-application.mock';
|
21
src/common/modules/neoleap/__mocks__/initiate-kyc.mock.ts
Normal file
21
src/common/modules/neoleap/__mocks__/initiate-kyc.mock.ts
Normal file
@ -0,0 +1,21 @@
|
||||
export const INITIATE_KYC_MOCK = {
|
||||
ResponseHeader: {
|
||||
Version: '1.0.0',
|
||||
MsgUid: 'f3a9d4b2-5c7a-4e2f-8121-9c4e5a6b7d8f',
|
||||
Source: 'ZOD',
|
||||
ServiceId: 'InitiateKyc',
|
||||
ReqDateTime: '2025-08-07T14:20:00.000Z',
|
||||
RspDateTime: '2025-08-07T14:20:00.123Z',
|
||||
ResponseCode: '000',
|
||||
ResponseType: 'Success',
|
||||
ProcessingTime: 123,
|
||||
ResponseDescription: 'KYC initiation successful',
|
||||
},
|
||||
InitiateKycResponseDetails: {
|
||||
InstitutionCode: '1100',
|
||||
TransId: '3136fd60-3f89-4d24-a92f-b9c63a53807f',
|
||||
RandomNumber: '38',
|
||||
Status: 'WAITING',
|
||||
ExpiryDateTime: '2025-08-07T14:30:00.000Z',
|
||||
},
|
||||
};
|
728
src/common/modules/neoleap/__mocks__/inquire-application.mock.ts
Normal file
728
src/common/modules/neoleap/__mocks__/inquire-application.mock.ts
Normal file
@ -0,0 +1,728 @@
|
||||
export const INQUIRE_APPLICATION_MOCK = {
|
||||
ResponseHeader: {
|
||||
Version: '1.0.0',
|
||||
MsgUid: 'adaa1893-9f95-48a8-b7a1-0422bcf629b4',
|
||||
Source: 'ZOD',
|
||||
ServiceId: 'InquireApplication',
|
||||
ReqDateTime: '2023-07-18T10:34:12.553Z',
|
||||
RspDateTime: '2025-06-03T11:14:54.748',
|
||||
ResponseCode: '000',
|
||||
ResponseType: 'Success',
|
||||
ProcessingTime: 476,
|
||||
EncryptionKey: null,
|
||||
ResponseDescription: 'Operation Successful',
|
||||
LocalizedResponseDescription: null,
|
||||
CustomerSpecificResponseDescriptionList: null,
|
||||
HeaderUserDataList: null,
|
||||
},
|
||||
InquireApplicationResponseDetails: {
|
||||
InstitutionCode: '1100',
|
||||
ApplicationTypeDetails: {
|
||||
TypeCode: '01',
|
||||
Description: 'Normal Primary',
|
||||
Additional: false,
|
||||
Corporate: false,
|
||||
UserData: null,
|
||||
},
|
||||
ApplicationDetails: {
|
||||
cif: null,
|
||||
ApplicationNumber: '3300000000070',
|
||||
ExternalApplicationNumber: '10000002',
|
||||
ApplicationStatus: '04',
|
||||
Organization: 0,
|
||||
Product: '1101',
|
||||
ApplicatonDate: '2025-05-29',
|
||||
ApplicationSource: 'O',
|
||||
SalesSource: null,
|
||||
DeliveryMethod: 'V',
|
||||
ProgramCode: null,
|
||||
Campaign: null,
|
||||
Plastic: null,
|
||||
Design: null,
|
||||
ProcessStage: '99',
|
||||
ProcessStageStatus: 'S',
|
||||
Score: null,
|
||||
ExternalScore: null,
|
||||
RequestedLimit: 0,
|
||||
SuggestedLimit: null,
|
||||
AssignedLimit: 0,
|
||||
AllowedLimitList: null,
|
||||
EligibilityCheckResult: '00',
|
||||
EligibilityCheckDescription: null,
|
||||
Title: 'Mr.',
|
||||
FirstName: 'Abdalhamid',
|
||||
SecondName: null,
|
||||
ThirdName: null,
|
||||
LastName: ' Ahmad',
|
||||
FullName: 'Abdalhamid Ahmad',
|
||||
EmbossName: 'ABDALHAMID AHMAD',
|
||||
PlaceOfBirth: null,
|
||||
DateOfBirth: '1999-01-07',
|
||||
LocalizedDateOfBirth: '1999-01-07',
|
||||
Age: 26,
|
||||
Gender: 'M',
|
||||
Married: 'U',
|
||||
Nationality: '682',
|
||||
IdType: '01',
|
||||
IdNumber: '1089055972',
|
||||
IdExpiryDate: '2031-09-17',
|
||||
EducationLevel: null,
|
||||
ProfessionCode: 0,
|
||||
NumberOfDependents: 0,
|
||||
EmployerName: 'N/A',
|
||||
EmploymentYears: 0,
|
||||
EmploymentMonths: 0,
|
||||
EmployerPhoneArea: null,
|
||||
EmployerPhoneNumber: null,
|
||||
EmployerPhoneExtension: null,
|
||||
EmployerMobile: null,
|
||||
EmployerFaxArea: null,
|
||||
EmployerFax: null,
|
||||
EmployerCity: null,
|
||||
EmployerAddress: null,
|
||||
EmploymentActivity: null,
|
||||
EmploymentStatus: null,
|
||||
CIF: null,
|
||||
BankAccountNumber: ' ',
|
||||
Currency: {
|
||||
CurrCode: '682',
|
||||
AlphaCode: 'SAR',
|
||||
},
|
||||
RequestedCurrencyList: null,
|
||||
CreditAccountNumber: '6823000000000019',
|
||||
AccountType: '30',
|
||||
OpenDate: null,
|
||||
Income: 0,
|
||||
AdditionalIncome: 0,
|
||||
TotalIncome: 0,
|
||||
CurrentBalance: 0,
|
||||
AverageBalance: 0,
|
||||
AssetsBalance: 0,
|
||||
InsuranceBalance: 0,
|
||||
DepositAmount: 0,
|
||||
GuarenteeAccountNumber: null,
|
||||
GuarenteeAmount: 0,
|
||||
InstalmentAmount: 0,
|
||||
AutoDebit: 'N',
|
||||
PaymentMethod: '2',
|
||||
BillingCycle: 'C1',
|
||||
OldIssueDate: null,
|
||||
OtherPaymentsDate: null,
|
||||
MaximumDelinquency: null,
|
||||
CreditBureauDecision: null,
|
||||
CreditBureauUserData: null,
|
||||
ECommerce: 'N',
|
||||
NumberOfCards: 0,
|
||||
OtherBank: null,
|
||||
OtherBankDescription: null,
|
||||
InsuranceProduct: null,
|
||||
SocialCode: '000',
|
||||
JobGrade: 0,
|
||||
Flags: [
|
||||
{
|
||||
Position: 1,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 2,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 3,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 4,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 5,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 6,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 7,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 8,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 9,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 10,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 11,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 12,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 13,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 14,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 15,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 16,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 17,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 18,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 19,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 20,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 21,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 22,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 23,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 24,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 25,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 26,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 27,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 28,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 29,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 30,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 31,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 32,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 33,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 34,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 35,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 36,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 37,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 38,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 39,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 40,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 41,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 42,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 43,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 44,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 45,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 46,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 47,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 48,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 49,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 50,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 51,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 52,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 53,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 54,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 55,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 56,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 57,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 58,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 59,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 60,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 61,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 62,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 63,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 64,
|
||||
Value: '0',
|
||||
},
|
||||
],
|
||||
CheckFlags: [
|
||||
{
|
||||
Position: 1,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 2,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 3,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 4,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 5,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 6,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 7,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 8,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 9,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 10,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 11,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 12,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 13,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 14,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 15,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 16,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 17,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 18,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 19,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 20,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 21,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 22,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 23,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 24,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 25,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 26,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 27,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 28,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 29,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 30,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 31,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 32,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 33,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 34,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 35,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 36,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 37,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 38,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 39,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 40,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 41,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 42,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 43,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 44,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 45,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 46,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 47,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 48,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 49,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 50,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 51,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 52,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 53,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 54,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 55,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 56,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 57,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 58,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 59,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 60,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 61,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 62,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 63,
|
||||
Value: '0',
|
||||
},
|
||||
{
|
||||
Position: 64,
|
||||
Value: '0',
|
||||
},
|
||||
],
|
||||
Maker: null,
|
||||
Checker: null,
|
||||
ReferredTo: null,
|
||||
ReferralReason: null,
|
||||
UserData1: null,
|
||||
UserData2: null,
|
||||
UserData3: null,
|
||||
UserData4: null,
|
||||
UserData5: null,
|
||||
AdditionalFields: [],
|
||||
},
|
||||
ApplicationStatusDetails: {
|
||||
StatusCode: '04',
|
||||
Description: 'Approved',
|
||||
Canceled: false,
|
||||
},
|
||||
ApplicationHistoryList: null,
|
||||
ApplicationAddressList: [
|
||||
{
|
||||
Id: 43859,
|
||||
AddressLine1: '5536 abdullah Ibn al zubair ',
|
||||
AddressLine2: ' Umm Alarad Dist.',
|
||||
AddressLine3: null,
|
||||
AddressLine4: null,
|
||||
AddressLine5: null,
|
||||
Directions: null,
|
||||
City: 'AT TAIF',
|
||||
PostalCode: null,
|
||||
Province: null,
|
||||
Territory: null,
|
||||
State: null,
|
||||
Region: null,
|
||||
County: null,
|
||||
Country: '682',
|
||||
CountryDetails: {
|
||||
IsoCode: '682',
|
||||
Alpha3: 'SAU',
|
||||
Alpha2: 'SA',
|
||||
DefaultCurrency: {
|
||||
CurrCode: '682',
|
||||
AlphaCode: 'SAR',
|
||||
},
|
||||
Description: [
|
||||
{
|
||||
Language: 'EN',
|
||||
Description: 'SAUDI ARABIA',
|
||||
},
|
||||
{
|
||||
Language: 'GB',
|
||||
Description: 'SAUDI ARABIA',
|
||||
},
|
||||
],
|
||||
},
|
||||
Phone1: '+966541884784',
|
||||
Phone2: null,
|
||||
Extension: null,
|
||||
Email: 'a.ahmad@zod-alkhair.com',
|
||||
Fax: null,
|
||||
District: null,
|
||||
PoBox: null,
|
||||
OwnershipType: 'O',
|
||||
UserData1: null,
|
||||
UserData2: null,
|
||||
AddressRole: 0,
|
||||
AddressCustomValues: null,
|
||||
},
|
||||
],
|
||||
CorporateDetails: null,
|
||||
CustomerDetails: {
|
||||
Id: 115129,
|
||||
CustomerCode: '100000024552',
|
||||
IdNumber: ' ',
|
||||
TypeId: 0,
|
||||
PreferredLanguage: 'EN',
|
||||
ExternalCustomerCode: null,
|
||||
Title: ' ',
|
||||
FirstName: ' ',
|
||||
LastName: ' ',
|
||||
DateOfBirth: null,
|
||||
UserData1: '2031-09-17',
|
||||
UserData2: '01',
|
||||
UserData3: null,
|
||||
UserData4: '682',
|
||||
CustomerSegment: null,
|
||||
Gender: 'U',
|
||||
Married: 'U',
|
||||
},
|
||||
|
||||
BranchDetails: null,
|
||||
CardAccountLinkageList: null,
|
||||
},
|
||||
};
|
23
src/common/modules/neoleap/__mocks__/kyc-callback.mock.ts
Normal file
23
src/common/modules/neoleap/__mocks__/kyc-callback.mock.ts
Normal file
@ -0,0 +1,23 @@
|
||||
export const getKycCallbackMock = (nationalId: string) => {
|
||||
return {
|
||||
InstId: '1100',
|
||||
transId: '3136fd60-3f89-4d24-a92f-b9c63a53807f',
|
||||
date: '20250807',
|
||||
time: '150000',
|
||||
status: 'SUCCESS',
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
dob: '19990107',
|
||||
nationality: '682',
|
||||
gender: 'M',
|
||||
nationalIdExpiry: '20310917',
|
||||
nationalId,
|
||||
mobile: '+962798765432',
|
||||
salaryMin: '500',
|
||||
salaryMax: '1000',
|
||||
incomeSource: 'Salary',
|
||||
professionTitle: 'Software Engineer',
|
||||
professionType: 'Full-Time',
|
||||
isPep: 'N',
|
||||
};
|
||||
};
|
@ -0,0 +1,40 @@
|
||||
import { Body, Controller, Post } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { ResponseFactory } from '~/core/utils';
|
||||
import {
|
||||
AccountCardStatusChangedWebhookRequest,
|
||||
AccountTransactionWebhookRequest,
|
||||
CardTransactionWebhookRequest,
|
||||
KycWebhookRequest,
|
||||
} from '../dtos/requests';
|
||||
import { NeoLeapWebhookService } from '../services';
|
||||
|
||||
@Controller('neoleap-webhooks')
|
||||
@ApiTags('Neoleap Webhooks')
|
||||
export class NeoLeapWebhooksController {
|
||||
constructor(private readonly neoleapWebhookService: NeoLeapWebhookService) {}
|
||||
|
||||
@Post('card-transaction')
|
||||
async handleCardTransactionWebhook(@Body() body: CardTransactionWebhookRequest) {
|
||||
await this.neoleapWebhookService.handleCardTransactionWebhook(body);
|
||||
return ResponseFactory.data({ message: 'Card transaction processed successfully', status: 'success' });
|
||||
}
|
||||
|
||||
@Post('account-transaction')
|
||||
async handleAccountTransactionWebhook(@Body() body: AccountTransactionWebhookRequest) {
|
||||
await this.neoleapWebhookService.handleAccountTransactionWebhook(body);
|
||||
return ResponseFactory.data({ message: 'Account transaction processed successfully', status: 'success' });
|
||||
}
|
||||
|
||||
@Post('account-card-status-changed')
|
||||
async handleAccountCardStatusChangedWebhook(@Body() body: AccountCardStatusChangedWebhookRequest) {
|
||||
await this.neoleapWebhookService.handleAccountCardStatusChangedWebhook(body);
|
||||
return ResponseFactory.data({ message: 'Card status updated successfully', status: 'success' });
|
||||
}
|
||||
|
||||
@Post('kyc')
|
||||
async handleKycWebhook(@Body() body: KycWebhookRequest) {
|
||||
await this.neoleapWebhookService.handleKycWebhook(body);
|
||||
return ResponseFactory.data({ message: 'KYC processed successfully', status: 'success' });
|
||||
}
|
||||
}
|
62
src/common/modules/neoleap/controllers/neotest.controller.ts
Normal file
62
src/common/modules/neoleap/controllers/neotest.controller.ts
Normal file
@ -0,0 +1,62 @@
|
||||
import { Body, Controller, Post, UseGuards } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { IJwtPayload } from '~/auth/interfaces';
|
||||
import { CardService } from '~/card/services';
|
||||
import { AuthenticatedUser } from '~/common/decorators';
|
||||
import { AccessTokenGuard } from '~/common/guards';
|
||||
import { ApiDataResponse } from '~/core/decorators';
|
||||
import { ResponseFactory } from '~/core/utils';
|
||||
import { CustomerResponseDto } from '~/customer/dtos/response';
|
||||
import { CustomerService } from '~/customer/services';
|
||||
import { UpdateCardControlsRequestDto } from '../dtos/requests';
|
||||
import { CreateApplicationResponse, InquireApplicationResponse } from '../dtos/response';
|
||||
import { NeoLeapService } from '../services/neoleap.service';
|
||||
|
||||
@Controller('neotest')
|
||||
@ApiTags('Neoleap Test API , for testing purposes only, will be removed in production')
|
||||
@UseGuards(AccessTokenGuard)
|
||||
@ApiBearerAuth()
|
||||
export class NeoTestController {
|
||||
constructor(
|
||||
private readonly neoleapService: NeoLeapService,
|
||||
private readonly customerService: CustomerService,
|
||||
private readonly cardService: CardService,
|
||||
private readonly configService: ConfigService,
|
||||
) {}
|
||||
|
||||
@Post('update-kys')
|
||||
@ApiDataResponse(CustomerResponseDto)
|
||||
async updateKys(@AuthenticatedUser() user: IJwtPayload) {
|
||||
const customer = await this.customerService.updateKyc(user.sub);
|
||||
|
||||
return ResponseFactory.data(new CustomerResponseDto(customer));
|
||||
}
|
||||
|
||||
@Post('inquire-application')
|
||||
@ApiDataResponse(InquireApplicationResponse)
|
||||
async inquireApplication(@AuthenticatedUser() user: IJwtPayload) {
|
||||
const customer = await this.customerService.findCustomerById(user.sub);
|
||||
const data = await this.neoleapService.inquireApplication(customer.applicationNumber.toString());
|
||||
return ResponseFactory.data(data);
|
||||
}
|
||||
|
||||
@Post('create-application')
|
||||
@ApiDataResponse(CreateApplicationResponse)
|
||||
async createApplication(@AuthenticatedUser() user: IJwtPayload) {
|
||||
const customer = await this.customerService.findCustomerById(user.sub);
|
||||
const data = await this.neoleapService.createApplication(customer);
|
||||
await this.cardService.createCard(customer.id, data);
|
||||
return ResponseFactory.data(data);
|
||||
}
|
||||
|
||||
@Post('update-card-controls')
|
||||
async updateCardControls(
|
||||
@AuthenticatedUser() user: IJwtPayload,
|
||||
@Body() { amount, count }: UpdateCardControlsRequestDto,
|
||||
) {
|
||||
const card = await this.cardService.getActiveCardForCustomer(user.sub);
|
||||
await this.neoleapService.updateCardControl(card.cardReference, amount, count);
|
||||
return ResponseFactory.data({ message: 'Card controls updated successfully' });
|
||||
}
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Expose } from 'class-transformer';
|
||||
import { IsString } from 'class-validator';
|
||||
|
||||
export class AccountCardStatusChangedWebhookRequest {
|
||||
@ApiProperty()
|
||||
@Expose({ name: 'InstId' })
|
||||
@IsString()
|
||||
instId!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@Expose({ name: 'cardId' })
|
||||
@IsString()
|
||||
cardId!: string;
|
||||
|
||||
@ApiProperty()
|
||||
@Expose({ name: 'newStatus' })
|
||||
@IsString()
|
||||
newStatus!: string;
|
||||
}
|
@ -0,0 +1,68 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Expose, Type } from 'class-transformer';
|
||||
import { IsNumber, IsPositive, IsString } from 'class-validator';
|
||||
|
||||
export class AccountTransactionWebhookRequest {
|
||||
@Expose({ name: 'InstId' })
|
||||
@IsString()
|
||||
@ApiProperty({ name: 'InstId', example: '9000' })
|
||||
instId!: string;
|
||||
|
||||
@Expose()
|
||||
@IsString()
|
||||
@ApiProperty({ example: '143761' })
|
||||
transactionId!: string;
|
||||
|
||||
@Expose()
|
||||
@IsString()
|
||||
@ApiProperty({ example: '0037' })
|
||||
transactionType!: string;
|
||||
|
||||
@Expose()
|
||||
@IsString()
|
||||
@ApiProperty({ example: '26' })
|
||||
transactionCode!: string;
|
||||
|
||||
@Expose()
|
||||
@IsString()
|
||||
@ApiProperty({ example: '6823000000000018' })
|
||||
accountNumber!: string;
|
||||
|
||||
@Expose()
|
||||
@IsString()
|
||||
@ApiProperty({ example: '6823000000000018' })
|
||||
accountId!: string;
|
||||
|
||||
@Expose()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
@ApiProperty({ example: '7080.15' })
|
||||
otb!: number;
|
||||
|
||||
@Expose()
|
||||
@Type(() => Number)
|
||||
@IsNumber()
|
||||
@IsPositive()
|
||||
@ApiProperty({ example: '3050.95' })
|
||||
amount!: number;
|
||||
|
||||
@Expose()
|
||||
@IsString()
|
||||
@ApiProperty({ example: 'C' })
|
||||
sign!: string;
|
||||
|
||||
@Expose()
|
||||
@IsString()
|
||||
@ApiProperty({ example: '682' })
|
||||
currency!: string;
|
||||
|
||||
@Expose()
|
||||
@IsString()
|
||||
@ApiProperty({ name: 'Date', example: '20241112' })
|
||||
date!: string;
|
||||
|
||||
@Expose()
|
||||
@IsString()
|
||||
@ApiProperty({ name: 'Time', example: '125340' })
|
||||
time!: string;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user