Skip to content

Commit

Permalink
Update deprecated repository methods usages (#547)
Browse files Browse the repository at this point in the history
Use the underlying entity manager instead.
  • Loading branch information
johnnyomair authored Nov 28, 2024
1 parent 8f644d5 commit 1a3fc52
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
12 changes: 8 additions & 4 deletions api/src/documents/links/links.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
validateNotModified,
} from "@comet/cms-api";
import { InjectRepository } from "@mikro-orm/nestjs";
import { EntityRepository } from "@mikro-orm/postgresql";
import { EntityManager, EntityRepository } from "@mikro-orm/postgresql";
import { UnauthorizedException } from "@nestjs/common";
import { Args, ID, Mutation, Parent, Query, ResolveField, Resolver } from "@nestjs/graphql";
import { PageTreeNode } from "@src/page-tree/entities/page-tree-node.entity";
Expand All @@ -18,7 +18,11 @@ import { Link } from "./entities/link.entity";
@Resolver(() => Link)
@RequiredPermission(["pageTree"])
export class LinksResolver {
constructor(@InjectRepository(Link) readonly repository: EntityRepository<Link>, private readonly pageTreeService: PageTreeService) {}
constructor(
@InjectRepository(Link) readonly repository: EntityRepository<Link>,
private readonly pageTreeService: PageTreeService,
private readonly entityManager: EntityManager,
) {}

@Query(() => Link, { nullable: true })
async link(@Args("linkId", { type: () => ID }) linkId: string): Promise<Link | null> {
Expand Down Expand Up @@ -60,14 +64,14 @@ export class LinksResolver {
content: input.content.transformToBlockData(),
});

this.repository.persist(link);
this.entityManager.persist(link);
}

if (attachedPageTreeNodeId) {
await this.pageTreeService.attachDocument({ id: linkId, type: "Link" }, attachedPageTreeNodeId);
}

await this.repository.flush();
await this.entityManager.flush();

return link;
}
Expand Down
12 changes: 8 additions & 4 deletions api/src/documents/pages/pages.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
validateNotModified,
} from "@comet/cms-api";
import { InjectRepository } from "@mikro-orm/nestjs";
import { EntityRepository } from "@mikro-orm/postgresql";
import { EntityManager, EntityRepository } from "@mikro-orm/postgresql";
import { UnauthorizedException } from "@nestjs/common";
import { Args, ID, Mutation, Parent, Query, ResolveField, Resolver } from "@nestjs/graphql";
import { PageTreeNode } from "@src/page-tree/entities/page-tree-node.entity";
Expand All @@ -18,7 +18,11 @@ import { Page } from "./entities/page.entity";
@Resolver(() => Page)
@RequiredPermission(["pageTree"])
export class PagesResolver {
constructor(@InjectRepository(Page) private readonly repository: EntityRepository<Page>, private readonly pageTreeService: PageTreeService) {}
constructor(
@InjectRepository(Page) private readonly repository: EntityRepository<Page>,
private readonly pageTreeService: PageTreeService,
private readonly entityManager: EntityManager,
) {}

@Query(() => Page)
@AffectedEntity(Page)
Expand Down Expand Up @@ -67,14 +71,14 @@ export class PagesResolver {
stage: input.stage.transformToBlockData(),
});

this.repository.persist(page);
this.entityManager.persist(page);
}

if (attachedPageTreeNodeId) {
await this.pageTreeService.attachDocument({ id: pageId, type: "Page" }, attachedPageTreeNodeId);
}

await this.repository.flush();
await this.entityManager.flush();

return page;
}
Expand Down

0 comments on commit 1a3fc52

Please sign in to comment.