-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathResourceRepository.js
More file actions
67 lines (55 loc) · 1.56 KB
/
Copy pathResourceRepository.js
File metadata and controls
67 lines (55 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import apiClient from "../services/ApiClient";
import {
mapApplication,
mapService,
mapDatabase,
} from "../services/resourceMapper";
class ResourceRepository {
constructor(client = apiClient) {
this.client = client;
}
async fetchAll() {
const [applications, services, databases] = await Promise.all([
this.client.get("/applications"),
this.client.get("/services"),
this.client.get("/databases").catch(() => []),
]);
return [
...applications.map(mapApplication),
...services.map(mapService),
...(databases || []).map(mapDatabase),
];
}
async fetchApplications() {
const data = await this.client.get("/applications");
return data.map(mapApplication);
}
async fetchServices() {
const data = await this.client.get("/services");
return data.map(mapService);
}
async fetchDatabases() {
try {
const data = await this.client.get("/databases");
return (data || []).map(mapDatabase);
} catch (error) {
console.warn("Failed to fetch databases:", error);
return [];
}
}
async start(type, uuid) {
return await this.client.post(`/${type}s/${uuid}/start`);
}
async stop(type, uuid) {
return await this.client.post(`/${type}s/${uuid}/stop`);
}
async delete(type, uuid) {
return await this.client.delete(`/${type}s/${uuid}`);
}
async getLogs(type, uuid) {
return await this.client.get(`/${type}s/${uuid}/logs`);
}
}
const resourceRepository = new ResourceRepository();
export default resourceRepository;
export { ResourceRepository };