From 67412bc5f6f0a1d46f4cfa5c8d69030d3df97521 Mon Sep 17 00:00:00 2001 From: Anni Piragauta Date: Thu, 1 Aug 2024 17:14:13 -0500 Subject: [PATCH] feat: add logs for flyover calls getQuote and getLiquidityProviders --- src/controllers/index.ts | 2 + .../register-flyover-call.controller.ts | 41 +++++++++++++++++++ src/models/index.ts | 1 + src/models/register-flyover-call.model.ts | 25 +++++++++++ src/services/register.service.ts | 12 +++++- 5 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 src/controllers/register-flyover-call.controller.ts create mode 100644 src/models/register-flyover-call.model.ts diff --git a/src/controllers/index.ts b/src/controllers/index.ts index ca8f194e..900b742d 100644 --- a/src/controllers/index.ts +++ b/src/controllers/index.ts @@ -5,3 +5,5 @@ export * from './health-check.controller'; export * from './tx-status.controller'; export * from './estimate-fee.controller'; export * from './addresses-info.controller'; +export * from './register.controller'; +export * from './register-flyover-call.controller'; diff --git a/src/controllers/register-flyover-call.controller.ts b/src/controllers/register-flyover-call.controller.ts new file mode 100644 index 00000000..68c0f610 --- /dev/null +++ b/src/controllers/register-flyover-call.controller.ts @@ -0,0 +1,41 @@ +import {Logger, getLogger} from 'log4js'; +import {inject} from '@loopback/core'; +import {Response, RestBindings, getModelSchemaRef, post, requestBody} from '@loopback/rest'; +import {repository} from '@loopback/repository'; +import {RegisterCallPayload} from '../models'; +import {SessionRepository} from '../repositories'; +import {ServicesBindings} from '../dependency-injection-bindings'; +import {RegisterService} from '../services'; + +export class RegisterFlyoverCallController { + logger: Logger; + + constructor( + @inject(ServicesBindings.REGISTER_SERVICE) + protected registerService: RegisterService, + @inject(RestBindings.Http.RESPONSE) + private response: Response, + @repository(SessionRepository) + public sessionRepository: SessionRepository, + ) { + this.logger = getLogger('register-flyover-call-controller'); + } + + @post('/register-flyover-call', { + responses: { + '200': { + description: + 'Register a flyover call by 2wp-app for metrics', + }, + }, + }) + async registerCalls( + @requestBody({ + content: {'application/json': {schema: getModelSchemaRef(RegisterCallPayload)}}, + }) + payload: RegisterCallPayload, + ): Promise { + await this.registerService.registerFlyoverCall(payload); + return this.response.status(200).send(); + } +} diff --git a/src/models/index.ts b/src/models/index.ts index 088a3de3..24b4a451 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -19,3 +19,4 @@ export * from './fee-amount.model'; export * from './register-payload.model'; export * from './features.model'; export * from './pegout-status.model'; +export * from './register-flyover-call.model'; diff --git a/src/models/register-flyover-call.model.ts b/src/models/register-flyover-call.model.ts new file mode 100644 index 00000000..ce844546 --- /dev/null +++ b/src/models/register-flyover-call.model.ts @@ -0,0 +1,25 @@ +import {Model, model, property} from '@loopback/repository'; + +@model() +export class RegisterCallPayload extends Model { + @property({ + type: 'string', + }) + operationType?: string; + + @property({ + type: 'string', + required: true, + }) + functionType: string; + + @property({ + type: 'string', + required: true, + }) + result: string; + + constructor(data?: Partial) { + super(data); + } +} diff --git a/src/services/register.service.ts b/src/services/register.service.ts index c4eddbbf..39e89b77 100644 --- a/src/services/register.service.ts +++ b/src/services/register.service.ts @@ -1,5 +1,5 @@ import mongoose from 'mongoose'; -import {RegisterPayload} from '../models'; +import {RegisterCallPayload, RegisterPayload} from '../models'; import {AppTxModel} from '../models/app-tx.model'; import {MongoDbDataService} from './mongodb-data.service'; @@ -11,7 +11,7 @@ const AppTxSchema = new mongoose.Schema({ creationDate: {type: Date, required: true}, value: {type: Number, required: true}, wallet: {type: String, required: true}, - fee: {type: Number, required: true}, + fee: {type: Number, required: true}, rskGas: {type: Number, required: true}, btcEstimatedFee: {type: Number, required: true}, provider: {type: String, required: true}, @@ -61,4 +61,12 @@ export class RegisterService extends MongoDbDataService { + const { operationType, functionType, result } = payload; + this.logger.info( + `[NEW_FLYOVER_CALL] [type=${operationType}, call=${functionType}, response=${result}]`, + ); + return true; + } }