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> {
24
24
return await this . makeEntity ( this . blueprint . create ( this . faker , this . args ) ) ;
25
25
}
26
26
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
+
27
38
public async create ( ) : Promise < Entity > {
28
39
const entity = await this . build ( ) ;
29
40
if ( typeof this . eachFn === 'function' ) {
Original file line number Diff line number Diff line change @@ -10,14 +10,12 @@ export interface EntityFactoryInterface<Entity> {
10
10
* Creates a entity with faked data, but not persisted to the database.
11
11
*/
12
12
make ( ) : Promise < Entity > ;
13
+ makeMany ( amount : number ) : Promise < Entity [ ] > ;
13
14
/**
14
15
* Creates a new faked entity in the database.
15
16
*/
16
17
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 [ ] > ;
21
19
/**
22
20
* This is called after creating a enity to the database. Use this to
23
21
* create other seeds but combined with this enitiy.
You can’t perform that action at this time.
0 commit comments