mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-27 21:03:29 +03:00
28b11e6fed
refs: https://github.com/TryGhost/Toolbox/issues/440 New command to generate demo data, creates data for over 20 tables in Ghost, suitable for testing most features of the dashboard, as well as making guided product tours using newsletters, tiers, many posts and tags. Usage: `yarn start generate-data` Optionally, keep your existing posts / tags with: `yarn start generate-data --use-existing-tags --use-existing-posts`
62 lines
1.9 KiB
JavaScript
62 lines
1.9 KiB
JavaScript
const {faker} = require('@faker-js/faker');
|
|
const TableImporter = require('./base');
|
|
const {blogStartDate} = require('../utils/blog-info');
|
|
|
|
class StripePricesImporter extends TableImporter {
|
|
constructor(knex, {products}) {
|
|
super('stripe_prices', knex);
|
|
this.products = products;
|
|
}
|
|
|
|
setImportOptions({model}) {
|
|
this.model = model;
|
|
|
|
this.count = 0;
|
|
}
|
|
|
|
generate() {
|
|
const sixWeeksLater = new Date(blogStartDate);
|
|
sixWeeksLater.setDate(sixWeeksLater.getDate() + (7 * 6));
|
|
|
|
const count = this.count;
|
|
this.count = this.count + 1;
|
|
|
|
const relatedProduct = this.products.find(product => product.id === this.model.product_id);
|
|
|
|
if (count === 1 && relatedProduct.monthly_price === null) {
|
|
// Only single complimentary price (yearly)
|
|
return null;
|
|
}
|
|
|
|
const billingCycle = {
|
|
nickname: 'Monthly',
|
|
interval: 'month',
|
|
type: 'recurring',
|
|
currency: 'usd',
|
|
amount: relatedProduct.monthly_price
|
|
};
|
|
if (count === 1) {
|
|
billingCycle.nickname = 'Yearly';
|
|
billingCycle.interval = 'year';
|
|
billingCycle.amount = relatedProduct.yearly_price;
|
|
} else if (relatedProduct.monthly_price === null) {
|
|
billingCycle.nickname = 'Complimentary';
|
|
billingCycle.interval = 'year';
|
|
billingCycle.amount = 0;
|
|
}
|
|
|
|
return Object.assign({}, {
|
|
id: faker.database.mongodbObjectId(),
|
|
stripe_price_id: faker.datatype.hexadecimal({
|
|
length: 64,
|
|
prefix: ''
|
|
}),
|
|
stripe_product_id: this.model.stripe_product_id,
|
|
active: true,
|
|
created_at: faker.date.between(blogStartDate, sixWeeksLater)
|
|
}, billingCycle);
|
|
}
|
|
}
|
|
|
|
module.exports = StripePricesImporter;
|