2023-08-02 16:43:26 +03:00
|
|
|
const TableImporter = require('./TableImporter');
|
2023-02-17 20:01:20 +03:00
|
|
|
const {faker} = require('@faker-js/faker');
|
|
|
|
const {slugify} = require('@tryghost/string');
|
|
|
|
const {blogStartDate} = require('../utils/blog-info');
|
|
|
|
const dateToDatabaseString = require('../utils/database-date');
|
|
|
|
|
|
|
|
class LabelsImporter extends TableImporter {
|
|
|
|
static table = 'labels';
|
2023-08-02 16:43:26 +03:00
|
|
|
static dependencies = [];
|
|
|
|
defaultQuantity = 10;
|
2023-02-17 20:01:20 +03:00
|
|
|
|
2023-08-02 16:43:26 +03:00
|
|
|
constructor(knex, transaction) {
|
|
|
|
super(LabelsImporter.table, knex, transaction);
|
2023-02-21 14:42:33 +03:00
|
|
|
this.generatedNames = new Set();
|
|
|
|
}
|
|
|
|
|
|
|
|
generateName() {
|
|
|
|
let name;
|
|
|
|
do {
|
|
|
|
name = `${faker.color.human()} ${faker.name.jobType()}`;
|
|
|
|
name = `${name[0].toUpperCase()}${name.slice(1)}`;
|
|
|
|
} while (this.generatedNames.has(name));
|
|
|
|
this.generatedNames.add(name);
|
|
|
|
return name;
|
2023-02-17 20:01:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
generate() {
|
2023-02-21 14:42:33 +03:00
|
|
|
const name = this.generateName();
|
2023-02-17 20:01:20 +03:00
|
|
|
return {
|
2024-01-05 16:42:30 +03:00
|
|
|
id: this.fastFakeObjectId(),
|
2023-02-17 20:01:20 +03:00
|
|
|
name: name,
|
|
|
|
slug: `${slugify(name)}`,
|
|
|
|
created_at: dateToDatabaseString(blogStartDate),
|
|
|
|
created_by: '1',
|
|
|
|
updated_at: dateToDatabaseString(blogStartDate),
|
|
|
|
updated_by: '1'
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = LabelsImporter;
|