Skip to content

Commit d82c7ad

Browse files
author
Gery Hirschfeld
authored
Merge pull request #47 from w3tecch/fix/#33-null-and-jsonb-values
fix: fix conditions in the resolveEntity method
2 parents 5c0f58b + 9287bc0 commit d82c7ad

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

sample/entities/User.entity.ts

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ export class User {
1313
@Column()
1414
lastName: string
1515

16+
@Column({ nullable: true })
17+
middleName: string
18+
1619
@Column()
1720
email: string
1821

sample/factories/user.factory.ts

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ define(User, (faker: typeof Faker) => {
1111
const user = new User()
1212
user.firstName = firstName
1313
user.lastName = lastName
14+
user.middleName = null
1415
user.email = email
1516
user.password = faker.random.word()
1617
return user

src/entity-factory.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,19 @@ export class EntityFactory<Entity, Settings> {
9898
for (const attribute in entity) {
9999
if (entity.hasOwnProperty(attribute)) {
100100
if (isPromiseLike(entity[attribute])) {
101-
entity[attribute] = entity[attribute]
101+
entity[attribute] = await entity[attribute]
102102
}
103-
if (entity[attribute] && typeof entity[attribute] === 'object' && !(entity[attribute] instanceof Date)) {
103+
if (
104+
entity[attribute] &&
105+
typeof entity[attribute] === 'object' &&
106+
entity[attribute].constructor.name === EntityFactory.name
107+
) {
104108
const subEntityFactory = entity[attribute]
105109
try {
106110
if (isSeeding) {
107-
if (typeof (subEntityFactory as any).seed === 'function') {
108-
entity[attribute] = await (subEntityFactory as any).seed()
109-
}
111+
entity[attribute] = await (subEntityFactory as any).seed()
110112
} else {
111-
if (typeof (subEntityFactory as any).make === 'function') {
112-
entity[attribute] = await (subEntityFactory as any).make()
113-
}
113+
entity[attribute] = await (subEntityFactory as any).make()
114114
}
115115
} catch (error) {
116116
const message = `Could not make ${(subEntityFactory as any).name}`

0 commit comments

Comments
 (0)