summaryrefslogtreecommitdiffstats
path: root/js/service/ShareResource.js
blob: ff390a9e2a110f36da320d646e827f336e8e25c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
 * Nextcloud - News
 *
 * @author Marco Nassabain <marco.nassabain@hotmail.com>
 * @author Nicolas Wendling <nicolas.wendling1011@gmail.com>
 */
app.factory('ShareResource', function (Resource, $http, BASE_URL) {
    'use strict';

    var ShareResource = function ($http, BASE_URL) {
        Resource.call(this, $http, BASE_URL);
    };

    ShareResource.prototype = Object.create(Resource.prototype);

    ShareResource.prototype.getUsers = function (search) {
        return this.http({
            url: OC.linkToOCS(`apps/files_sharing/api/v1/sharees?search=${search}&itemType=news_item&perPage=5`, 1),
            method: 'GET',
        }).then(function(response) {
            return response.data;
        });
    };

    ShareResource.prototype.shareItem = function (itemId, userId) {
        var url = this.BASE_URL +
            '/items/' + itemId + '/share/' + userId;

        return this.http({
            url: url,
            method: 'POST',
        });
    };


    return new ShareResource($http, BASE_URL);
});