Skip to content

Instantly share code, notes, and snippets.

@lucaswerkmeister
Created June 6, 2018 16:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucaswerkmeister/5c584b1383ce04ae1d29ac02ef1f02b0 to your computer and use it in GitHub Desktop.
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
/**
* 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);
@lucaswerkmeister
Copy link
Author

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:

  • giving
  • lending
  • selling
  • inventorying

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment