2022-10-26 19:55:08 +03:00
|
|
|
const TableImporter = require('./base');
|
|
|
|
const {faker} = require('@faker-js/faker');
|
2022-11-03 14:08:03 +03:00
|
|
|
const dateToDatabaseString = require('../utils/database-date');
|
2022-10-26 19:55:08 +03:00
|
|
|
|
|
|
|
class MembersStatusEventsImporter extends TableImporter {
|
2023-02-16 15:11:00 +03:00
|
|
|
static table = 'members_status_events';
|
|
|
|
|
2022-10-26 19:55:08 +03:00
|
|
|
constructor(knex) {
|
2023-02-16 15:11:00 +03:00
|
|
|
super(MembersStatusEventsImporter.table, knex);
|
2022-10-26 19:55:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
setImportOptions({model}) {
|
|
|
|
this.events = [{
|
|
|
|
id: faker.database.mongodbObjectId(),
|
|
|
|
member_id: model.id,
|
|
|
|
from_status: null,
|
|
|
|
to_status: 'free',
|
|
|
|
created_at: model.created_at
|
|
|
|
}];
|
|
|
|
if (model.status !== 'free') {
|
|
|
|
this.events.push({
|
|
|
|
id: faker.database.mongodbObjectId(),
|
|
|
|
member_id: model.id,
|
|
|
|
from_status: 'free',
|
|
|
|
to_status: model.status,
|
2022-11-03 14:08:03 +03:00
|
|
|
created_at: dateToDatabaseString(faker.date.between(new Date(model.created_at), new Date()))
|
2022-10-26 19:55:08 +03:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
generate() {
|
|
|
|
const event = this.events.shift();
|
|
|
|
if (!event) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return event;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = MembersStatusEventsImporter;
|