Skip to content

Commit

Permalink
fix: refactor em reset
Browse files Browse the repository at this point in the history
  • Loading branch information
etienne-bechara committed Aug 27, 2021
1 parent 5b7a96a commit 01ffa2d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion source/orm/orm.interceptor/orm.entity.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class OrmEntityManager implements NestInterceptor {
*/
public intercept(context: ExecutionContext, next: CallHandler): any {
const store = this.requestService.getStore();
const entityManager = this.mikroOrm.em.fork(true, true);
let entityManager = this.mikroOrm.em.fork(true, true);
store.set(OrmStoreKey.ENTITY_MANAGER, entityManager);

return next
Expand All @@ -34,6 +34,7 @@ export class OrmEntityManager implements NestInterceptor {

if (flushPending) {
try {
entityManager = store.get(OrmStoreKey.ENTITY_MANAGER);
await entityManager.flush();
}
catch (e) {
Expand Down
8 changes: 4 additions & 4 deletions source/orm/orm.repository/orm.repository.base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ export abstract class OrmBaseRepository<Entity> extends EntityRepository<Entity>
}

/**
* Clear all persisted entities.
* Resets the entity manager.
*/
public clear(): void {
const em: EntityManager = this.getStore().get(OrmStoreKey.ENTITY_MANAGER);
em.clear();
public reset(): void {
const cleanEntityManager = this.entityManager.fork(true);
this.getStore().set(OrmStoreKey.ENTITY_MANAGER, cleanEntityManager);
}

/**
Expand Down

0 comments on commit 01ffa2d

Please sign in to comment.