Quellcode durchsuchen

Finished feature 684

feature/684
Djordje Mitrovic vor 3 Jahren
Ursprung
Commit
75093f2197
4 geänderte Dateien mit 41 neuen und 19 gelöschten Zeilen
  1. 3
    0
      src/request/apiEndpoints.js
  2. 26
    11
      src/request/chatRequest.js
  3. 2
    2
      src/request/index.js
  4. 10
    6
      src/store/saga/chatSaga.js

+ 3
- 0
src/request/apiEndpoints.js Datei anzeigen

@@ -173,6 +173,9 @@ export default {
},
chat: {
getChat: "chats",
getUserChats: "users/{userId}/chat",
getOneChat: "users/{userId}/chats/{chatId}",
createChat: "users/{userId}/offers/{offerId}/chat",
sendMessage: "chats",
},
exchange: {

+ 26
- 11
src/request/chatRequest.js Datei anzeigen

@@ -1,18 +1,33 @@
import { getRequest, postRequest } from "."
import { getRequest, postRequest, replaceInUrl } from ".";
import apiEndpoints from "./apiEndpoints";

export const attemptFetchChats = (payload) => {
return getRequest(`users/${payload}/chat`);
}
return getRequest(
replaceInUrl(apiEndpoints.chat.getUserChats, { userId: payload })
);
};
export const attemptFetchHeaderChats = (payload) => {
return getRequest(`users/${payload}/chat/?page=1&size=2`)
}
return getRequest(
replaceInUrl(apiEndpoints.chat.getUserChats, { userId: payload }) +
`?page=1&size=2`
);
};
export const attemptFetchOneChat = (payload) => {
return getRequest(apiEndpoints.chat.getChat + `/${payload}`);
}
return getRequest(
replaceInUrl(apiEndpoints.chat.getOneChat, {
userId: payload.userId,
chatId: payload.chatId,
})
);
};
export const attemptSendMessage = (chatId, message) => {
return postRequest(apiEndpoints.chat.sendMessage + `/${chatId}`, message)
}
return postRequest(apiEndpoints.chat.sendMessage + `/${chatId}`, message);
};
export const attemptCreateNewChat = (payload) => {
return postRequest(`offers/${payload}/chat`)
}
return postRequest(
replaceInUrl(apiEndpoints.chat.createChat, {
userId: payload.userId,
offerId: payload.offerId,
})
);
};

+ 2
- 2
src/request/index.js Datei anzeigen

@@ -5,8 +5,8 @@ const request = axios.create({
// baseURL: "http://192.168.88.150:3001/", // DJOLE
// baseURL: "http://192.168.88.175:3005/",
// baseURL: "http://192.168.88.143:3001/", // DULE
baseURL: "https://trampa-api-test.dilig.net/",
// baseURL: "http://localhost:3001/",
// baseURL: "https://trampa-api-test.dilig.net/",
baseURL: "http://localhost:3001/",
// baseURL: process.env.REACT_APP_BASE_API_URL,
headers: {
"Content-Type": "application/json",

+ 10
- 6
src/store/saga/chatSaga.js Datei anzeigen

@@ -38,6 +38,7 @@ function* fetchChats() {
try {
const userId = yield select(selectUserId);
const data = yield call(attemptFetchChats, userId);
yield call(console.dir, data);
yield put(setChats([...data.data]));
yield put(fetchChatsSuccess());
} catch (e) {
@@ -59,7 +60,11 @@ function* fetchHeaderChats() {
}
function* fetchOneChat(payload) {
try {
const chatData = yield call(attemptFetchOneChat, payload.payload);
const userId = yield select(selectUserId);
const chatData = yield call(attemptFetchOneChat, {
chatId: payload.payload,
userId,
});
const chat = {
chat: chatData.data.chat,
offer: {
@@ -67,7 +72,6 @@ function* fetchOneChat(payload) {
},
interlocutor: chatData.data.interlocutorData,
};
(chatData);
yield put(setOneChat(chat));
yield put(fetchOneChatSuccess());
} catch (e) {
@@ -100,11 +104,11 @@ function* sendMessage(payload) {
}
function* startNewChat(payload) {
try {
const newChatData = yield call(
attemptCreateNewChat,
payload.payload.offerId
);
const userId = yield select(selectUserId);
const newChatData = yield call(attemptCreateNewChat, {
offerId: payload.payload.offerId,
userId,
});
const data = yield call(attemptFetchChats, userId);
yield put(setChats([...data.data]));
const newChatId = newChatData.data.chatId;

Laden…
Abbrechen
Speichern