bkper-js 1.11.0 → 1.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.ts +18 -0
- package/lib/model/Collection.js +43 -0
- package/lib/service/collection-service.js +21 -0
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -849,6 +849,18 @@ export declare class Collection {
|
|
|
849
849
|
* @returns All Books of this collection.
|
|
850
850
|
*/
|
|
851
851
|
getBooks(): Book[];
|
|
852
|
+
/**
|
|
853
|
+
* Adds Books to this Collection.
|
|
854
|
+
*
|
|
855
|
+
* @returns The added Book objects
|
|
856
|
+
*/
|
|
857
|
+
addBooks(books: Book[]): Promise<Book[]>;
|
|
858
|
+
/**
|
|
859
|
+
* Removes Books from this Collection.
|
|
860
|
+
*
|
|
861
|
+
* @returns The removed Book objects
|
|
862
|
+
*/
|
|
863
|
+
removeBooks(books: Book[]): Promise<Book[]>;
|
|
852
864
|
/**
|
|
853
865
|
* Gets the last update date of this Collection
|
|
854
866
|
*
|
|
@@ -867,6 +879,12 @@ export declare class Collection {
|
|
|
867
879
|
* @returns The updated Collection object
|
|
868
880
|
*/
|
|
869
881
|
update(): Promise<Collection>;
|
|
882
|
+
/**
|
|
883
|
+
* Performs delete Collection.
|
|
884
|
+
*
|
|
885
|
+
* @returns The list of Books the user has access to that were affected by the deletion of this Collection
|
|
886
|
+
*/
|
|
887
|
+
remove(): Promise<Book[]>;
|
|
870
888
|
}
|
|
871
889
|
|
|
872
890
|
/**
|
package/lib/model/Collection.js
CHANGED
|
@@ -75,6 +75,38 @@ export class Collection {
|
|
|
75
75
|
}
|
|
76
76
|
return books;
|
|
77
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* Adds Books to this Collection.
|
|
80
|
+
*
|
|
81
|
+
* @returns The added Book objects
|
|
82
|
+
*/
|
|
83
|
+
addBooks(books) {
|
|
84
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
85
|
+
const collectionId = this.getId();
|
|
86
|
+
if (collectionId && books.length > 0) {
|
|
87
|
+
const bookList = { items: books.map(b => b.json()) };
|
|
88
|
+
let addedBooks = yield CollectionService.addBooksToCollection(collectionId, bookList);
|
|
89
|
+
return addedBooks.map(book => new Book(book));
|
|
90
|
+
}
|
|
91
|
+
return [];
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Removes Books from this Collection.
|
|
96
|
+
*
|
|
97
|
+
* @returns The removed Book objects
|
|
98
|
+
*/
|
|
99
|
+
removeBooks(books) {
|
|
100
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
+
const collectionId = this.getId();
|
|
102
|
+
if (collectionId && books.length > 0) {
|
|
103
|
+
const bookList = { items: books.map(b => b.json()) };
|
|
104
|
+
let removedBooks = yield CollectionService.removeBooksFromCollection(collectionId, bookList);
|
|
105
|
+
return removedBooks.map(book => new Book(book));
|
|
106
|
+
}
|
|
107
|
+
return [];
|
|
108
|
+
});
|
|
109
|
+
}
|
|
78
110
|
/**
|
|
79
111
|
* Gets the last update date of this Collection
|
|
80
112
|
*
|
|
@@ -105,5 +137,16 @@ export class Collection {
|
|
|
105
137
|
return this;
|
|
106
138
|
});
|
|
107
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Performs delete Collection.
|
|
142
|
+
*
|
|
143
|
+
* @returns The list of Books the user has access to that were affected by the deletion of this Collection
|
|
144
|
+
*/
|
|
145
|
+
remove() {
|
|
146
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
147
|
+
let books = yield CollectionService.deleteCollection(this.payload);
|
|
148
|
+
return books.map(book => new Book(book));
|
|
149
|
+
});
|
|
150
|
+
}
|
|
108
151
|
}
|
|
109
152
|
//# sourceMappingURL=Collection.js.map
|
|
@@ -27,4 +27,25 @@ export function updateCollection(payload) {
|
|
|
27
27
|
return response.data;
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
|
+
export function deleteCollection(payload) {
|
|
31
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
32
|
+
var _a;
|
|
33
|
+
let response = yield new HttpApiV5Request(`collections/${payload.id}`).setMethod('DELETE').fetch();
|
|
34
|
+
return ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
export function addBooksToCollection(collectionId, payload) {
|
|
38
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
39
|
+
var _a;
|
|
40
|
+
let response = yield new HttpApiV5Request(`collections/${collectionId}/books/add`).setMethod('PATCH').setPayload(payload).fetch();
|
|
41
|
+
return ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
export function removeBooksFromCollection(collectionId, payload) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
var _a;
|
|
47
|
+
let response = yield new HttpApiV5Request(`collections/${collectionId}/books/remove`).setMethod('PATCH').setPayload(payload).fetch();
|
|
48
|
+
return ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.items) || [];
|
|
49
|
+
});
|
|
50
|
+
}
|
|
30
51
|
//# sourceMappingURL=collection-service.js.map
|