Skip to content

Instantly share code, notes, and snippets.

@matthijskooijman
Created April 22, 2020 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthijskooijman/3c021d57fb161e0465f3e48de5a7a0d5 to your computer and use it in GitHub Desktop.
Save matthijskooijman/3c021d57fb161e0465f3e48de5a7a0d5 to your computer and use it in GitHub Desktop.
var authz = 'Insert value of Authorization header here'
var url = 'https://api.eventix.io/3.0.0/shop/' + new URLSearchParams(window.location.search).get('editing');
function fetch_tickets() {return fetch(new Request(url + '/tickets', {'headers': {'Authorization': authz}})).then(response => response.json())}
function order_tickets(a, b) {return fetch(new Request(url + '/tickets/reorder', {'headers': {'Authorization': authz, 'Content-Type': 'application/json;charset=UTF-8'}, 'body': JSON.stringify({'predecessor': a.guid, 'successor': b.guid}), 'method': 'PUT'}))}
async function sort() {tickets = await fetch_tickets(); tickets.sort((a, b) => a.name.localeCompare(b.name)); for (let i = 0; i < tickets.length - 1; ++i) { await order_tickets(tickets[i], tickets[tickets.length-1])}}
sort()
// Note: Printing fetch_tickets afterwards is not helpful, as the returned list is not sorted itself
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment