Created
April 22, 2020 17:24
-
-
Save matthijskooijman/3c021d57fb161e0465f3e48de5a7a0d5 to your computer and use it in GitHub Desktop.
This file contains 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
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