mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-08-26 06:09:41 +00:00
feat: handle card status changed webhook
This commit is contained in:
@ -1,20 +1,29 @@
|
||||
import { Body, Controller, Post } from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { TransactionService } from '~/card/services/transaction.service';
|
||||
import { AccountTransactionWebhookRequest, CardTransactionWebhookRequest } from '../dtos/requests';
|
||||
import {
|
||||
AccountCardStatusChangedWebhookRequest,
|
||||
AccountTransactionWebhookRequest,
|
||||
CardTransactionWebhookRequest,
|
||||
} from '../dtos/requests';
|
||||
import { NeoLeapWebhookService } from '../services';
|
||||
|
||||
@Controller('neoleap-webhooks')
|
||||
@ApiTags('Neoleap Webhooks')
|
||||
export class NeoLeapWebhooksController {
|
||||
constructor(private readonly transactionService: TransactionService) {}
|
||||
constructor(private readonly neoleapWebhookService: NeoLeapWebhookService) {}
|
||||
|
||||
@Post('card-transaction')
|
||||
async handleCardTransactionWebhook(@Body() body: CardTransactionWebhookRequest) {
|
||||
return this.transactionService.createCardTransaction(body);
|
||||
return this.neoleapWebhookService.handleCardTransactionWebhook(body);
|
||||
}
|
||||
|
||||
@Post('account-transaction')
|
||||
async handleAccountTransactionWebhook(@Body() body: AccountTransactionWebhookRequest) {
|
||||
return this.transactionService.createAccountTransaction(body);
|
||||
return this.neoleapWebhookService.handleAccountTransactionWebhook(body);
|
||||
}
|
||||
|
||||
@Post('account-card-status-changed')
|
||||
async handleAccountCardStatusChangedWebhook(@Body() body: AccountCardStatusChangedWebhookRequest) {
|
||||
return this.neoleapWebhookService.handleAccountCardStatusChangedWebhook(body);
|
||||
}
|
||||
}
|
||||
|
@ -37,7 +37,7 @@ export class NeoTestController {
|
||||
@ApiDataResponse(InquireApplicationResponse)
|
||||
async inquireApplication(@AuthenticatedUser() user: IJwtPayload) {
|
||||
const customer = await this.customerService.findCustomerById(user.sub);
|
||||
const data = await this.neoleapService.inquireApplication(customer.waitingNumber.toString());
|
||||
const data = await this.neoleapService.inquireApplication(customer.applicationNumber.toString());
|
||||
return ResponseFactory.data(data);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
export * from './account-card-status-changed-webhook.request.dto';
|
||||
export * from './account-transaction-webhook.request.dto';
|
||||
export * from './card-transaction-webhook.request.dto';
|
||||
export * from './update-card-controls.request.dto';
|
||||
|
@ -4,11 +4,12 @@ import { CardModule } from '~/card/card.module';
|
||||
import { CustomerModule } from '~/customer/customer.module';
|
||||
import { NeoLeapWebhooksController } from './controllers/neoleap-webhooks.controller';
|
||||
import { NeoTestController } from './controllers/neotest.controller';
|
||||
import { NeoLeapWebhookService } from './services';
|
||||
import { NeoLeapService } from './services/neoleap.service';
|
||||
|
||||
@Module({
|
||||
imports: [HttpModule, CustomerModule, CardModule],
|
||||
controllers: [NeoTestController, NeoLeapWebhooksController],
|
||||
providers: [NeoLeapService],
|
||||
providers: [NeoLeapService, NeoLeapWebhookService],
|
||||
})
|
||||
export class NeoLeapModule {}
|
||||
|
@ -0,0 +1,2 @@
|
||||
export * from './neoleap-webook.service';
|
||||
export * from './neoleap.service';
|
||||
|
@ -0,0 +1,25 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { CardService } from '~/card/services';
|
||||
import { TransactionService } from '~/card/services/transaction.service';
|
||||
import {
|
||||
AccountCardStatusChangedWebhookRequest,
|
||||
AccountTransactionWebhookRequest,
|
||||
CardTransactionWebhookRequest,
|
||||
} from '../dtos/requests';
|
||||
|
||||
@Injectable()
|
||||
export class NeoLeapWebhookService {
|
||||
constructor(private readonly transactionService: TransactionService, private readonly cardService: CardService) {}
|
||||
|
||||
handleCardTransactionWebhook(body: CardTransactionWebhookRequest) {
|
||||
return this.transactionService.createCardTransaction(body);
|
||||
}
|
||||
|
||||
handleAccountTransactionWebhook(body: AccountTransactionWebhookRequest) {
|
||||
return this.transactionService.createAccountTransaction(body);
|
||||
}
|
||||
|
||||
handleAccountCardStatusChangedWebhook(body: AccountCardStatusChangedWebhookRequest) {
|
||||
return this.cardService.updateCardStatus(body);
|
||||
}
|
||||
}
|
@ -50,7 +50,7 @@ export class NeoLeapService {
|
||||
CreateNewApplicationRequestDetails: {
|
||||
ApplicationRequestDetails: {
|
||||
InstitutionCode: this.institutionCode,
|
||||
ExternalApplicationNumber: customer.waitingNumber.toString(),
|
||||
ExternalApplicationNumber: customer.applicationNumber.toString(),
|
||||
ApplicationType: '01',
|
||||
Product: '1101',
|
||||
ApplicationDate: moment().format('YYYY-MM-DD'),
|
||||
|
Reference in New Issue
Block a user