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