Passed
Push — master ( 34c669...9a4c09 )
by Christian
13:27 queued 13s
created

src/Administration/Resources/app/administration/src/module/sw-extension/service/extension-store-licenses.service.js   A

Complexity

Total Complexity 5
Complexity/F 1.25

Size

Lines of Code 45
Function Count 4

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 27
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 5
mnd 1
bc 1
fnc 4
bpm 0.25
cpm 1.25
noi 0

4 Functions

Rating   Name   Duplication   Size   Complexity  
A ExtensionLicenseService.constructor 0 4 1
A ExtensionLicenseService.purchaseExtension 0 10 1
A ExtensionLicenseService.basicHeaders 0 13 2
A ExtensionLicenseService.getLicensedExtensions 0 11 1
1
import ApiService from 'src/core/service/api.service';
2
3
export default class ExtensionLicenseService extends ApiService {
4
    constructor(httpClient, loginService, apiEndpoint = 'plugin') {
5
        super(httpClient, loginService, apiEndpoint);
6
        this.name = 'extensionStoreLicensesService';
7
    }
8
9
    async getLicensedExtensions(context) {
10
        const { data } = await this.httpClient.get('_action/extension/licensed', {
11
            headers: this.basicHeaders(context),
12
            version: 3
13
        });
14
15
        const licensedExtensions = data.data;
16
        licensedExtensions.total = data.meta.total;
17
18
        return licensedExtensions;
19
    }
20
21
    async purchaseExtension(extensionId, variantId, tocAccepted, permissionsAccepted) {
22
        await this.httpClient.post(
23
            '_action/extension/purchase',
24
            { extensionId, variantId, tocAccepted, permissionsAccepted },
25
            {
26
                headers: this.basicHeaders(),
27
                version: 3
28
            }
29
        );
30
    }
31
32
    basicHeaders(context = null) {
33
        const headers = {
34
            'Content-Type': 'application/json',
35
            Accept: 'application/json',
36
            Authorization: `Bearer ${this.loginService.getToken()}`
37
        };
38
39
        if (context && context.languageId) {
40
            headers['sw-language-id'] = context.languageId;
41
        }
42
43
        return headers;
44
    }
45
}
46