src/Store/Connection/Adapter/JsonRequestAdapter.ts   A
last analyzed

Complexity

Total Complexity 8
Complexity/F 1

Size

Lines of Code 108
Function Count 8

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 77
dl 0
loc 108
rs 10
c 0
b 0
f 0
wmc 8
mnd 0
bc 0
fnc 8
bpm 0
cpm 1
noi 0

8 Functions

Rating   Name   Duplication   Size   Complexity  
A JsonRequestAdapter.all 0 9 1
A JsonRequestAdapter.post 0 9 1
A JsonRequestAdapter.responseJson 0 7 1
A JsonRequestAdapter.patch 0 9 1
A JsonRequestAdapter.delete 0 9 1
A JsonRequestAdapter.put 0 9 1
A JsonRequestAdapter.get 0 9 1
A JsonRequestAdapter.load 0 3 1
1
import QueueMessage from '../Queue/QueueMessage';
2
import ConnectionRequest from "../ConnectionRequest";
3
import {AdapterInterface, ModelInterface, ModelStaticInterface, QueueAble} from "../../../JeloquentInterfaces";
4
import ConnectionSettings from "../ConnectionSettings";
5
6
/**
7
 *
8
 */
9
export default class JsonRequestAdapter implements AdapterInterface {
10
11
    connectionSettings: ConnectionSettings;
12
13
    constructor (connectionSettings: ConnectionSettings) {
14
        this.connectionSettings = connectionSettings;
15
    }
16
17
    get isLocal(): boolean {
18
        return false;
19
    }
20
21
    get isRemote(): boolean {
22
        return true;
23
    }
24
25
    all(model: ModelStaticInterface): Promise<QueueAble> {
26
        return new Promise((resolve => {
27
            new ConnectionRequest(this.connectionSettings)
28
                .all(model)
29
                .then(response => this.responseJson(response))
30
                .then(data => {
31
                    const message = new QueueMessage(model, 'insert', data);
32
                    resolve(message);
33
                });
34
        }));
35
    }
36
37
    delete(model: ModelInterface): Promise<QueueAble> {
38
        return new Promise((resolve => {
39
            new ConnectionRequest(this.connectionSettings)
40
                .delete(model)
41
                .then(response => this.responseJson(response))
42
                .then(data => {
43
                    const message = new QueueMessage(model, 'delete', data);
44
                    resolve(message);
45
                });
46
        }));
47
    }
48
49
    get(model: ModelInterface): Promise<QueueAble> {
50
        return new Promise((resolve => {
51
            new ConnectionRequest(this.connectionSettings)
52
                .get(model)
53
                .then(response => this.responseJson(response))
54
                .then(data => {
55
                    const message = new QueueMessage(model, 'fill', data);
56
                    resolve(message);
57
                });
58
        }))
59
    }
60
61
    load(model: ModelStaticInterface): Promise<QueueAble> {
62
        return this.all(model);
63
    }
64
65
    patch(model: ModelInterface): Promise<QueueAble> {
66
        return new Promise((resolve => {
67
            new ConnectionRequest(this.connectionSettings)
68
                .patch(model)
69
                .then(response => this.responseJson(response))
70
                .then(data => {
71
                    const message = new QueueMessage(model, 'fill', data);
72
                    resolve(message);
73
                });
74
        }));
75
    }
76
77
    post(model: ModelInterface): Promise<QueueAble> {
78
        return new Promise((resolve => {
79
            new ConnectionRequest(this.connectionSettings)
80
                .post(model)
81
                .then(response => this.responseJson(response))
82
                .then(data => {
83
                    const message = new QueueMessage(model, 'fill', data);
84
                    resolve(message);
85
                });
86
        }))
87
    }
88
89
    put(model: ModelInterface): Promise<QueueAble> {
90
        return new Promise((resolve => {
91
            new ConnectionRequest(this.connectionSettings)
92
                .put(model)
93
                .then(response => this.responseJson(response))
94
                .then(data => {
95
                    const message = new QueueMessage(model, 'fill', data);
96
                    resolve(message);
97
                });
98
        }));
99
    }
100
101
    /**
102
     *
103
     * @param {Response} response
104
     */
105
    responseJson(response) {
106
        return response.json();
107
    }
108
}