All files / request/recommend recommend.request.ts

100% Statements 3/3
100% Branches 18/18
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                  29x                                           20x     20x                    
import { customIdentity, customPickBy } from '../../utils';
import { GlobalRequestOptions } from '../main/main.request.type';
import { buildRecommendRequestSchema } from './recommend.schema';
import { RecommendRequestParams, RecommendRequestResult } from './recommend.request.type';
 
 
export async function buildRecommendRequest(this: GlobalRequestOptions, params: RecommendRequestParams): Promise<RecommendRequestResult> {
 
 
    const validatedParams = await buildRecommendRequestSchema
        .validate(
            customPickBy({
                ...params,
                indexName: params.indexName || this?.indexName || process.env.GLOBAL_DEFAULT_INDEX_NAME,
                platformName: params.platformName || this?.platformName,
                recommendHandler: params.recommendHandler || this?.recommendHandler || process.env.GLOBAL_DEFAULT_RECOMMEND_HANDLER,
                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,
            }, customIdentity)
        );
 
 
    const {
        indexName,
        platformName,
        recommendHandler,
        APIKey,
        ...restOfOptions
    } = validatedParams;
 
 
    return {
        method: 'GET',
        url: `${process.env.API_BASE_URL}/projects/${platformName}/indices/${indexName}/recommend/${recommendHandler}`,
        params: {
            apikey: APIKey,
            ...restOfOptions
        },
        headers: {}
    }
}