I need help from some of you experienced folks. I am attempting to generate tickets that hold metadata in JSON format. I am a fairly new developer. My idea in this is to take a user and have them create an event with x amount of tickets. The user or our company will then enter the standard input info (venue name, artist name, select seat numbers, sections etc). I want to be able to generate thousands of tickets, each with the correct info that reflects the venue. In general how should I go about this?
Below is me messing around with ways to do this, but I don't have a lot of experience as you can see. I was able to get the tickets to put in String info, but not have seat numbers iterate and increase etc.
import { watchFile, writeFile } from "fs";
import fs from "fs";
class BlockPass_`enter code here`PermanentData {
constructor(venue_Name, artist_Name, genre) {
this.venue_Name = venue_Name;
this.artist_Name = artist_Name;
this.genre = genre;
}
}
let ticket_Omega = new BlockPass_PermanentData(
"Catalyst",
"As I Lay Dying",
"Post-Hardcore Metal"
);
const maxTickets = 10;
function makeTickets(maxTickets) {
const tickets = {};
for (let i = 0; i < maxTickets; i++) {
tickets[i] = ticket_Omega;
}
return tickets;
}
let tickets_Generated = makeTickets(maxTickets);
const ticket_MetaData = JSON.stringify(tickets_Generated);
console.log(ticket_MetaData);
writeFile("JSON/tickets_Omega.JSON", ticket_MetaData, function (err) {
if (err) throw err;
console.log("Omega Tickets generated. Begin Modifications.");
});
The main issue with your code is that you are setting all your tickets to the same object (ticket_Omega). You probably want to generate a new object for every ticket.
I would do something like this instead:
class Event {
constructor(venue_Name, artist_Name, genre) {
this.venue_Name = venue_Name;
this.artist_Name = artist_Name;
this.genre = genre;
}
makeTickets(maxTickets) {
const tickets = {};
for (let i = 0; i < maxTickets; i++) {
tickets[i] = {
seatNumber: i,
sold: false,
venue_Name: this.venue_Name,
artist_Name: this.artist_Name,
genre: this.genre,
};
}
return tickets;
}
}
const some_event = new Event("Catalyst", "As I Lay Dying", "Post-Hardcore Metal");
let tickets = some_event.makeTickets(10);
console.log(tickets);