All files / src/services user.ts

100% Statements 25/25
100% Branches 8/8
100% Functions 3/3
100% Lines 25/25

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 401x     1x 1x     1x               1x 4x 4x 4x 4x 4x 4x 4x 4x   2x 4x 4x 2x 2x 2x 2x 2x 4x 4x 4x 4x      
import { Effect, pipe } from 'effect';
 
// Constants
import { END_POINTS, ERROR_MESSAGES } from '@/constants';
import { STATUS_CODE } from '@shared/constants';
 
// Services
import { httpClient } from '@/services/httpClient';
 
// Types
import { UserProfile } from '@/types/auth';
 
// Utils
import { HttpClientConfig } from '@/types';
 
const getUserProfile = async (options?: { requestConfig?: HttpClientConfig }) =>
  Effect.runPromise(
    pipe(
      Effect.tryPromise({
        try: async () => {
          const response = await httpClient<UserProfile>(
            END_POINTS.GET_USER_PROFILE,
            options?.requestConfig,
          );
 
          return response;
        },
        catch: (error) => ({
          data: null,
          error:
            error instanceof Error ? error.message : ERROR_MESSAGES.DEFAULT,
          status: STATUS_CODE.INTERNAL_SERVER_ERROR,
        }),
      }),
      Effect.catchAll((error) => Effect.succeed(error)),
    ),
  );
 
export { getUserProfile };