- Routes to populate/depopulate demo event/item data
This commit is contained in:
156
fixtures/item.js
156
fixtures/item.js
@@ -1,37 +1,123 @@
|
||||
const item = {
|
||||
eventId: 'x9374bdH93u3ihds453s',
|
||||
title: 'Stay Local, Get Away!',
|
||||
subtitle: 'A romantic weekend for two at the Malden Econolodge!',
|
||||
donor: 'Charlie Baker',
|
||||
description: 'There may be bedbugs, there is absolutely no continental breakfast, and bring earplugs to sleep through police actions. A luxurious courtyard double.',
|
||||
images: [
|
||||
{ url: 'https://random.pics/chdgfj' },
|
||||
{ url: 'https://random.pics/745gdf' },
|
||||
{ url: 'https://random.pics/34sd56' },
|
||||
],
|
||||
type: 'auction',
|
||||
quantityAvailable: 1,
|
||||
soldCount: 0,
|
||||
currentPrice: 125,
|
||||
startingPrice: 100,
|
||||
reservePrice: 199,
|
||||
estimatedValue: 225.49,
|
||||
currentWinner: 'mifi',
|
||||
bidders: [
|
||||
{ name: 'mifi' },
|
||||
{ name: 'mifi79' },
|
||||
],
|
||||
bidCount: 2,
|
||||
bidIncrement: 5,
|
||||
catalogNumber: 16,
|
||||
start: Date.now(),
|
||||
end: Date.now() + (3*60*60*1000),
|
||||
hideBeforeStart: false,
|
||||
hideAfterEnd: true,
|
||||
notifyOnAvailable: false,
|
||||
isShippable: true,
|
||||
shippingCost: 25.68,
|
||||
organizationTake: 0.75,
|
||||
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,
|
||||
};
|
||||
};
|
||||
|
||||
module.exports = item;
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user