const faker = require('faker'); const item = ({ donor, end, eventId, index, quantityAvailable, soldCount, start, startPrice, subtitle, title, type, }) => { const isAuction = type === 'auction'; const startingPrice = startPrice || faker.random.number({ min: 100, max: 500 }); const bidCount = isAuction ? faker.random.number({ min: 0, max: 5 }) : 0; const bidIncrement = isAuction ? faker.random.number({ min: 5, max: 100 }) : null; currentPrice = !isAuction ? null : startPrice; currentPrice = bidCount > 0 ? currentPrice + faker.random.number({ min: (bidIncrement * bidCount), max: (bidIncrement * bidCount * 4) }) : currentPrice; const estimatedValue = isAuction ? (startingPrice * faker.random.number({ min: 15, max: 20 })) : 0; const reservePrice = isAuction && faker.random.boolean() ? (startingPrice * faker.random.number({ min: 5, max: 10 })) : 0; const isShippable = faker.random.boolean(); return { eventId: eventId || faker.random.uuid(), title: title || faker.lorem.sentence(), subtitle: subtitle === false ? null : subtitle || faker.lorem.sentence(), donor: donor === false ? null : donor || faker.name.findName(), description: faker.lorem.sentences(faker.random.number({ min: 2, max: 5 }, '. ')), images: type === 'ticket' ? null : [ { url: faker.image.imageUrl(640, 480, 'cats', true, true) }, { url: faker.image.imageUrl(640, 480, 'cats', true, true) }, { url: faker.image.imageUrl(640, 480, 'cats', true, true) }, ], type: type || faker.random.arrayElement(), quantityAvailable: quantityAvailable || 1, soldCount: soldCount || 0, currentPrice: currentPrice === false ? null : faker.random.number({ }), startingPrice, reservePrice, estimatedValue, currentWinner: null, bidders: [], bidCount, bidIncrement, catalogNumber: index || null, start, end: end || start + (3*60*60*1000), hideBeforeStart: faker.random.boolean(), hideAfterEnd: faker.random.boolean(), notifyOnAvailable: faker.random.boolean(), isShippable, shippingCost: isShippable ? faker.random.number({ min: 5.5, max: 39.98 }) : null, organizationTake: isAuction ? faker.random.number({ min: 0.25, max: 1 }) : 1, }; }; const getItems = ({ eventId = faker.random.uuid(), auction = 10, ticket = 4, eventStart = Date.now(), eventEnd = (Date.now() + (3*60*60*1000)), }) => { let items = []; if (typeof ticket === 'number') { for (let i = 0; i < ticket; i++) { items.push(item({ donor: false, end: eventEnd, eventId, index: false, start: eventStart, subtitle: false, type: 'ticket', })); } } if (typeof ticket === 'object' && ticket.length) { for (let i = 0; i < ticket.length; i++) { items.push(item({ donor: false, end: ticket[i].endSale, eventId, index: false, quantityAvailable: ticket[i].capacity, soldCount: (ticket[i].capacity - ticket[i].available), start: ticket[i].startSale, startPrice: ticket[i].price, subtitle: false, type: 'ticket', title: ticket[i].name, })); } } if (typeof auction === 'number') { for (let i = 0; i < auction; i++) { items.push(item({ end: eventEnd, eventId, index: i, start: eventStart, type: 'auction', })); } } return items; }; module.exports = getItems;