Skip to content

Commit 49c40ce

Browse files
committed
Added possibility to add and remove item images
1 parent 8686954 commit 49c40ce

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/bring.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,25 @@ class Bring {
217217
} // endCatch
218218
} // endSaveItem
219219

220+
/**
221+
* Save an image to an item
222+
*
223+
* @param formData The formdata you want to send.
224+
* @param itemUuid The itemUUID you want to update.
225+
* returns an imageUrl and answerHttpStatus should contain 204. If not -> error
226+
*/
227+
async saveItemImage(itemUuid: string, formData: { [key: string]: any } | undefined): Promise<{ imageUrl: string }> {
228+
try {
229+
const data = await request.put(`${this.url}bringlistitemdetails/${itemUuid}/image`, {
230+
headers: this.putHeaders,
231+
formData: formData
232+
});
233+
return JSON.parse(data);
234+
} catch (e: any) {
235+
throw new Error(`Cannot save item image ${itemUuid}: ${e.message}`);
236+
} // endCatch
237+
} // endSaveItemImage
238+
220239
/**
221240
* remove an item from your current shopping list
222241
*
@@ -236,6 +255,20 @@ class Bring {
236255
} // endCatch
237256
} // endRemoveItem
238257

258+
/**
259+
* Remove the image from your item
260+
*
261+
* @param itemUuid The itemUUID you want to remove the image from.
262+
* returns an empty string and answerHttpStatus should contain 204. If not -> error
263+
*/
264+
async removeItemImage(itemUuid: string): Promise<string> {
265+
try {
266+
return await request.delete(`${this.url}bringlistitemdetails/${itemUuid}/image`);
267+
} catch (e: any) {
268+
throw new Error(`Cannot remove item image ${itemUuid}: ${e.message}`);
269+
} // endCatch
270+
} // endRemoveItemImage
271+
239272
/**
240273
* move an item to recent items list
241274
*

0 commit comments

Comments
 (0)