Refactor network service to use config objects for clarity

This commit is contained in:
Alex Holliday committed 2024-09-22 11:38:42 +08:00
1 parent a8e069b820
commit 1c8376dc24
11 files changed
+325 -286

No files matched your search

@@ -13,7 +13,10 @@ export const createPageSpeed = createAsyncThunk(
async (data, thunkApi) => {
try {
const { authToken, monitor } = data;
const res = await networkService.createMonitor(authToken, monitor);
const res = await networkService.createMonitor({
authToken: authToken,
moniotr: monitor,
});
return res.data;
} catch (error) {
if (error.response && error.response.data) {
@@ -33,7 +36,7 @@ export const getPagespeedMonitorById = createAsyncThunk(
async (data, thunkApi) => {
try {
const { authToken, monitorId } = data;
const res = await networkService.getMonitorByid(authToken, monitorId);
const res = await networkService.getMonitorByid({ authToken, monitorId });
return res.data;
} catch (error) {
if (error.response && error.response.data) {
@@ -53,11 +56,11 @@ export const getPageSpeedByTeamId = createAsyncThunk(
async (token, thunkApi) => {
const user = jwtDecode(token);
try {
const res = await networkService.getMonitorsAndSummaryByTeamId(
token,
user.teamId,
["pagespeed"]
);
const res = await networkService.getMonitorsAndSummaryByTeamId({
authToken: token,
teamId: user.teamId,
types: ["pagespeed"],
});
return res.data;
} catch (error) {
@@ -84,11 +87,11 @@ export const updatePageSpeed = createAsyncThunk(
interval: monitor.interval,
// notifications: monitor.notifications,
};
const res = await networkService.updateMonitor(
authToken,
monitor._id,
updatedFields
);
const res = await networkService.updateMonitor({
authToken: authToken,
monitorId: monitor._id,
updatedFields: updatedFields,
});
return res.data;
} catch (error) {
if (error.response && error.response.data) {
@@ -108,10 +111,10 @@ export const deletePageSpeed = createAsyncThunk(
async (data, thunkApi) => {
try {
const { authToken, monitor } = data;
const res = await networkService.deleteMonitorById(
authToken,
monitor._id
);
const res = await networkService.deleteMonitorById({
authToken: authToken,
monitorId: monitor._id,
});
return res.data;
} catch (error) {
if (error.response && error.response.data) {
@@ -130,7 +133,10 @@ export const pausePageSpeed = createAsyncThunk(
async (data, thunkApi) => {
try {
const { authToken, monitorId } = data;
const res = await networkService.pauseMonitorById(authToken, monitorId);
const res = await networkService.pauseMonitorById({
authToken: authToken,
monitorId: monitorId,
});
return res.data;
} catch (error) {
if (error.response && error.response.data) {