CR fixes
[arvados.git] / src / services / services.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import Axios from "axios";
6 import { AuthService } from "./auth-service/auth-service";
7 import { GroupsService } from "./groups-service/groups-service";
8 import { ProjectService } from "./project-service/project-service";
9 import { LinkService } from "./link-service/link-service";
10 import { FavoriteService } from "./favorite-service/favorite-service";
11 import { CollectionService } from "./collection-service/collection-service";
12 import { TagService } from "./tag-service/tag-service";
13 import { CollectionFilesService } from "./collection-files-service/collection-files-service";
14 import { KeepService } from "./keep-service/keep-service";
15 import { WebDAV } from "../common/webdav";
16 import { Config } from "../common/config";
17 import { UserService } from './user-service/user-service';
18 import { AncestorService } from "~/services/ancestors-service/ancestors-service";
19 import { ResourceKind } from "~/models/resource";
20 import { ContainerRequestService } from './container-request-service/container-request-service';
21 import { ContainerService } from './container-service/container-service';
22
23 export type ServiceRepository = ReturnType<typeof createServices>;
24
25 export const createServices = (config: Config) => {
26     const apiClient = Axios.create();
27     apiClient.defaults.baseURL = config.baseUrl;
28
29     const webdavClient = new WebDAV();
30     webdavClient.defaults.baseURL = config.keepWebServiceUrl;
31
32     const groupsService = new GroupsService(apiClient);
33     const keepService = new KeepService(apiClient);
34     const linkService = new LinkService(apiClient);
35     const projectService = new ProjectService(apiClient);
36     const userService = new UserService(apiClient);
37     const containerRequestService = new ContainerRequestService(apiClient);
38     const containerService = new ContainerService(apiClient);
39     
40     const ancestorsService = new AncestorService(groupsService, userService);
41     const authService = new AuthService(apiClient, config.rootUrl);
42     const collectionService = new CollectionService(apiClient, webdavClient, authService);
43     const collectionFilesService = new CollectionFilesService(collectionService);
44     const favoriteService = new FavoriteService(linkService, groupsService);
45     const tagService = new TagService(linkService);
46
47     return {
48         ancestorsService,
49         apiClient,
50         authService,
51         collectionFilesService,
52         collectionService,
53         containerRequestService,
54         containerService,
55         favoriteService,
56         groupsService,
57         keepService,
58         linkService,
59         projectService,
60         tagService,
61         userService,
62         webdavClient,
63     };
64 };
65
66 export const getResourceService = (kind?: ResourceKind) => (serviceRepository: ServiceRepository) => {
67     switch (kind) {
68         case ResourceKind.USER:
69             return serviceRepository.userService;
70         case ResourceKind.GROUP:
71             return serviceRepository.groupsService;
72         case ResourceKind.COLLECTION:
73             return serviceRepository.collectionService;
74         default:
75             return undefined;
76     }
77 };