Skip to content

Commit f5ac88d

Browse files
author
hirsch88
committed
fix types
1 parent 0bf3110 commit f5ac88d

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/database/seeds/CreatePets.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ export class CreatePets implements Seed {
1010
const em = connection.createEntityManager();
1111

1212
await times(10, async (n) => {
13-
const pet = await factory<Pet, undefined>(Pet as any)().seed();
14-
const user = await factory<User, undefined>(User as any)().make();
13+
const pet = await factory(Pet)().seed();
14+
const user = await factory(User)().make();
1515
user.pets = [pet];
1616
await em.save(user);
1717
});

src/lib/seed/EntityFactory.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as Faker from 'faker';
2-
import { Connection } from 'typeorm/connection/Connection';
2+
import { Connection, ObjectType } from 'typeorm';
33

44
import { FactoryFunction } from './types';
55
import { isPromiseLike } from './utils';
@@ -13,7 +13,7 @@ export class EntityFactory<Entity, Settings> {
1313

1414
constructor(
1515
public name: string,
16-
public entity: Entity,
16+
public entity: ObjectType<Entity>,
1717
private factory: FactoryFunction<Entity, Settings>,
1818
private settings?: Settings
1919
) { }
@@ -54,7 +54,7 @@ export class EntityFactory<Entity, Settings> {
5454
const em = connection.createEntityManager();
5555
try {
5656
const entity = await this.make();
57-
return await em.save<Entity>(this.entity, entity);
57+
return await em.save<Entity>(entity);
5858
} catch (error) {
5959
throw new Error('Could not save entity');
6060
}

src/lib/seed/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'reflect-metadata';
22
import { Connection, ObjectType } from 'typeorm';
33

4+
import { Factory } from '../seeds/Factory';
45
import { EntityFactory } from './EntityFactory';
56
import { EntityFactoryDefinition, FactoryFunction, SeedConstructor } from './types';
67
import { getNameOfClass } from './utils';
@@ -46,7 +47,7 @@ export const define = <Entity, Settings>(entity: ObjectType<Entity>, factoryFn:
4647
/**
4748
* Gets a defined entity factory and pass the settigns along to the entity factory function
4849
*/
49-
export const factory = <Entity, Settings>(entity: Entity) => (settings?: Settings) => {
50+
export const factory: Factory = <Entity, Settings>(entity: ObjectType<Entity>) => (settings?: Settings) => {
5051
const name = getNameOfClass(entity);
5152
const entityFactoryObject = (global as any).seeder.entityFactories.get(name);
5253
return new EntityFactory<Entity, Settings>(

0 commit comments

Comments
 (0)