- Routes to populate/depopulate demo event/item data
This commit is contained in:
89
fixtures/event.js
Normal file
89
fixtures/event.js
Normal file
@@ -0,0 +1,89 @@
|
||||
const faker = require('faker');
|
||||
|
||||
const capacities = {
|
||||
high: faker.random.number({ min: 400, max: 600 }),
|
||||
low: faker.random.number({ min: 125, max: 250 }),
|
||||
};
|
||||
|
||||
const dates = {
|
||||
near: faker.date.future(faker.random.number({ min: 0.125, max: 0.75 })),
|
||||
past: faker.date.recent(faker.random.number({ min: 3, max: 16 })),
|
||||
}
|
||||
|
||||
const getPosts = (number = 3) => {
|
||||
let posts = [];
|
||||
for (let i = 0; i < number; i++) {
|
||||
const date = faker.date.recent(faker.random.number({ min: 3, max: 16 }));
|
||||
const scheduledPost = faker.random.boolean();
|
||||
|
||||
posts.push({
|
||||
author: faker.name.findName(),
|
||||
title: faker.lorem.sentence(),
|
||||
content: faker.lorem.paragraphs(faker.random.number({ min: 3, max: 5 })),
|
||||
isPublic: faker.random.boolean(),
|
||||
scheduledPost: scheduledPost,
|
||||
sendNotification: scheduledPost ? faker.date.future(faker.random.number({ min: 0.125, max: 0.25 })) : null,
|
||||
timestamp: date,
|
||||
});
|
||||
}
|
||||
|
||||
return posts;
|
||||
};
|
||||
|
||||
const getTickets = (ticketItems = []) => {
|
||||
let tickets = [];
|
||||
|
||||
if (ticketItems !== false) {
|
||||
const count = typeof ticketItems === 'array' ? ticketItems.length :
|
||||
faker.random.number({ min: 1, max: 5 });
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
const ticketItem = ticketItems[i] || {};
|
||||
const {
|
||||
capacity = capacities[faker.random.arrayElement(['high', 'low'])],
|
||||
itemId = faker.random.uuid(),
|
||||
name = faker.lorem.sentence(),
|
||||
price = faker.random.number({ min: 50, max: 450 }),
|
||||
} = ticketItem;
|
||||
|
||||
tickets.push({
|
||||
available: (capacity -
|
||||
faker.random.number({ min: Math.floor(capacity / 2), max: (capacity - 50) })),
|
||||
capacity,
|
||||
endSale: dates.near,
|
||||
itemId,
|
||||
name,
|
||||
price,
|
||||
startSale: dates.past,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return tickets;
|
||||
}
|
||||
|
||||
const getEvent = (isTicketed = true) => ({
|
||||
description: faker.lorem.sentences(faker.random.number({ min: 3, max: 5 }), '. '),
|
||||
endTime: dates.near,
|
||||
images: [
|
||||
{ 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) },
|
||||
],
|
||||
isTicketed: isTicketed,
|
||||
posts: getPosts(faker.random.number({ min: 4, max: 12 })),
|
||||
requireLoginToSeeAuction: false,
|
||||
showFrom: dates.past - (14*24*60*60*1000),
|
||||
showUntil: dates.near + (14*24*60*60*1000),
|
||||
startTime: dates.past,
|
||||
tagline: faker.lorem.sentence(),
|
||||
ticketClasses: getTickets(isTicketed),
|
||||
title: faker.lorem.words(faker.random.number({ min: 1, max: 4 })),
|
||||
url: 'https://www.mfa.org/summer-party',
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
getEvent,
|
||||
getPosts,
|
||||
getTickets,
|
||||
};
|
||||
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