Skip to content

Commit

Permalink
fix: fix conditions in the resolveEntity method
Browse files Browse the repository at this point in the history
  • Loading branch information
hirsch committed Apr 11, 2020
1 parent 5c0f58b commit 9287bc0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
3 changes: 3 additions & 0 deletions sample/entities/User.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export class User {
@Column()
lastName: string

@Column({ nullable: true })
middleName: string

@Column()
email: string

Expand Down
1 change: 1 addition & 0 deletions sample/factories/user.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ define(User, (faker: typeof Faker) => {
const user = new User()
user.firstName = firstName
user.lastName = lastName
user.middleName = null
user.email = email
user.password = faker.random.word()
return user
Expand Down
16 changes: 8 additions & 8 deletions src/entity-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,19 @@ export class EntityFactory<Entity, Settings> {
for (const attribute in entity) {
if (entity.hasOwnProperty(attribute)) {
if (isPromiseLike(entity[attribute])) {
entity[attribute] = entity[attribute]
entity[attribute] = await entity[attribute]
}
if (entity[attribute] && typeof entity[attribute] === 'object' && !(entity[attribute] instanceof Date)) {
if (
entity[attribute] &&
typeof entity[attribute] === 'object' &&
entity[attribute].constructor.name === EntityFactory.name
) {
const subEntityFactory = entity[attribute]
try {
if (isSeeding) {
if (typeof (subEntityFactory as any).seed === 'function') {
entity[attribute] = await (subEntityFactory as any).seed()
}
entity[attribute] = await (subEntityFactory as any).seed()
} else {
if (typeof (subEntityFactory as any).make === 'function') {
entity[attribute] = await (subEntityFactory as any).make()
}
entity[attribute] = await (subEntityFactory as any).make()
}
} catch (error) {
const message = `Could not make ${(subEntityFactory as any).name}`
Expand Down

0 comments on commit 9287bc0

Please sign in to comment.