All files / src/Application/Pokemon/Queries/GetPokemon GetPokemonQueryHandler.ts

100% Statements 5/5
100% Branches 0/0
100% Functions 2/2
100% Lines 5/5

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                  2x   3x 3x                 12x   12x      
import { ClientInterface } from '@Application/Shared/Pokemon/ClientInterface';
import { GetPokemonQuery } from './GetPokemonQuery';
import { Result } from '@Domain/Types/Result';
import { Pokemon } from '@Domain/ValueObjects/Pokemon';
import { LoggerInterface } from '@Application/Shared/Monitoring/LoggerInterface';
 
/**
 * Handler for the GetPokemonQuery
 */
export class GetPokemonQueryHandler {
    constructor(
        private readonly logger: LoggerInterface,
        private readonly client: ClientInterface
    ) { }
 
    /**
     * Executes the query to retrieve Pokemon details
     * @param query The query containing the Pokemon name
     * @returns A promise resolving to a Result containing either the Pokemon details or an Error
     */
    async execute(query: GetPokemonQuery): Promise<Result<Error, Pokemon>> {
        this.logger.info(`Processing pokemon`, { name: query.name });
 
        return this.client.getPokemon(query.name);
    }
}