src/api/restful-api.js   A
last analyzed

Size

Lines of Code 48

Duplication

Duplicated Lines 0
Ratio 0 %

Test Coverage

Coverage 23.08%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
nc 1
dl 0
loc 48
ccs 3
cts 13
cp 0.2308
rs 10
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A restful-api.js ➔ ??? 0 7 1
1
import axios from 'axios';
2
3
4
5
export default class CommentsApi {
6
7
	constructor(baseUrl = '/comments/') {
8 2
		this.axios = axios.create({
9
			baseURL: baseUrl
10
		});
11
12 2
		this.axios.defaults.headers.common['Accept'] = 'application/json';
13
	}
14
15
	getComments(model, id, parentId = null, params = {}) {
16
		let url = model + '/' + id;
17
18 4
		if (parentId !== null) {
19
			url = url + '/' + parentId
20
		}
21
22
		return this.axios.get(url, {
23
			params: params
24
		});
25
	}
26
27
	getCommentsBefore(model, id, parentId = null, time, params = {}) {
28
		params.before = time;
29
		return this.getComments(model, id, parentId, params);
30
	}
31
32
	getCommentsAfter(model, id, parentId = null, time, params = {}) {
33
		params.after = time;
34
		return this.getComments(model, id, parentId, params);
35
	}
36
37
	add(model, id, data) {
38
		return this.axios.post(model + '/' + id, data);
39
	}
40
41
	remove(model, id, commentId) {
42
		return this.axios.delete(model + '/' + id + '/' + commentId);
43
	}
44
45
	update(model, id, commentId, data) {
46
		this.axios.patch(model + '/' + id + '/' + commentId, data)
47
	}
48
}
49