File tree Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Expand file tree Collapse file tree 2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,17 @@ export class EntityFactory<Entity> implements EntityFactoryInterface<Entity> {
2424 return await this . makeEntity ( this . blueprint . create ( this . faker , this . args ) ) ;
2525 }
2626
27+ public async makeMany ( amount : number ) : Promise < Entity [ ] > {
28+ const results : Entity [ ] = [ ] ;
29+ for ( let i = 0 ; i < amount ; i ++ ) {
30+ const entity = await this . makeEntity ( this . blueprint . create ( this . faker , this . args ) ) ;
31+ if ( entity ) {
32+ results . push ( entity ) ;
33+ }
34+ }
35+ return results ;
36+ }
37+
2738 public async create ( ) : Promise < Entity > {
2839 const entity = await this . build ( ) ;
2940 if ( typeof this . eachFn === 'function' ) {
Original file line number Diff line number Diff line change @@ -10,14 +10,12 @@ export interface EntityFactoryInterface<Entity> {
1010 * Creates a entity with faked data, but not persisted to the database.
1111 */
1212 make ( ) : Promise < Entity > ;
13+ makeMany ( amount : number ) : Promise < Entity [ ] > ;
1314 /**
1415 * Creates a new faked entity in the database.
1516 */
1617 create ( ) : Promise < Entity > ;
17- /**
18- * Creates an amount (default 1) of the defined entity.
19- */
20- createMany ( amount : number ) : Promise < Entity [ ] | undefined > ;
18+ createMany ( amount : number ) : Promise < Entity [ ] > ;
2119 /**
2220 * This is called after creating a enity to the database. Use this to
2321 * create other seeds but combined with this enitiy.
You can’t perform that action at this time.
0 commit comments