Skip to content

Commit

Permalink
fix: entity to be Partial<Entity> | undefined in UpdateEvent (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
francescoferraioli committed Jul 9, 2021
1 parent 8436fdb commit f033045
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/subscriber/event/UpdateEvent.ts
Expand Up @@ -30,7 +30,7 @@ export interface UpdateEvent<Entity> {
/**
* Updating entity.
*/
entity: Entity;
entity: Partial<Entity> | undefined;

/**
* Metadata of the entity.
Expand Down
Expand Up @@ -10,9 +10,11 @@ export class AbstractEntitySubscriber implements EntitySubscriberInterface<Abstr
this.updateFullName(event.entity);
}
async beforeUpdate(event: UpdateEvent<AbstractEntity>) {
this.updateFullName(event.entity);
if(event.entity) {
this.updateFullName(event.entity);
}
}
updateFullName(o: AbstractEntity) {
updateFullName(o: Partial<AbstractEntity>) {
o.fullname = o.firstname + " " + o.lastname;
}
}
4 changes: 3 additions & 1 deletion test/github-issues/3256/subscriber/PostSubscriber.ts
Expand Up @@ -12,7 +12,9 @@ export class PostSubscriber implements EntitySubscriberInterface<Post> {
}

async beforeUpdate(event: UpdateEvent<Post>) {
event.entity.updated = true;
if(event.entity) {
event.entity.updated = true;
}
}

}
Expand Up @@ -8,8 +8,10 @@ export class PostSubscriber implements EntitySubscriberInterface<Post> {
}

beforeUpdate(event: UpdateEvent<Post>) {
event.entity.updatedColumns = event.updatedColumns.length;
event.entity.updatedRelations = event.updatedRelations.length;
if(event.entity) {
event.entity.updatedColumns = event.updatedColumns.length;
event.entity.updatedRelations = event.updatedRelations.length;
}
}

}
Expand Up @@ -8,7 +8,9 @@ export class PostSubscriber implements EntitySubscriberInterface<Post> {
}

beforeUpdate(event: UpdateEvent<Post>) {
event.entity.updatedColumns = event.updatedColumns.length;
if(event.entity) {
event.entity.updatedColumns = event.updatedColumns.length;
}
}

afterLoad(entity: Post) {
Expand Down

0 comments on commit f033045

Please sign in to comment.