This commit is contained in:
2024-05-12 21:32:30 +02:00
parent af562b7b10
commit aa59eaa3fc
18 changed files with 428 additions and 78 deletions

View File

@@ -6,7 +6,7 @@ export const isLoggedIn = async () => {
return response.data;
} catch (error) {
return error.response.data;
return error.responseq;
}
};
@@ -15,7 +15,7 @@ export const login = async (username, password) => {
const response = await axios.post("/authenticate", { username, password });
return response.data;
} catch (error) {
return error.response.data;
return error.response;
}
};
@@ -25,6 +25,6 @@ export const logout = async () => {
return response.data;
} catch (error) {
return error.response.data;
return error.response;
}
};

View File

@@ -5,7 +5,7 @@ import axios from "axios";
export const getRoom = async (_id) => {
try {
const response = await axios.get("/room", {_id});
const response = await axios.get("/room/"+{_id});
console.log(response.data)
return response.data;
} catch (error) {
@@ -16,7 +16,7 @@ export const getRoom = async (_id) => {
export const getRooms = async () => {
try {
const response = await axios.get("/room", {});
const response = await axios.get("/room");
console.log(response.data)
return response.data;
} catch (error) {
@@ -24,3 +24,60 @@ export const getRooms = async () => {
return error.response.data;
}
};
export const getRoomStats = async () => {
try {
const response = await axios.get("/room/stats");
console.log(response.data)
return response.data;
} catch (error) {
console.log("ERROR", error.response.data)
return error.response.data;
}
};
export const formatRoomStats = (roomStats) => {
const global = formatRoomStatsGlobal(roomStats.global)
const rooms = Object.values(roomStats.rooms).map(formatRoom);
const years = roomStats.years;
return {
global,
rooms,
years
}
}
function formatRoomStatsGlobal(global){
const { rooms_count, items_count, total_price, average_price} = global;
const most_item_room = {
name: global.most_item_room.name,
count: global.most_item_room.count
};
const most_expensive_room = {
name: global.most_expensive_room.name,
price: global.most_expensive_room.price
};
return {
rooms_count,
items_count,
total_price,
average_price,
most_item_room,
most_expensive_room
};
}
function formatRoom(room) {
const { _id, name, items_count, room_price } = room;
return {
_id,
name,
items_count,
room_price
};
}