All files / src/api/service/user-service index.ts

73.33% Statements 55/75
100% Branches 5/5
50% Functions 5/10
73.33% Lines 55/75

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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 761x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x         6x 6x 6x 2x 2x 6x 6x 6x         6x 6x 6x         6x 6x 6x 3x 3x 6x 6x 6x 6x 6x 6x 3x 3x 3x 3x 6x 6x 6x 5x 5x 6x 6x 6x         6x 6x 6x         6x  
import { baseAPI } from '@/api/core/base';
import {
  Availability,
  FollowPathParams,
  GetEmailAvailabilityQueryParams,
  GetNicknameAvailabilityQueryParams,
  GetUserPathParams,
  UnfollowQueryParams,
  UpdateMyImagePayloads,
  UpdateMyInfoPayloads,
  UpdateMyNotificationQueryParams,
  User,
} from '@/types/service/user';
 
export const userServiceRemote = () => ({
  // 1. 사용자 팔로우
  followUser: async (pathParams: FollowPathParams) => {
    return baseAPI.post<string>(`/api/v1/users/follow`, null, {
      params: { followNickname: pathParams.followNickname },
    });
  },
 
  // 2. 유저 프로필 변경
  updateMyInfo: async (payloads: UpdateMyInfoPayloads) => {
    return baseAPI.patch<User>('/api/v1/users/profile', payloads);
  },
 
  // 3. 프로필 이미지 변경
  updateMyImage: async (payloads: UpdateMyImagePayloads) => {
    const formData = new FormData();
    formData.append('file', payloads.file);
    return baseAPI.patch<User>(`/api/v1/users/profile-image`, formData);
  },
 
  // 4. 알림 설정 변경
  updateMyNotification: async (queryParams: UpdateMyNotificationQueryParams) => {
    return baseAPI.patch<User>(`/api/v1/users/notification`, null, {
      params: { ...queryParams },
    });
  },
 
  // 5. 유저 프로필 조회
  getUser: async (pathParams: GetUserPathParams) => {
    return baseAPI.get<User>(`/api/v1/users/${pathParams.userId}`);
  },
 
  // 6. 팔로우 리스트 조회
  // getfollowUsers
 
  // 7. 닉네임 중복 검사
  getNicknameAvailability: async (queryParams: GetNicknameAvailabilityQueryParams) => {
    return baseAPI.get<Availability>(`/api/v1/users/nickname/availability`, {
      params: { nickname: queryParams.nickName },
    });
  },
 
  // 8. 본인 프로필 조회
  getMe: async () => {
    return baseAPI.get<User>(`/api/v1/users/me`);
  },
 
  // 9. 이메일 중복 검사
  getEmailAvailability: async (queryParams: GetEmailAvailabilityQueryParams) => {
    return baseAPI.get<Availability>(`/api/v1/users/email/availability`, {
      params: { email: queryParams.email },
    });
  },
 
  // 10. 사용자 언팔로우
  unfollowUser: async (params: UnfollowQueryParams) => {
    return baseAPI.delete<string>(`/api/v1/users/unfollow`, {
      params: { unFollowNickname: params.unFollowNickname },
    });
  },
});