2016-06-17 20:25:44 +02:00
|
|
|
'use strict';
|
|
|
|
|
2016-06-19 19:16:40 +02:00
|
|
|
const api = require('../api.js');
|
|
|
|
const AbstractList = require('./abstract_list.js');
|
2016-06-17 20:25:44 +02:00
|
|
|
const Post = require('./post.js');
|
|
|
|
|
2016-06-19 19:16:40 +02:00
|
|
|
class PostList extends AbstractList {
|
|
|
|
static getAround(id, searchQuery) {
|
|
|
|
return api.get(`/post/${id}/around?fields=id&query=${searchQuery}`)
|
|
|
|
.then(response => {
|
|
|
|
return Promise.resolve(response);
|
|
|
|
}).catch(response => {
|
|
|
|
return Promise.reject(response.description);
|
|
|
|
});
|
2016-06-17 20:25:44 +02:00
|
|
|
}
|
|
|
|
|
2016-06-19 19:16:40 +02:00
|
|
|
static search(text, page, pageSize, fields) {
|
|
|
|
const url =
|
|
|
|
`/posts/?query=${text}` +
|
|
|
|
`&page=${page}` +
|
|
|
|
`&pageSize=${pageSize}` +
|
|
|
|
`&fields=${fields.join(',')}`;
|
|
|
|
return api.get(url).then(response => {
|
|
|
|
return Promise.resolve(Object.assign(
|
|
|
|
{},
|
|
|
|
response,
|
|
|
|
{results: PostList.fromResponse(response.results)}));
|
|
|
|
});
|
2016-06-17 20:25:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-19 19:16:40 +02:00
|
|
|
PostList._itemClass = Post;
|
|
|
|
PostList._itemName = 'post';
|
|
|
|
|
2016-06-17 20:25:44 +02:00
|
|
|
module.exports = PostList;
|