Skip to content

Commit 8035ea2

Browse files
author
hirsch88
committed
Fix seeding
1 parent f31e73b commit 8035ea2

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/database/seeds/CreatePets.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ export class CreatePets implements Seed {
88

99
public async seed(factory: Factory, connection: Connection): Promise<any> {
1010
const em = connection.createEntityManager();
11-
1211
await times(10, async (n) => {
1312
const pet = await factory(Pet)().seed();
1413
const user = await factory(User)().make();
1514
user.pets = [pet];
16-
await em.save(user);
15+
return await em.save(user);
1716
});
1817
}
1918

src/lib/seed/utils.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,11 @@ export const isPromiseLike = (o: any): boolean => !!o && (typeof o === 'object'
1111
/**
1212
* Times repeats a function n times
1313
*/
14-
export const times = async <TResult>(n: number, iteratee: (index: number) => Promise<TResult>): Promise<TResult[]> =>
15-
Promise.all(new Array(n).map(async (v, i) => await iteratee(i)));
14+
export const times = async <TResult>(n: number, iteratee: (index: number) => Promise<TResult>): Promise<TResult[]> => {
15+
const rs = [] as TResult[];
16+
for (let i = 0; i < n; i++) {
17+
const r = await iteratee(i);
18+
rs.push(r);
19+
}
20+
return rs;
21+
};

0 commit comments

Comments
 (0)