Created
June 6, 2018 16:55
-
-
Save lucaswerkmeister/5c584b1383ce04ae1d29ac02ef1f02b0 to your computer and use it in GitHub Desktop.
inventaire.io: set the transaction status of all items by the current user to a certain status
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Set the transaction status of all items by the current user to the given status. | |
*/ | |
async function setTransaction(transaction) { | |
const userId = await fetch('https://inventaire.io/api/user', { credentials: 'include' }) | |
.then(response => response.json()) | |
.then(json => json._id); | |
const items = await fetch(`https://inventaire.io/api/items?action=by-users&users=${userId}`) | |
.then(response => response.json()) | |
.then(json => json.items); | |
for (const item of items) { | |
if (item.transaction === transaction) { | |
continue; | |
} | |
item.transaction = transaction; | |
await fetch('https://inventaire.io/api/items', { | |
method: 'PUT', | |
body: JSON.stringify(item), | |
credentials: 'include', | |
headers: { 'Content-Type': 'application/json' } | |
}) | |
} | |
} | |
setTransaction('inventorying').then(() => console.log('Done.')).catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: go to https://inventaire.io and paste this into the browser console (Ctrl+Shift+K) to set the status of all items to “inventorying”. If you want a different status, edit the final line. The valid status strings are: