import { MongoRepository } from 'typeorm'; import { Factory } from '../../types'; export default class EntitySeed { private repo: MongoRepository; private factory: Factory; constructor(repo: MongoRepository, factory: Factory) { this.repo = repo; this.factory = factory; } public async seedOne(data?: Entity): Promise { const ent = await this.factory(data); await this.repo.save(ent); return ent; } public async seedMany(amount: number, data?: Entity): Promise { const res: Entity[] = []; for (let i = 0; i < amount; i++) { res[i] = await this.factory(data); await this.repo.save(res[i]); } return res; } }