Passed
Push — trunk ( 5d9bf1...024f41 )
by Christian
34:40 queued 22:07
created

api-services.init.ts ➔ initializeApiServices   A

Complexity

Conditions 1

Size

Total Lines 19
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 18
dl 0
loc 19
rs 9.5
c 0
b 0
f 0
1
/**
2
 * @package admin
3
 */
4
5
const apiServices = Shopware._private.ApiServices();
6
7
// eslint-disable-next-line sw-deprecation-rules/private-feature-declarations
8
export default function initializeApiServices() {
9
    // Add custom api service providers
10
    apiServices.forEach((ApiService) => {
11
        const factoryContainer = Shopware.Application.getContainer('factory');
12
        const initContainer = Shopware.Application.getContainer('init');
13
14
        const apiServiceFactory = factoryContainer.apiService;
15
        // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment
16
        const service = new ApiService(initContainer.httpClient, Shopware.Service('loginService'));
17
        // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
18
        const serviceName = service.name as keyof ServiceContainer;
19
        // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
20
        apiServiceFactory.register(serviceName, service);
21
22
        Shopware.Application.addServiceProvider(serviceName, () => {
23
            // eslint-disable-next-line @typescript-eslint/no-unsafe-return
24
            return service;
25
        });
26
    });
27
}
28