mirror of
https://github.com/janishutz/libreevent.git
synced 2025-11-25 05:14:23 +00:00
completely re-engineered backend for tickets
This commit is contained in:
@@ -28,12 +28,10 @@ class GETHandler {
|
|||||||
} );
|
} );
|
||||||
} else if ( call === 'getReservedSeats' ) {
|
} else if ( call === 'getReservedSeats' ) {
|
||||||
if ( query.event ) {
|
if ( query.event ) {
|
||||||
db.getJSONDataSimple( 'booked', query.event ).then( data => {
|
db.getDataSimple( 'temp', 'user_id', session.id ).then( dat => {
|
||||||
db.getDataSimple( 'temp', 'user_id', session.id ).then( dat => {
|
resolve( { 'user': dat[ 0 ] ? JSON.parse( dat[ 0 ].data )[ query.event ] ?? {} : {} } );
|
||||||
resolve( { 'booked': data ?? {}, 'user': dat[ 0 ] ? JSON.parse( dat[ 0 ].data )[ query.event ] ?? {} : {} } );
|
} ).catch( () => {
|
||||||
} );
|
reject( { 'code': 500, 'message': 'ERR_DB' } );
|
||||||
} ).catch( error => {
|
|
||||||
reject( { 'code': 500, 'message': error } );
|
|
||||||
} );
|
} );
|
||||||
} else {
|
} else {
|
||||||
reject( { 'code': 400, 'message': 'Bad request, missing event query' } );
|
reject( { 'code': 400, 'message': 'Bad request, missing event query' } );
|
||||||
|
|||||||
@@ -7,81 +7,111 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const path = require( 'path' );
|
||||||
const db = require( '../db/db.js' );
|
const db = require( '../db/db.js' );
|
||||||
|
const fs = require( 'fs' );
|
||||||
|
|
||||||
class POSTHandler {
|
class POSTHandler {
|
||||||
constructor () {
|
constructor () {
|
||||||
this.allSelectedSeats = { 'test2': { 'secAr1s1': { 'id': 'secAr1s1', 'component': 1 } } };
|
db.getJSONData( 'booked' ).then( dat => {
|
||||||
|
this.allSelectedSeats = dat;
|
||||||
|
} );
|
||||||
|
// this.allSelectedSeats = { 'test2': { 'secAr1s1': { 'id': 'secAr1s1', 'component': 1 } } };
|
||||||
this.ticketTotals = { 'test2': { 'ticket1': 5, 'ticket2': 5 } };
|
this.ticketTotals = { 'test2': { 'ticket1': 5, 'ticket2': 5 } };
|
||||||
this.settings = { 'maxTickets': 10 };
|
this.settings = JSON.parse( fs.readFileSync( path.join( __dirname + '/../../config/settings.config.json' ) ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add lang in the future
|
// Add lang in the future
|
||||||
handleCall ( call, data, session ) {
|
handleCall ( call, data, session ) {
|
||||||
return new Promise( ( resolve, reject ) => {
|
return new Promise( ( resolve, reject ) => {
|
||||||
if ( call === 'reserveTicket' ) {
|
if ( call === 'reserveTicket' ) {
|
||||||
// TODO: Completely rework to optimize for speed.
|
if ( data.count || data.count === 0 ) {
|
||||||
db.getDataSimple( 'temp', 'user_id', session.id ).then( dat => {
|
db.getDataSimple( 'temp', 'user_id', session.id ).then( dat => {
|
||||||
let transmit = {};
|
if ( dat[ 0 ] ) {
|
||||||
if ( dat.length > 0 ) {
|
let totalTicketsPerID = {};
|
||||||
transmit = JSON.parse( dat[ 0 ].data );
|
// sum up total of tickets per category (based on a sliced ID of the ticket selected,
|
||||||
}
|
// as ticketID is based on category and ageGroup)
|
||||||
|
let tickets = JSON.parse( dat[ 0 ].data )[ data.eventID ];
|
||||||
|
for ( let ticket in tickets ) {
|
||||||
|
if ( !totalTicketsPerID[ ticket.slice( 0, ticket.indexOf( '_' ) ) ] ) {
|
||||||
|
totalTicketsPerID[ ticket.slice( 0, ticket.indexOf( '_' ) ) ] = 0;
|
||||||
|
}
|
||||||
|
totalTicketsPerID[ ticket.slice( 0, ticket.indexOf( '_' ) ) ] += tickets[ ticket ].count;
|
||||||
|
}
|
||||||
|
|
||||||
|
const id = data.id.slice( 0, data.id.indexOf( '_' ) );
|
||||||
|
|
||||||
|
if ( !totalTicketsPerID[ id ] ) {
|
||||||
|
totalTicketsPerID[ id ] = 0;
|
||||||
|
}
|
||||||
|
totalTicketsPerID[ id ] += 1;
|
||||||
|
|
||||||
|
let totalTickets = 0;
|
||||||
|
for ( let category in totalTicketsPerID ) {
|
||||||
|
totalTickets += totalTicketsPerID[ category ];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( totalTickets <= this.settings.maxTickets ) {
|
||||||
|
if ( totalTicketsPerID[ id ] <= this.ticketTotals[ data.eventID ][ id ] ) {
|
||||||
|
let info = {};
|
||||||
|
info[ data.eventID ] = tickets;
|
||||||
|
if ( data.count < 1 ) {
|
||||||
|
if ( Object.keys( info[ data.eventID ] ).length < 1 ) {
|
||||||
|
delete info[ data.eventID ];
|
||||||
|
} else {
|
||||||
|
delete info[ data.eventID ][ data.id ];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
info[ data.eventID ][ data.id ] = data;
|
||||||
|
}
|
||||||
|
let ticketCount = data.count;
|
||||||
|
const maxTickets = this.ticketTotals[ data.eventID ][ data.id.slice( 0, data.id.indexOf( '_' ) ) ];
|
||||||
|
if ( ticketCount > maxTickets ) {
|
||||||
|
ticketCount = maxTickets;
|
||||||
|
}
|
||||||
|
if ( maxTickets > 0 ) {
|
||||||
|
db.writeDataSimple( 'temp', 'user_id', session.id, { 'user_id': session.id, 'timestamp': new Date().toDateString(), 'data': JSON.stringify( info ) } );
|
||||||
|
resolve( { 'status': 'ok', 'ticketCount': ticketCount } );
|
||||||
|
} else {
|
||||||
|
reject( { 'code': 409, 'message': 'ERR_ALL_OCCUPIED' } );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
reject( { 'code': 418, 'message': 'ERR_TOO_MANY_TICKETS' } );
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let info = {};
|
||||||
|
info[ data.eventID ] = {};
|
||||||
|
info[ data.eventID ][ data.id ] = data;
|
||||||
|
let ticketCount = data.count;
|
||||||
|
const maxTickets = this.ticketTotals[ data.eventID ][ data.id.slice( 0, data.id.indexOf( '_' ) ) ];
|
||||||
|
if ( ticketCount > maxTickets ) {
|
||||||
|
ticketCount = maxTickets;
|
||||||
|
}
|
||||||
|
if ( maxTickets > 0 ) {
|
||||||
|
db.writeDataSimple( 'temp', 'user_id', session.id, { 'user_id': session.id, 'timestamp': new Date().toDateString(), 'data': JSON.stringify( info ) } );
|
||||||
|
resolve( { 'status': 'ok', 'ticketCount': ticketCount } );
|
||||||
|
} else {
|
||||||
|
reject( { 'code': 409, 'message': 'ERR_ALL_OCCUPIED' } );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} );
|
||||||
|
} else {
|
||||||
if ( !this.allSelectedSeats[ data.eventID ] ) {
|
if ( !this.allSelectedSeats[ data.eventID ] ) {
|
||||||
this.allSelectedSeats[ data.eventID ] = {};
|
this.allSelectedSeats[ data.eventID ] = {};
|
||||||
}
|
}
|
||||||
|
if ( this.allSelectedSeats[ data.eventID ][ data.id ] ) {
|
||||||
if ( !transmit[ data.eventID ] ) {
|
reject( { 'code': 409, 'message': 'ERR_ALREADY_SELECTED' } );
|
||||||
transmit[ data.eventID ] = {};
|
} else {
|
||||||
|
let info = {};
|
||||||
|
info[ data.eventID ] = {};
|
||||||
|
info[ data.eventID ][ data.id ] = data;
|
||||||
|
db.writeDataSimple( 'temp', 'user_id', session.id, { 'user_id': session.id, 'timestamp': new Date().toDateString(), 'data': JSON.stringify( info ) } ).catch( err => {
|
||||||
|
console.error( err );
|
||||||
|
} );
|
||||||
|
resolve( 'ok' );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if ( this.allSelectedSeats[ data.eventID ][ data.id ] && !data.count ) {
|
|
||||||
reject( { 'code': 409, 'message': 'ERR_SEAT_SELECTED' } );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
db.getJSONDataSimple( 'booked', data.eventID ).then( booked => {
|
|
||||||
transmit[ data.eventID ][ data.id ] = data;
|
|
||||||
// TODO: Prevent seat selection if already taken (also if in booked!)
|
|
||||||
// TODO: Respect max ticket count per user
|
|
||||||
// TODO: maybe move to per event setting
|
|
||||||
let totalUserTickets = 0;
|
|
||||||
for ( let event in transmit ) {
|
|
||||||
for ( let ticket in transmit[ event ] ) {
|
|
||||||
totalUserTickets += transmit[ event ][ ticket ][ 'count' ] ?? 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( totalUserTickets <= this.settings.maxTickets ) {
|
|
||||||
if ( data.count ) {
|
|
||||||
if ( this.ticketTotals[ data.eventID ] ) {
|
|
||||||
if ( data.count <= ( this.ticketTotals[ data.eventID ][ data.id.slice( 0, data.id.indexOf( '_' ) ) ] ?? 1 ) ) {
|
|
||||||
transmit[ data.eventID ][ data.id ][ 'count' ] = data.count;
|
|
||||||
this.allSelectedSeats[ data.eventID ].push( { 'id': data.id, 'component': data.component, 'count': data.count } );
|
|
||||||
} else {
|
|
||||||
reject( { 'code': 409, 'message': this.ticketTotals[ data.eventID ] ?? 1 } );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
reject( { 'code': 400, 'message': 'ERR_UNKNOWN_EVENT' } );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.allSelectedSeats[ data.eventID ].push( { 'id': data.id, 'component': data.component } );
|
|
||||||
}
|
|
||||||
db.writeDataSimple( 'temp', 'user_id', session.id, { 'user_id': session.id, 'data': JSON.stringify( transmit ), 'timestamp': new Date().toString() } ).then( () => {
|
|
||||||
resolve( 'ok' );
|
|
||||||
} ).catch( error => {
|
|
||||||
console.error( error );
|
|
||||||
reject( { 'code': 500, 'message': 'ERR_DB' } );
|
|
||||||
} );
|
|
||||||
} else {
|
|
||||||
reject( { 'code': 418, 'message': 'ERR_TOO_MANY_TICKETS' } );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
} ).catch( error => {
|
|
||||||
console.error( error );
|
|
||||||
reject( { 'code': 500, 'message': 'ERR_DB' } );
|
|
||||||
} );
|
|
||||||
} else if ( call === 'deselectTicket' ) {
|
} else if ( call === 'deselectTicket' ) {
|
||||||
db.getDataSimple( 'temp', 'user_id', session.id ).then( dat => {
|
db.getDataSimple( 'temp', 'user_id', session.id ).then( dat => {
|
||||||
let transmit = {};
|
let transmit = {};
|
||||||
@@ -111,9 +141,7 @@ class POSTHandler {
|
|||||||
} else {
|
} else {
|
||||||
reject( { 'code': 404, 'message': 'ERR_DATA_NOT_FOUND' } );
|
reject( { 'code': 404, 'message': 'ERR_DATA_NOT_FOUND' } );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
db.writeDataSimple( 'temp', 'user_id', session.id, { 'user_id': session.id, 'data': JSON.stringify( transmit ) } ).then( () => {
|
db.writeDataSimple( 'temp', 'user_id', session.id, { 'user_id': session.id, 'data': JSON.stringify( transmit ) } ).then( () => {
|
||||||
resolve( 'ok' );
|
resolve( 'ok' );
|
||||||
@@ -130,7 +158,7 @@ class POSTHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getReservedSeats ( event ) {
|
getReservedSeats ( event ) {
|
||||||
return Object.values( this.allSelectedSeats[ event ] );
|
return this.allSelectedSeats[ event ] ? Object.values( this.allSelectedSeats[ event ] ) : {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,5 +7,5 @@
|
|||||||
"name": "libreevent",
|
"name": "libreevent",
|
||||||
"yourDomain": "http://localhost:8080",
|
"yourDomain": "http://localhost:8080",
|
||||||
"mailSender": "libreevent <info@libreevent.janishutz.com>",
|
"mailSender": "libreevent <info@libreevent.janishutz.com>",
|
||||||
"maxTickets": 3
|
"maxTickets": 10
|
||||||
}
|
}
|
||||||
@@ -1,23 +1,24 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="seatingWrapper">
|
<div class="seatingWrapper">
|
||||||
<sideCartView :cart="cart" ref="cart"></sideCartView>
|
<sideCartView :cart="cart" :name="event.name" ref="cart"></sideCartView>
|
||||||
<div class="noseatplan">
|
<div class="noseatplan">
|
||||||
<h3>Available tickets</h3>
|
<h2>Available tickets</h2>
|
||||||
|
<button @click="cartHandling()">Add selected tickets to cart</button>
|
||||||
<div class="wrapper">
|
<div class="wrapper">
|
||||||
<div v-for="ticket in tickets">
|
<div v-for="ticket in tickets">
|
||||||
{{ event[ 'categories' ][ ticket.category ][ 'name' ] }}
|
{{ event[ 'categories' ][ ticket.category ][ 'name' ] }}
|
||||||
<table>
|
<table>
|
||||||
<tr v-for="ticketOption in event[ 'ageGroups' ]">
|
<tr v-for="ticketOption in event[ 'ageGroups' ]">
|
||||||
<td>
|
<td>
|
||||||
{{ ticketOption.name }} <div style="display: inline" v-if="ticketOption.age">({{ ticketOption.age }})</div>
|
{{ ticketOption.name }} <div style="display: inline" v-if="ticketOption.age">({{ ticketOption.age }} years)</div>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ event.currency }} {{ event[ 'categories' ][ ticket.category ][ 'price' ][ ticketOption.id ] }}
|
{{ event.currency }} {{ event[ 'categories' ][ ticket.category ][ 'price' ][ ticketOption.id ] }}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<span class="material-symbols-outlined controls" @click="selectTicket( ticket.id, ticketOption.id )">add</span>
|
<span class="material-symbols-outlined controls" @click="ticketHandling( ticket.id, ticketOption.id, 'select' )">add</span>
|
||||||
{{ cart[ event.eventID ] ? ( cart[ event.eventID ][ 'tickets' ][ ticket.id + '_' + ticketOption.id ] ? cart[ event.eventID ][ 'tickets' ][ ticket.id + '_' + ticketOption.id ][ 'count' ] : 0 ) : 0 }}
|
{{ selectedTickets[ ticket.id + '_' + ticketOption.id ] ?? 0 }}
|
||||||
<span class="material-symbols-outlined controls" @click="deselectTicket( ticket.id, ticketOption.id )">remove</span>
|
<span class="material-symbols-outlined controls" @click="ticketHandling( ticket.id, ticketOption.id, 'deselect' )">remove</span>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
@@ -46,59 +47,108 @@ export default {
|
|||||||
tickets: { 'ticket1': { 'name': 'Ticket 1', 'id': 'ticket1', 'category': 1, 'free': 20 }, 'ticket2': { 'name': 'Ticket 2', 'id': 'ticket2', 'category': 2, 'free': 20 } },
|
tickets: { 'ticket1': { 'name': 'Ticket 1', 'id': 'ticket1', 'category': 1, 'free': 20 }, 'ticket2': { 'name': 'Ticket 2', 'id': 'ticket2', 'category': 2, 'free': 20 } },
|
||||||
event: { 'name': 'TestEvent2', 'location': 'TestLocation2', 'eventID': 'test2', 'date': '2023-07-15', 'currency': 'CHF', 'categories': { '1': { 'price': { '1':25, '2':35 }, 'bg': 'black', 'fg': 'white', 'name': 'Category 1' }, '2': { 'price': { '1':15, '2':20 }, 'bg': 'green', 'fg': 'white', 'name': 'Category 2' } }, 'ageGroups': { '1':{ 'id': 1, 'name':'Child', 'age':'0 - 15.99' }, '2':{ 'id': 2, 'name': 'Adult' } }, 'maxTickets': 2 },
|
event: { 'name': 'TestEvent2', 'location': 'TestLocation2', 'eventID': 'test2', 'date': '2023-07-15', 'currency': 'CHF', 'categories': { '1': { 'price': { '1':25, '2':35 }, 'bg': 'black', 'fg': 'white', 'name': 'Category 1' }, '2': { 'price': { '1':15, '2':20 }, 'bg': 'green', 'fg': 'white', 'name': 'Category 2' } }, 'ageGroups': { '1':{ 'id': 1, 'name':'Child', 'age':'0 - 15.99' }, '2':{ 'id': 2, 'name': 'Adult' } }, 'maxTickets': 2 },
|
||||||
cart: {},
|
cart: {},
|
||||||
|
selectedTickets: {},
|
||||||
|
maxTickets: 10,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
selectTicket( id, option ) {
|
ticketHandling( id, option, operation ) {
|
||||||
let totalTicketsPerID = 0;
|
if ( operation === 'select' ) {
|
||||||
if ( this.cart[ this.event.eventID ] ) {
|
let totalTicketsPerID = {};
|
||||||
if ( this.cart[ this.event.eventID ][ 'tickets' ][ id + '_' + option ] ) {
|
// sum up total of tickets per category (based on a sliced ID of the ticket selected,
|
||||||
const tickets = this.cart[ this.event.eventID ][ 'tickets' ];
|
// as ticketID is based on category and ageGroup)
|
||||||
for ( let ticket in tickets ) {
|
for ( let ticket in this.selectedTickets ) {
|
||||||
if ( tickets[ ticket ][ 'id' ].split( '_' )[ 0 ] === id ) {
|
if ( !totalTicketsPerID[ ticket.slice( 0, ticket.indexOf( '_' ) ) ] ) {
|
||||||
totalTicketsPerID += this.cart[ this.event.eventID ][ 'tickets' ][ tickets[ ticket ][ 'id' ] ][ 'count' ];
|
totalTicketsPerID[ ticket.slice( 0, ticket.indexOf( '_' ) ) ] = 0;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ( totalTicketsPerID < this.tickets[ id ].free ) {
|
totalTicketsPerID[ ticket.slice( 0, ticket.indexOf( '_' ) ) ] += this.selectedTickets[ ticket ];
|
||||||
this.cartHandling( 'select', this.tickets[ id ], option );
|
}
|
||||||
|
|
||||||
|
if ( !totalTicketsPerID[ id ] ) {
|
||||||
|
totalTicketsPerID[ id ] = 0;
|
||||||
|
}
|
||||||
|
totalTicketsPerID[ id ] += 1;
|
||||||
|
|
||||||
|
let totalTickets = 0;
|
||||||
|
for ( let category in totalTicketsPerID ) {
|
||||||
|
totalTickets += totalTicketsPerID[ category ];
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( totalTickets <= this.maxTickets ) {
|
||||||
|
if ( totalTicketsPerID[ id ] <= this.tickets[ id ][ 'free' ] ) {
|
||||||
|
if ( !this.selectedTickets[ id + '_' + option ] ) {
|
||||||
|
this.selectedTickets[ id + '_' + option ] = 0;
|
||||||
|
}
|
||||||
|
this.selectedTickets[ id + '_' + option ] += 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.cartHandling( 'select', this.tickets[ id ], option );
|
this.$refs.popups.openPopup( 'We are sorry, but you have already selected the maximum amount of tickets you can buy at once.', {}, 'string' );
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.cartHandling( 'select', this.tickets[ id ], option );
|
if ( !this.selectedTickets[ id + '_' + option ] || this.selectedTickets[ id + '_' + option ] === 0 ) {
|
||||||
|
this.selectedTickets[ id + '_' + option ] = 0;
|
||||||
|
} else {
|
||||||
|
this.selectedTickets[ id + '_' + option ] -= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
cartHandling ( operation, data, option ) {
|
cartHandling () {
|
||||||
if ( operation === 'select' ) {
|
for ( let ticket in this.selectedTickets ) {
|
||||||
// TODO: Redo to optimize speed and server load
|
|
||||||
const options = {
|
const options = {
|
||||||
method: 'post',
|
method: 'post',
|
||||||
body: JSON.stringify( { 'id': data.id + '_' + option, 'component': data.category, 'ticketOption': option, 'eventID': this.event.eventID, 'count': ( this.cart[ this.event.eventID ] ? ( this.cart[ this.event.eventID ][ 'tickets' ][ data.id + '_' + option ] ? this.cart[ this.event.eventID ][ 'tickets' ][ data.id + '_' + option ][ 'count' ] : 0 ) : 0 ) + 1, 'category': data.category, 'name': 'Ticket ' + data.category + ' (' + this.event.ageGroups[ option ].name + ')' } ),
|
body: JSON.stringify( {
|
||||||
|
'id': ticket,
|
||||||
|
'component': 1,
|
||||||
|
'ticketOption': ticket.substring( ticket.indexOf( '_' ) + 1 ),
|
||||||
|
'eventID': this.event.eventID,
|
||||||
|
'count': this.selectedTickets[ ticket ],
|
||||||
|
'category': this.tickets[ ticket.slice( 0, ticket.indexOf( '_' ) ) ].category,
|
||||||
|
'name': this.tickets[ ticket.slice( 0, ticket.indexOf( '_' ) ) ].name + ' (' + this.event.ageGroups[ ticket.substring( ticket.indexOf( '_' ) + 1 ) ].name + ')',
|
||||||
|
} ),
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json',
|
'Content-Type': 'application/json',
|
||||||
'charset': 'utf-8'
|
'charset': 'utf-8'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetch( localStorage.getItem( 'url' ) + '/API/reserveTicket', options ).then( res => {
|
fetch( localStorage.getItem( 'url' ) + '/API/reserveTicket', options ).then( res => {
|
||||||
|
if ( !this.cart[ this.event.eventID ] ) {
|
||||||
|
this.cart[ this.event.eventID ] = { 'displayName': this.event.name, 'tickets': {}, 'eventID': this.event.eventID };
|
||||||
|
}
|
||||||
if ( res.status === 200 ) {
|
if ( res.status === 200 ) {
|
||||||
if ( this.cart[ this.event.eventID ] ) {
|
// add item to cart
|
||||||
if ( this.cart[ this.event.eventID ][ 'tickets' ][ data.id + '_' + option ] ) {
|
if ( this.selectedTickets[ ticket ] < 1 ) {
|
||||||
this.cart[ this.event.eventID ][ 'tickets' ][ data.id + '_' + option ][ 'count' ] += 1;
|
if ( Object.keys( this.cart[ this.event.eventID ][ 'tickets' ] ).length < 1 ) {
|
||||||
|
try {
|
||||||
|
delete this.cart[ this.event.eventID ];
|
||||||
|
} catch {}
|
||||||
} else {
|
} else {
|
||||||
this.cart[ this.event.eventID ][ 'tickets' ][ data.id + '_' + option ] = { 'displayName': data.name + ' (' + this.event.ageGroups[ option ].name + ')', 'price': this.event.categories[ data.category ].price[ option ], 'id': data.id + '_' + option, 'count': 1 };
|
delete this.cart[ this.event.eventID ][ 'tickets' ][ ticket ];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.cart[ this.event.eventID ] = { 'displayName': this.event.name, 'tickets': {} };
|
this.cart[ this.event.eventID ][ 'tickets' ][ ticket ] = {
|
||||||
this.cart[ this.event.eventID ][ 'tickets' ][ data.id + '_' + option ] = { 'displayName': data.name + ' (' + this.event.ageGroups[ option ].name + ')', 'price': this.event.categories[ data.category ].price[ option ], 'id': data.id + '_' + option, 'count': 1 };
|
'displayName': this.tickets[ ticket.slice( 0, ticket.indexOf( '_' ) ) ].name + ' (' + this.event.ageGroups[ ticket.substring( ticket.indexOf( '_' ) + 1 ) ].name + ')',
|
||||||
|
'price': this.event.categories[ this.tickets[ ticket.slice( 0, ticket.indexOf( '_' ) ) ].category ].price[ ticket.substring( ticket.indexOf( '_' ) + 1 ) ],
|
||||||
|
'id': ticket,
|
||||||
|
'count': this.selectedTickets[ ticket ],
|
||||||
|
'comp': 1,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
} else if ( res.status === 409 ) {
|
} else if ( res.status === 409 ) {
|
||||||
|
res.json().then( dat => {
|
||||||
|
this.cart[ this.event.eventID ][ 'tickets' ][ ticket ] = {
|
||||||
|
'displayName': this.tickets[ ticket.slice( 0, ticket.indexOf( '_' ) ) ].name + ' (' + this.event.ageGroups[ ticket.substring( ticket.indexOf( '_' ) + 1 ) ].name + ')',
|
||||||
|
'price': this.event.categories[ this.tickets[ ticket.slice( 0, ticket.indexOf( '_' ) ) ].category ].price[ ticket.substring( ticket.indexOf( '_' ) + 1 ) ],
|
||||||
|
'id': ticket,
|
||||||
|
'count': dat.count,
|
||||||
|
'comp': 1,
|
||||||
|
};
|
||||||
|
} );
|
||||||
setTimeout( () => {
|
setTimeout( () => {
|
||||||
this.$refs.popups.openPopup( 'Unfortunately, the ticket you just tried to select was reserved by somebody else since the last time the free ticket counts were refreshed. Please select a ticket from another price category. We are sorry for the inconvenience.', {}, 'string' );
|
this.$refs.popups.openPopup( 'Unfortunately, you have selected more tickets than were still available. The maximum amount of tickets that are available have been selected for you automatically. We are sorry for the inconvenience.', {}, 'string' );
|
||||||
}, 300 );
|
}, 300 );
|
||||||
} else if ( res.status === 418 ) {
|
} else if ( res.status === 418 ) {
|
||||||
setTimeout( () => {
|
setTimeout( () => {
|
||||||
this.$refs.popups.openPopup( 'You have reached the maximum amount of tickets allowed for a single purchase.', {}, 'string' );
|
this.$refs.popups.openPopup( 'We are sorry, but you have already selected the maximum amount of tickets you can buy at once.', {}, 'string' );
|
||||||
}, 300 );
|
}, 300 );
|
||||||
}
|
}
|
||||||
if ( Object.keys( this.cart[ this.event.eventID ][ 'tickets' ] ).length < 1 ) {
|
if ( Object.keys( this.cart[ this.event.eventID ][ 'tickets' ] ).length < 1 ) {
|
||||||
@@ -108,28 +158,7 @@ export default {
|
|||||||
this.$refs.cart.calculateTotal();
|
this.$refs.cart.calculateTotal();
|
||||||
localStorage.setItem( 'cart', JSON.stringify( this.cart ) );
|
localStorage.setItem( 'cart', JSON.stringify( this.cart ) );
|
||||||
} );
|
} );
|
||||||
} else if ( operation === 'deselect' ) {
|
|
||||||
if ( this.cart[ this.event.eventID ][ 'tickets' ][ data + '_' + option ][ 'count' ] === 1 ) {
|
|
||||||
delete this.cart[ this.event.eventID ][ 'tickets' ][ data + '_' + option ];
|
|
||||||
} else {
|
|
||||||
this.cart[ this.event.eventID ][ 'tickets' ][ data + '_' + option ][ 'count' ] -= 1;
|
|
||||||
}
|
|
||||||
if ( Object.keys( this.cart[ this.event.eventID ][ 'tickets' ] ).length < 1 ) {
|
|
||||||
delete this.cart[ this.event.eventID ];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
this.$refs.cart.calculateTotal();
|
|
||||||
localStorage.setItem( 'cart', JSON.stringify( this.cart ) );
|
|
||||||
},
|
|
||||||
deselectTicket( id, option ) {
|
|
||||||
if ( this.cart[ this.event.eventID ] ) {
|
|
||||||
if ( this.cart[ this.event.eventID ][ 'tickets' ][ id + '_' + option ] ) {
|
|
||||||
if ( this.cart[ this.event.eventID ][ 'tickets' ][ id + '_' + option ][ 'count' ] > 0 ) {
|
|
||||||
this.cartHandling( 'deselect', id, option );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// TODO: Make call to server to deselect ticket
|
|
||||||
},
|
},
|
||||||
loadTickets () {
|
loadTickets () {
|
||||||
// TODO: Load from server
|
// TODO: Load from server
|
||||||
|
|||||||
@@ -187,15 +187,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( let seat in data.booked ) {
|
|
||||||
if ( data.booked[ seat ] ) {
|
|
||||||
if ( !unavailableSeats[ data.booked[ seat ].component ] ) {
|
|
||||||
unavailableSeats[ data.booked[ seat ].component ];
|
|
||||||
}
|
|
||||||
unavailableSeats[ data.booked[ seat ].component ][ data.booked[ seat ].id ] = 'nav';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let tickets = {};
|
let tickets = {};
|
||||||
if ( this.cart[ this.event.eventID ] ) {
|
if ( this.cart[ this.event.eventID ] ) {
|
||||||
tickets = this.cart[ this.event.eventID ][ 'tickets' ];
|
tickets = this.cart[ this.event.eventID ][ 'tickets' ];
|
||||||
|
|||||||
@@ -50,7 +50,7 @@
|
|||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
hasSeatplan: false,
|
hasSeatplan: true,
|
||||||
eventID: '',
|
eventID: '',
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user