bkper-js 1.11.0 → 1.13.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 +20 -2
- package/lib/model/Collection.js +43 -0
- package/lib/model/Transaction.js +6 -12
- 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
|
/**
|
|
@@ -1644,13 +1662,13 @@ export declare class Transaction {
|
|
|
1644
1662
|
*
|
|
1645
1663
|
* Adds a file attachment to the Transaction.
|
|
1646
1664
|
*
|
|
1647
|
-
* Files
|
|
1665
|
+
* Files MUST be previously created in the Book.
|
|
1648
1666
|
*
|
|
1649
1667
|
* @param file - The file to add
|
|
1650
1668
|
*
|
|
1651
1669
|
* @returns This Transaction, for chainning.
|
|
1652
1670
|
*/
|
|
1653
|
-
addFile(file: File):
|
|
1671
|
+
addFile(file: File): Transaction;
|
|
1654
1672
|
/**
|
|
1655
1673
|
* Check if the transaction has the specified tag.
|
|
1656
1674
|
*/
|
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
|
package/lib/model/Transaction.js
CHANGED
|
@@ -164,24 +164,18 @@ export class Transaction {
|
|
|
164
164
|
*
|
|
165
165
|
* Adds a file attachment to the Transaction.
|
|
166
166
|
*
|
|
167
|
-
* Files
|
|
167
|
+
* Files MUST be previously created in the Book.
|
|
168
168
|
*
|
|
169
169
|
* @param file - The file to add
|
|
170
170
|
*
|
|
171
171
|
* @returns This Transaction, for chainning.
|
|
172
172
|
*/
|
|
173
173
|
addFile(file) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
if (file.getId() == null) {
|
|
180
|
-
file = yield file.create();
|
|
181
|
-
}
|
|
182
|
-
this.payload.files.push(file.json());
|
|
183
|
-
return this;
|
|
184
|
-
});
|
|
174
|
+
if (this.payload.files == null) {
|
|
175
|
+
this.payload.files = [];
|
|
176
|
+
}
|
|
177
|
+
this.payload.files.push(file.json());
|
|
178
|
+
return this;
|
|
185
179
|
}
|
|
186
180
|
/**
|
|
187
181
|
* Check if the transaction has the specified tag.
|
|
@@ -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
|