Skip to content

Commit

Permalink
Merge pull request #13 from bancodobrasil/feat/menu-items-resolver
Browse files Browse the repository at this point in the history
feat: MenuItems resolver findOne
  • Loading branch information
ralphg6 authored Feb 9, 2023
2 parents a112180 + bf5d184 commit 4311560
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/menu-items/entities/menu-item.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class MenuItem {
@Column({ nullable: true })
parentId?: number;

@Field(() => Menu)
@ManyToOne(() => Menu, (menu) => menu.items, {
lazy: true,
onDelete: 'CASCADE',
Expand Down
3 changes: 2 additions & 1 deletion src/menu-items/menu-items.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { MenuItem } from './entities/menu-item.entity';
import { MenuItemsService } from './menu-items.service';
import { MenuItemsResolver } from './menu-items.resolver';

@Module({
imports: [TypeOrmModule.forFeature([MenuItem])],
providers: [MenuItemsService],
providers: [MenuItemsService, MenuItemsResolver],
exports: [MenuItemsService],
})
export class MenuItemsModule {}
18 changes: 18 additions & 0 deletions src/menu-items/menu-items.resolver.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { Test, TestingModule } from '@nestjs/testing';
import { MenuItemsResolver } from './menu-items.resolver';

describe('MenuItemsResolver', () => {
let resolver: MenuItemsResolver;

beforeEach(async () => {
const module: TestingModule = await Test.createTestingModule({
providers: [MenuItemsResolver],
}).compile();

resolver = module.get<MenuItemsResolver>(MenuItemsResolver);
});

it('should be defined', () => {
expect(resolver).toBeDefined();
});
});
13 changes: 13 additions & 0 deletions src/menu-items/menu-items.resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Resolver, Query, Args, Int } from '@nestjs/graphql';
import { MenuItem } from './entities/menu-item.entity';
import { MenuItemsService } from './menu-items.service';

@Resolver(() => MenuItem)
export class MenuItemsResolver {
constructor(private readonly menusService: MenuItemsService) {}

@Query(() => MenuItem, { name: 'menuItem' })
findOne(@Args('id', { type: () => Int }) id: number) {
return this.menusService.findOne(id);
}
}
2 changes: 1 addition & 1 deletion src/menu-items/menu-items.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class MenuItemsService {
}

findOne(id: number) {
return `This action returns a #${id} menu item`;
return this.menuItemRepository.findOneBy({ id: id });
}

async update(input: UpdateMenuItemInput, manager: EntityManager) {
Expand Down
2 changes: 2 additions & 0 deletions src/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type MenuItem {
meta: JSONObject!
children: [MenuItem!]
parentId: Int
menu: Menu!
menuId: Int
enabled: Boolean!
startPublication: DateTime
Expand All @@ -58,6 +59,7 @@ scalar DateTime
type Query {
menus(first: Int, after: String, last: Int, before: String, sort: MenuSort, direction: Direction): MenuConnection!
menu(id: Int!): Menu!
menuItem(id: Int!): MenuItem!
}

enum MenuSort {
Expand Down

0 comments on commit 4311560

Please sign in to comment.