Ghost/ghost/data-generator/lib/tables/newsletters.js
Sam Lord 0d7944861c Data generator: Swap order of free and premium newsletters
no issue
Free and premium newsletters were the other way around in the demo-data. This was a good opportunity to stop the email table importer from relying on the newsletter name, and use the order alone.
2023-02-08 22:12:19 +00:00

34 lines
1.1 KiB
JavaScript

const TableImporter = require('./base');
const {blogStartDate} = require('../utils/blog-info');
const {faker} = require('@faker-js/faker');
const {slugify} = require('@tryghost/string');
class NewslettersImporter extends TableImporter {
constructor(knex) {
super('newsletters', knex);
this.sortOrder = 0;
this.names = ['Regular premium', 'Occasional freebie'];
}
generate() {
const name = this.names.shift();
const sortOrder = this.sortOrder;
this.sortOrder = this.sortOrder + 1;
const weekAfter = new Date(blogStartDate);
weekAfter.setDate(weekAfter.getDate() + 7);
return {
id: faker.database.mongodbObjectId(),
uuid: faker.datatype.uuid(),
name: name,
slug: `${slugify(name)}-${faker.random.numeric(3)}`,
sender_reply_to: 'hello@example.com',
status: 'active',
subscribe_on_signup: faker.datatype.boolean(),
sort_order: sortOrder,
created_at: faker.date.between(blogStartDate, weekAfter)
};
}
}
module.exports = NewslettersImporter;