Added recommendation click and subscribe events to data generator
ref PROD-244
This commit is contained in:
parent
50788a78df
commit
58f23726fe
@ -0,0 +1,32 @@
|
||||
const TableImporter = require('./TableImporter');
|
||||
const {faker} = require('@faker-js/faker');
|
||||
const {luck} = require('../utils/random');
|
||||
|
||||
class RecommendationClickEventsImporter extends TableImporter {
|
||||
static table = 'recommendation_click_events';
|
||||
static dependencies = ['recommendations', 'members'];
|
||||
|
||||
constructor(knex, transaction) {
|
||||
super(RecommendationClickEventsImporter.table, knex, transaction);
|
||||
}
|
||||
|
||||
async import(quantity) {
|
||||
const recommendations = await this.transaction.select('id', 'created_at').from('recommendations');
|
||||
this.members = await this.transaction.select('id').from('members').limit(500);
|
||||
|
||||
await this.importForEach(recommendations, quantity ? quantity / recommendations.length : () => faker.datatype.number({min: 0, max: 50}));
|
||||
}
|
||||
|
||||
generate() {
|
||||
// Not unique
|
||||
const member = luck(30) ? null : faker.helpers.arrayElement(this.members);
|
||||
return {
|
||||
id: faker.database.mongodbObjectId(),
|
||||
recommendation_id: this.model.id,
|
||||
member_id: member?.id ?? null,
|
||||
created_at: faker.date.past()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RecommendationClickEventsImporter;
|
@ -0,0 +1,32 @@
|
||||
const TableImporter = require('./TableImporter');
|
||||
const {faker} = require('@faker-js/faker');
|
||||
const {luck} = require('../utils/random');
|
||||
|
||||
class RecommendationSubscribeEventsImporter extends TableImporter {
|
||||
static table = 'recommendation_subscribe_events';
|
||||
static dependencies = ['recommendations', 'members'];
|
||||
|
||||
constructor(knex, transaction) {
|
||||
super(RecommendationSubscribeEventsImporter.table, knex, transaction);
|
||||
}
|
||||
|
||||
async import(quantity) {
|
||||
const recommendations = await this.transaction.select('id', 'created_at').from('recommendations').where('one_click_subscribe', true);
|
||||
this.members = await this.transaction.select('id').from('members').limit(500);
|
||||
|
||||
await this.importForEach(recommendations, quantity ? quantity / recommendations.length : () => faker.datatype.number({min: 0, max: 50}));
|
||||
}
|
||||
|
||||
generate() {
|
||||
// Not unique
|
||||
const member = luck(1) ? null : faker.helpers.arrayElement(this.members);
|
||||
return {
|
||||
id: faker.database.mongodbObjectId(),
|
||||
recommendation_id: this.model.id,
|
||||
member_id: member?.id ?? null,
|
||||
created_at: faker.date.past()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RecommendationSubscribeEventsImporter;
|
@ -35,5 +35,7 @@ module.exports = [
|
||||
require('./MembersLabelsImporter'),
|
||||
require('./RolesUsersImporter'),
|
||||
require('./MembersFeedbackImporter'),
|
||||
require('./RecommendationsImporter')
|
||||
require('./RecommendationsImporter'),
|
||||
require('./RecommendationClickEventsImporter'),
|
||||
require('./RecommendationSubscribeEventsImporter')
|
||||
];
|
||||
|
Loading…
Reference in New Issue
Block a user