I have the following code which is attempting to store 2 types of object to the moralis database, but I am getting the following error message
FAILED@Event Error: XMLHttpRequest failed: “this.$d.toISOString is not a function” at handleError (RESTController.js:457)
Here is the code I have written:
import Moralis from 'moralis';
import { hash } from 'object-hash';
const Ticket = Moralis.Object.extend('Ticket');
const Event = Moralis.Object.extend('Event');
const uploadFileToIPFS = async (image) => {
const imageFile = new Blob(image.src, { type: 'image/png' });
const fileName = `${hash(imageFile)}.png`;
const moralisFile = new Moralis.File(fileName, imageFile);
await moralisFile.saveIPFS();
return moralisFile;
};
export const createEventAndTickets = async (
eventName,
eventDescription,
eventDate,
eventOrganiser,
eventVenue,
eventTickets
) => {
const event = new Event();
event.set('eventName', eventName);
event.set('eventDescription', eventDescription);
event.set('eventDate', eventDate);
event.set('eventVenue', eventVenue);
event.set('eventOrganiser', eventOrganiser);
event.save().then(
(event) => {
const eventId = event.id;
console.log('got to here');
console.log('New event created with id: ' + eventId);
eventTickets.forEach((x) => {
const ticketX = new Ticket();
const {
timestamp,
art,
ticketPrice,
fontColor,
color1,
color2,
ticketQuantity,
ticketName,
} = x;
if (art) {
const imageFile = uploadFileToIPFS(art);
ticketX.set('art', imageFile);
ticketX.set('artURL', imageFile.ipfs());
console.log(imageFile.ipfs());
}
ticketX.set('eventId', eventId);
ticketX.set('timestamp', timestamp);
ticketX.set('ticketPrice', ticketPrice);
ticketX.set('fontColor', fontColor);
ticketX.set('color1', color1);
ticketX.set('color2', color2);
ticketX.set('ticketName', ticketName);
ticketX.set('ticketQuantity', ticketQuantity);
ticketX.set('numberMinted', 0);
ticketX.save().then(
(ticket) => console.log('New ticket created with id: ' + ticket.id),
(err) => console.error('FAILED@Ticket', err)
);
});
},
(err) => console.error('FAILED@Event', err)
);
};