Skip to content

Commit

Permalink
added history service file
Browse files Browse the repository at this point in the history
  • Loading branch information
rutvikpumak committed Mar 24, 2022
1 parent b38c423 commit 8978bf2
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/services/history/historyService.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import axios from "axios";
import { ACTION_TYPE } from "../../utils";

export const addToHistory = (dispatch, video, token) => {
try {
(async () => {
const {
data: { history },
} = await axios.post(
"/api/user/history",
{
video,
},
{
headers: {
authorization: token,
},
}
);
history &&
dispatch({
type: ACTION_TYPE.ADD_TO_HISTORY,
payload: history,
});
})();
} catch (error) {
console.log("Error in add to history handler", error);
}
};

export const removeFromHistory = (dispatch, id, token) => {
try {
(async () => {
const {
data: { history },
} = await axios.delete(`/api/user/history/${id}`, {
headers: {
authorization: token,
},
});
history &&
dispatch({
type: ACTION_TYPE.REMOVE_FROM_HISTORY,
payload: history,
});
})();
} catch (error) {
console.log("Error in remove from history handler", error);
}
};

export const clearHistory = (dispatch, token) => {
try {
(async () => {
const {
data: { history },
} = await axios.delete("/api/user/history/all", {
headers: {
authorization: token,
},
});
history &&
dispatch({
type: ACTION_TYPE.CLEAR_HISTORY,
payload: history,
});
})();
} catch (error) {
console.log("Error in clear history handler", error);
}
};

0 comments on commit 8978bf2

Please sign in to comment.