import { Injectable } from '@nestjs/common' ; import { Account , AccountNotFoundException , AccountService } from '@fc/account' ; import { CryptographyFcpService , IPivotIdentity } from '@fc/cryptography-fcp' ; import { LoggerLevelNames , LoggerService } from '@fc/logger' ; import { CsrmTracksNoTracksException } from '../exceptions' ; import { ICsmrTracksOutputTrack } from '../interfaces' ; import { CsmrTracksElasticsearchService } from './csmr-tracks-elasticsearch.service' ; @ Injectable ( ) export class CsmrTracksService { constructor ( private readonly logger , private readonly account , private readonly cryptographyFcp , private readonly elasticsearch ) { this . logger . setContext ( this . constructor . name ) ; } async getList ( identity ) { const identityHash = this . cryptographyFcp . computeIdentityHash ( identity ) ; const { id } = await this . account . getAccountByIdentityHash ( identityHash ) ; if ( id === null ) { this . logger . trace ( { error : 'No account found' , identityHash } , LoggerLevelNames . WARN ) ; throw new AccountNotFoundException ( ) ; } const tracks = await this . elasticsearch . getTracksByAccountId ( id ) ; if ( tracks . length <= 0 ) { this . logger . trace ( { error : 'No traces found' } , LoggerLevelNames . WARN ) ; throw new CsrmTracksNoTracksException ( ) ; } this . logger . trace ( { accountId : id , identity , identityHash , tracks } ) ; return tracks ; } }