All files / request/search-by-id search-by-id.request.ts

100% Statements 3/3
100% Branches 17/17
100% Functions 1/1
100% Lines 3/3

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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46                  23x                                           15x       15x                    
import { customIdentity, customPickBy } from '../../utils';
import { GlobalRequestOptions } from '../main/main.request.type';
import { SearchByIdRequestParams, SearchByIdRequestResult } from './search-by-id.request.type';
import { buildSearchByIdRequestSchema } from './search-by-id.schema';
 
 
export async function buildSearchByIdRequest(this: GlobalRequestOptions, params: SearchByIdRequestParams): Promise<SearchByIdRequestResult> {
 
 
    const validatedParams = await buildSearchByIdRequestSchema
        .validate(
            customPickBy({
                ...params,
                indexName: params.indexName || this?.indexName || process.env.GLOBAL_DEFAULT_INDEX_NAME,
                platformName: params.platformName || this?.platformName,
                APIKey: params.APIKey || this?.APIKey,
                userCountry: params.userCountry || this?.userCountry,
                userId: params.userId || this?.userId,
                userIp: params.userIp || this?.userIp,
                sessionId: params.sessionId || this?.sessionId,
                sessionIdGenerator: params.sessionIdGenerator || this?.sessionIdGenerator,
            }, customIdentity)
        );
 
 
    const {
        indexName,
        platformName,
        APIKey,
        id,
        ...restOfOptions
    } = validatedParams;
 
 
 
    return {
        method: 'GET',
        url: `${process.env.API_BASE_URL}/projects/${platformName}/indices/${indexName}/documents/${id}`,
        params: {
            apikey: APIKey,
            ...restOfOptions
        },
        headers: {},
    }
}