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

66.66% Statements 38/57
100% Branches 1/1
12.5% Functions 1/8
66.66% Lines 38/57

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 581x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x     6x 6x 6x     6x 6x 6x               6x 6x 6x     6x 6x 6x     6x 6x 6x     6x 6x 6x     6x  
import { baseAPI } from '@/api/core/base';
import {
  ChattingRoom,
  CreateDMPayloads,
  GetChatMessagesParams,
  GetChatMessagesResponse,
  GetChatRoomParams,
  getChatRoomResponse,
  GetChatRoomsResponse,
  GetParticipantsParams,
  GetParticipantsResponse,
  KickUserPayloads,
  ReadMessagesParams,
  ReadMessagesResponse,
} from '@/types/service/chat';
 
export const chatServiceRemote = () => ({
  // 채팅방 목록 조회
  getChatRooms: async () => {
    return baseAPI.get<GetChatRoomsResponse>('/api/v1/chat/rooms');
  },
 
  // 1:1(DM) 채팅방 생성
  createDMChatRoom: async (payloads: CreateDMPayloads) => {
    return baseAPI.post<ChattingRoom>('/api/v1/chat/dm', payloads);
  },
 
  // 메세지 이력 조회
  getChatMessages: async ({ roomId, cursor, size }: GetChatMessagesParams) => {
    return baseAPI.get<GetChatMessagesResponse>(`/api/v1/chat/rooms/${roomId}/messages`, {
      params: {
        cursor,
        size,
      },
    });
  },
 
  // 메세지 읽음 처리
  readMessages: async ({ roomId }: ReadMessagesParams) => {
    return baseAPI.put<ReadMessagesResponse>(`/api/v1/chat/rooms/${roomId}/read`);
  },
 
  // 채팅방 상세 조회
  getChatRoom: async ({ roomId }: GetChatRoomParams) => {
    return baseAPI.get<getChatRoomResponse>(`/api/v1/chat/rooms/${roomId}`);
  },
 
  // 참여자 목록 조회
  getParticipants: async ({ roomId }: GetParticipantsParams) => {
    return baseAPI.get<GetParticipantsResponse>(`/api/v1/chat/rooms/${roomId}/participants`);
  },
 
  // 추방하기
  kickUser: async (roomId: number, payload: KickUserPayloads) => {
    return baseAPI.post(`/api/v1/chat/rooms/${roomId}/kick`, payload);
  },
});