mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-15 03:01:37 -05:00
Added offers to data generator
no issue Can generate a pair of offers. TODO: Add offers to the base-data pack
This commit is contained in:
parent
22ac685354
commit
db7ac14467
3 changed files with 73 additions and 2 deletions
|
@ -30,7 +30,8 @@ const {
|
|||
EmailBatchesImporter,
|
||||
EmailRecipientsImporter,
|
||||
RedirectsImporter,
|
||||
MembersClickEventsImporter
|
||||
MembersClickEventsImporter,
|
||||
OffersImporter
|
||||
} = tables;
|
||||
const path = require('path');
|
||||
const fs = require('fs/promises');
|
||||
|
@ -378,6 +379,9 @@ class DataGenerator {
|
|||
const membersClickEventsImporter = new MembersClickEventsImporter(transaction, {redirects, emails});
|
||||
await membersClickEventsImporter.importForEach(emailRecipients, {amount: 2});
|
||||
|
||||
const offersImporter = new OffersImporter(transaction, {products: products.filter(product => product.name !== 'Free')});
|
||||
await offersImporter.import({amount: 2});
|
||||
|
||||
// TODO: Email clicks - redirect, members_click_events (relies on emails)
|
||||
|
||||
// TODO: Feedback - members_feedback (relies on members and posts)
|
||||
|
|
|
@ -29,5 +29,6 @@ module.exports = {
|
|||
EmailBatchesImporter: require('./email-batches'),
|
||||
EmailRecipientsImporter: require('./email-recipients'),
|
||||
RedirectsImporter: require('./redirects'),
|
||||
MembersClickEventsImporter: require('./members-click-events')
|
||||
MembersClickEventsImporter: require('./members-click-events'),
|
||||
OffersImporter: require('./offers')
|
||||
};
|
||||
|
|
66
ghost/data-generator/lib/tables/offers.js
Normal file
66
ghost/data-generator/lib/tables/offers.js
Normal file
|
@ -0,0 +1,66 @@
|
|||
const TableImporter = require('./base');
|
||||
const {faker} = require('@faker-js/faker');
|
||||
const {slugify} = require('@tryghost/string');
|
||||
const {blogStartDate} = require('../utils/blog-info');
|
||||
const dateToDatabaseString = require('../utils/database-date');
|
||||
|
||||
class OffersImporter extends TableImporter {
|
||||
static table = 'offers';
|
||||
|
||||
constructor(knex, {products}) {
|
||||
super(OffersImporter.table, knex);
|
||||
this.products = products;
|
||||
}
|
||||
|
||||
setImportOptions() {
|
||||
this.names = ['Black Friday', 'Free Trial'];
|
||||
this.count = 0;
|
||||
}
|
||||
|
||||
generate() {
|
||||
const name = this.names.shift();
|
||||
|
||||
const product = this.products[faker.datatype.number({
|
||||
min: 0,
|
||||
max: this.products.length - 1
|
||||
})];
|
||||
|
||||
// id: {type: 'string', maxlength: 24, nullable: false, primary: true},
|
||||
// // @deprecated: use a status enum with isIn validation, not an `active` boolean
|
||||
// active: {type: 'boolean', nullable: false, defaultTo: true},
|
||||
// name: {type: 'string', maxlength: 191, nullable: false, unique: true},
|
||||
// code: {type: 'string', maxlength: 191, nullable: false, unique: true},
|
||||
// product_id: {type: 'string', maxlength: 24, nullable: false, references: 'products.id'},
|
||||
// stripe_coupon_id: {type: 'string', maxlength: 255, nullable: true, unique: true},
|
||||
// interval: {type: 'string', maxlength: 50, nullable: false, validations: {isIn: [['month', 'year']]}},
|
||||
// currency: {type: 'string', maxlength: 50, nullable: true},
|
||||
// discount_type: {type: 'string', maxlength: 50, nullable: false, validations: {isIn: [['percent', 'amount', 'trial']]}},
|
||||
// discount_amount: {type: 'integer', nullable: false},
|
||||
// duration: {type: 'string', maxlength: 50, nullable: false, validations: {isIn: [['trial', 'once', 'repeating', 'forever']]}},
|
||||
// duration_in_months: {type: 'integer', nullable: true},
|
||||
// portal_title: {type: 'string', maxlength: 191, nullable: true},
|
||||
// portal_description: {type: 'string', maxlength: 2000, nullable: true},
|
||||
// created_at: {type: 'dateTime', nullable: false},
|
||||
// updated_at: {type: 'dateTime', nullable: true}
|
||||
return {
|
||||
id: faker.database.mongodbObjectId(),
|
||||
active: true,
|
||||
name,
|
||||
code: slugify(name),
|
||||
product_id: product.id,
|
||||
stripe_coupon_id: faker.random.alphaNumeric(8),
|
||||
interval: 'month',
|
||||
currency: product.currency,
|
||||
discount_type: name === 'Free Trial' ? 'trial' : 'percent',
|
||||
discount_amount: name === 'Free Trial' ? 7 : 20,
|
||||
duration: name === 'Free Trial' ? 'trial' : 'once',
|
||||
duration_in_months: name === 'Free Trial' ? 1 : 12,
|
||||
portal_title: name,
|
||||
portal_description: name === 'Free Trial' ? 'Get a 1 week free trial' : 'Get 20% off for Black Friday',
|
||||
created_at: dateToDatabaseString(blogStartDate),
|
||||
updated_at: dateToDatabaseString(blogStartDate)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = OffersImporter;
|
Loading…
Add table
Reference in a new issue