Skip to content

Commit 60b669d

Browse files
committed
crud operations
1 parent 2609e44 commit 60b669d

File tree

4 files changed

+94
-4
lines changed

4 files changed

+94
-4
lines changed

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const ItemsAPI = require('itemsapi')
3434

3535
let response = await index.updateConfig(config);
3636
response = await index.addItems(items);
37-
response = await await index.search({
37+
response = await index.search({
3838
per_page: 3,
3939
filters: {
4040
tags: ['epic']
@@ -52,7 +52,11 @@ const ItemsAPI = require('itemsapi')
5252

5353
- Make a search request:
5454

55-
`await client.getIndex().search(input)`
55+
`await index.search(input)`
56+
57+
- List filters for specific facet:
58+
59+
`await index.facet(input)`
5660

5761
### Index
5862

@@ -66,6 +70,23 @@ const ItemsAPI = require('itemsapi')
6670

6771
`await index.addItems(items)`
6872

73+
- Get item:
74+
75+
`await index.getItem(id)`
76+
77+
- Update item partially:
78+
79+
`await index.partialUpdateItem(id, data)`
80+
81+
- Update item:
82+
83+
`await index.updateItem(id, data)`
84+
85+
- Delete item:
86+
87+
`await index.deleteItem(id)`
88+
89+
6990
### Configuration
7091

7192
- Get configuration:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "itemsapi",
3-
"version": "2.0.2",
3+
"version": "2.0.4",
44
"description": "Javascript client for ItemsAPI",
55
"main": "index.js",
66
"scripts": {

src/index.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,37 @@ class Index extends AxiosWrapper {
2222
})
2323
}
2424

25+
facet(data) {
26+
27+
return this.instance.get('/facet', {
28+
params: data
29+
})
30+
}
31+
32+
aggregation(data) {
33+
return this.facet(data);
34+
}
35+
2536
addItems(data) {
2637
return this.instance.post('/items', data);
2738
}
2839

40+
getItem(id) {
41+
return this.instance.get(`/items/${id}`);
42+
}
43+
44+
updateItem(id, data) {
45+
return this.instance.post(`/items/${id}/update`, data);
46+
}
47+
48+
partialUpdateItem(id, data) {
49+
return this.instance.post(`/items/${id}/partial`, data);
50+
}
51+
52+
deleteItem(id) {
53+
return this.instance.delete(`/items/${id}`);
54+
}
55+
2956
//addItemsFromFile(data) {
3057
//return this.instance.post('/index', data);
3158
//}

tests/clientSpec.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const assert = require('assert');
2-
const data = require('./fixtures/movies.json');
2+
33

44
const ItemsAPI = require('../src/client');
55
const client = new ItemsAPI({
@@ -25,6 +25,15 @@ const config = {
2525
}
2626
}
2727

28+
var data = require('./fixtures/movies.json');
29+
30+
var i = 1;
31+
data = data.map(v => {
32+
v.id = i;
33+
++i;
34+
return v;
35+
})
36+
2837
describe('search', function() {
2938
it('should search items', async function() {
3039

@@ -41,8 +50,41 @@ describe('search', function() {
4150
facets_fields: ['tags']
4251
});
4352
console.log(result);
53+
assert.deepEqual(result.pagination.total, 20);
4454

4555
result = await index.getConfig();
4656
console.log(result);
57+
58+
result = await index.facet({
59+
name: 'tags'
60+
});
61+
console.log(result.data);
62+
63+
result = await index.getItem(1);
64+
assert.deepEqual(result.name, 'The Shawshank Redemption');
65+
66+
result = await index.getItem(100);
67+
console.log('res');
68+
console.log(result);
69+
70+
result = await index.deleteItem(3);
71+
result = await index.search({
72+
});
73+
assert.deepEqual(result.pagination.total, 19);
74+
75+
result = await index.partialUpdateItem(1, {
76+
votes: 1000000
77+
});
78+
result = await index.getItem(1);
79+
assert.deepEqual(result.name, 'The Shawshank Redemption');
80+
assert.deepEqual(result.votes, 1000000);
81+
82+
result = await index.updateItem(1, {
83+
id: 1,
84+
votes: 100
85+
});
86+
result = await index.getItem(1);
87+
assert.deepEqual(result.name, undefined);
88+
assert.deepEqual(result.votes, 100);
4789
});
4890
});

0 commit comments

Comments
 (0)