Skip to content

Commit 6407530

Browse files
committed
refactoring
1 parent 6570c28 commit 6407530

File tree

6 files changed

+26
-32
lines changed

6 files changed

+26
-32
lines changed

src/pages/ProjectPage.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react";
22
import { Grid, Dialog, IconButton, Box, Typography } from "@material-ui/core";
33
import { useParams, useLocation, useHistory } from "react-router-dom";
44
import { Build, TestRun } from "../types";
5-
import { projectsService, buildsService, testRunService } from "../services";
5+
import { buildsService, testRunService } from "../services";
66
import BuildList from "../components/BuildList";
77
import ProjectSelect from "../components/ProjectSelect";
88
import qs from "qs";
@@ -79,14 +79,14 @@ const ProjectPage = () => {
7979

8080
useEffect(() => {
8181
if (projectId) {
82-
projectsService.getBuilds(projectId).then((builds) => setBuilds(builds));
82+
buildsService.getList(projectId).then((builds) => setBuilds(builds));
8383
}
8484
}, [projectId]);
8585

8686
useEffect(() => {
8787
if (selectedBuildId) {
88-
buildsService.get(selectedBuildId).then((build) => {
89-
setTestRuns(build.testRuns);
88+
testRunService.getList(selectedBuildId).then((testRuns) => {
89+
setTestRuns(testRuns);
9090
});
9191
}
9292
}, [selectedBuildId]);

src/services/builds.service.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@ import { Build } from "../types";
22
import { handleResponse, authHeader } from "../_helpers/service.helpers";
33
import { API_URL } from "../_config/api.config";
44

5+
const ENDPOINT_URL = "/builds"
6+
57
export const buildsService = {
6-
get,
8+
getList,
79
remove,
810
};
911

10-
function get(id: string): Promise<Build> {
12+
function getList(projectId: string): Promise<Build[]> {
1113
const requestOptions = {
1214
method: "GET",
1315
headers: authHeader(),
1416
};
1517

16-
return fetch(`${API_URL}/builds/${id}`, requestOptions).then(handleResponse);
18+
return fetch(`${API_URL}${ENDPOINT_URL}?projectId=${projectId}`, requestOptions).then(
19+
handleResponse
20+
);
1721
}
1822

1923
function remove(id: string): Promise<number> {
@@ -22,5 +26,5 @@ function remove(id: string): Promise<number> {
2226
headers: authHeader(),
2327
};
2428

25-
return fetch(`${API_URL}/builds/${id}`, requestOptions).then(handleResponse);
29+
return fetch(`${API_URL}${ENDPOINT_URL}/${id}`, requestOptions).then(handleResponse);
2630
}

src/services/projects.service.ts

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
import { Project, Build } from "../types";
1+
import { Project } from "../types";
22
import { handleResponse, authHeader } from "../_helpers/service.helpers";
33
import { API_URL } from "../_config/api.config";
44

55
export const projectsService = {
6-
getBuilds,
76
getAll,
87
remove,
98
create,
@@ -18,17 +17,6 @@ function getAll(): Promise<Project[]> {
1817
return fetch(`${API_URL}/projects`, requestOptions).then(handleResponse);
1918
}
2019

21-
function getBuilds(id: string): Promise<Build[]> {
22-
const requestOptions = {
23-
method: "GET",
24-
headers: authHeader(),
25-
};
26-
27-
return fetch(`${API_URL}/projects/${id}`, requestOptions).then(
28-
handleResponse
29-
);
30-
}
31-
3220
function remove(id: string): Promise<number> {
3321
const requestOptions = {
3422
method: "DELETE",

src/services/testRun.service.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,20 @@ import { IgnoreArea } from "../types/ignoreArea";
66
const ENDPOINT_URL = "/test-runs"
77

88
export const testRunService = {
9-
get,
9+
getList,
1010
remove,
1111
approve,
1212
reject,
1313
setIgnoreAreas,
1414
};
1515

16-
function get(testId: string): Promise<TestRun> {
16+
function getList(buildId: string): Promise<TestRun[]> {
1717
const requestOptions = {
1818
method: "GET",
1919
headers: authHeader(),
2020
};
2121

22-
return fetch(`${API_URL}${ENDPOINT_URL}/${testId}`, requestOptions).then(
23-
handleResponse
24-
);
22+
return fetch(`${API_URL}${ENDPOINT_URL}?buildId=${buildId}`, requestOptions).then(handleResponse);
2523
}
2624

2725
function remove(id: string): Promise<Number> {

src/services/testVariation.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { handleResponse, authHeader } from "../_helpers/service.helpers";
33
import { API_URL } from "../_config/api.config";
44
import { IgnoreArea } from "../types/ignoreArea";
55

6+
const ENDPOINT_URL = "/test-variations"
7+
68
export const testVariationService = {
79
get,
810
setIgnoreAreas
@@ -14,7 +16,7 @@ function get(projectId: String): Promise<TestVariation[]> {
1416
headers: authHeader(),
1517
};
1618

17-
return fetch(`${API_URL}/test-variations?projectId=${projectId}`, requestOptions).then(handleResponse);
19+
return fetch(`${API_URL}${ENDPOINT_URL}?projectId=${projectId}`, requestOptions).then(handleResponse);
1820
}
1921

2022
function setIgnoreAreas(
@@ -28,7 +30,7 @@ function setIgnoreAreas(
2830
};
2931

3032
return fetch(
31-
`${API_URL}/test-variations/ignoreArea/${variationId}`,
33+
`${API_URL}${ENDPOINT_URL}/ignoreArea/${variationId}`,
3234
requestOptions
3335
).then(handleResponse);
3436
}

src/services/users.service.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { handleResponse, authHeader } from "../_helpers/service.helpers";
22
import { User } from "../types/user";
33
import { API_URL } from "../_config/api.config";
44

5+
const ENDPOINT_URL = "/users"
6+
57
export const usersService = {
68
login,
79
logout,
@@ -17,7 +19,7 @@ function login(email: string, password: string): Promise<User> {
1719
body: JSON.stringify({ email, password }),
1820
};
1921

20-
return fetch(`${API_URL}/users/login`, requestOptions)
22+
return fetch(`${API_URL}${ENDPOINT_URL}/login`, requestOptions)
2123
.then(handleResponse)
2224
.then((user) => {
2325
setUserInLocalStorage(user)
@@ -32,7 +34,7 @@ function register(firstName: string, lastName: string, email: string, password:
3234
body: JSON.stringify({ firstName, lastName, email, password }),
3335
};
3436

35-
return fetch(`${API_URL}/users/register`, requestOptions)
37+
return fetch(`${API_URL}${ENDPOINT_URL}/register`, requestOptions)
3638
.then(handleResponse)
3739
.then((user) => {
3840
setUserInLocalStorage(user)
@@ -47,7 +49,7 @@ function update({ id, firstName, lastName, email }: { id: string, firstName: str
4749
body: JSON.stringify({ firstName, lastName, email }),
4850
};
4951

50-
return fetch(`${API_URL}/users/${id}`, requestOptions)
52+
return fetch(`${API_URL}${ENDPOINT_URL}/${id}`, requestOptions)
5153
.then(handleResponse)
5254
.then((user) => {
5355
setUserInLocalStorage(user)
@@ -62,7 +64,7 @@ function changePassword(password: string): Promise<boolean> {
6264
body: JSON.stringify({ password }),
6365
};
6466

65-
return fetch(`${API_URL}/users/password`, requestOptions)
67+
return fetch(`${API_URL}${ENDPOINT_URL}/password`, requestOptions)
6668
.then(handleResponse)
6769
}
6870

0 commit comments

Comments
 (0)