All files / src/services logging.service.ts

62.5% Statements 5/8
0% Branches 0/4
0% Functions 0/3
50% Lines 3/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 311x 1x     1x                                                    
import {inject, injectable} from '@loopback/core';
import {juggler} from '@loopback/repository';
 
@injectable()
export class LoggingService {
  constructor(
    @inject('datasources.logchain')
    private dataSource: juggler.DataSource,
  ) {}
 
  async logScan(data: {code: string; type: string; status: string; responseTime: number; error?: string}) {
    await this.dataSource.execute(
      `
      INSERT INTO scan_log (code, type, status, response_time, error_message)
      VALUES ($1, $2, $3, $4, $5)
      `,
      [data.code, data.type, data.status, data.responseTime, data.error ?? null],
    );
  }
 
  async logApi(data: {endpoint: string; method: string; statusCode: number; responseTime: number}) {
    await this.dataSource.execute(
      `
      INSERT INTO api_log (endpoint, method, status_code, response_time)
      VALUES ($1, $2, $3, $4)
      `,
      [data.endpoint, data.method, data.statusCode, data.responseTime],
    );
  }
}