2022-10-26 19:55:08 +03:00
|
|
|
const {faker} = require('@faker-js/faker');
|
|
|
|
const TableImporter = require('./base');
|
|
|
|
|
|
|
|
class PostsAuthorsImporter extends TableImporter {
|
2023-02-16 15:11:00 +03:00
|
|
|
static table = 'posts_authors';
|
|
|
|
|
2022-10-26 19:55:08 +03:00
|
|
|
constructor(knex, {users}) {
|
2023-02-16 15:11:00 +03:00
|
|
|
super(PostsAuthorsImporter.table, knex);
|
2022-10-26 19:55:08 +03:00
|
|
|
this.users = users;
|
|
|
|
this.sortOrder = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
setImportOptions({model}) {
|
|
|
|
this.model = model;
|
|
|
|
}
|
|
|
|
|
|
|
|
generate() {
|
|
|
|
const sortOrder = this.sortOrder;
|
|
|
|
this.sortOrder = this.sortOrder + 1;
|
|
|
|
return {
|
|
|
|
id: faker.database.mongodbObjectId(),
|
|
|
|
post_id: this.model.id,
|
|
|
|
author_id: this.users[faker.datatype.number(this.users.length - 1)].id,
|
|
|
|
sort_order: sortOrder
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = PostsAuthorsImporter;
|