Skip to content

Commit

Permalink
Merge branch 'develop' into feat/add-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
matheusromano authored Jan 18, 2023
2 parents 77011a5 + 43ad396 commit 4bad6d0
Show file tree
Hide file tree
Showing 22 changed files with 1,370 additions and 97 deletions.
7 changes: 6 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ node_modules
docker-compose.yml
.git
.gitignore
.env*
.env*
Dockerfile
.dockerignore
node_modules
npm-debug.log
dist
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ lerna-debug.log*
*.launch
.settings/
*.sublime-workspace
/.vscode

# IDE - VSCode
.vscode/*
Expand Down
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,4 @@ RUN yarn build

EXPOSE 3000

CMD ["yarn", "start"]


CMD ["yarn", "start"]
29 changes: 16 additions & 13 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,6 @@ services:
MYSQL_USER: 'api'
MYSQL_PASSWORD: 'api'

wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
volumes:
- ./html:/var/www/html
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: api
WORDPRESS_DB_PASSWORD: api
WORDPRESS_DB_NAME: api
prometheus:
image: bitnami/prometheus
ports:
Expand Down Expand Up @@ -62,4 +49,20 @@ services:
- JAMIE_API_DATABASE_USER=api
- JAMIE_API_DATABASE_PASSWORD=api

jaeger:
image: jaegertracing/all-in-one:1.41
environment:
COLLECTOR_ZIPKIN_HOST_PORT: :9411
COLLECTOR_OTLP_ENABLED: true
ports:
- 14250:14250
- 14268:14268
- 14269:14269
- 16686:16686
- 4317:4317
- 4318:4318
- 5778:5778
- 6831:6831
- 6832:6832
- 9411:9411

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
"@nestjs/platform-express": "^9.0.0",
"@nestjs/typeorm": "^9.0.1",
"@willsoto/nestjs-prometheus": "^5.1.0",
"@opentelemetry/auto-instrumentations-node": "^0.36.0",
"@opentelemetry/exporter-trace-otlp-http": "^0.34.0",
"@opentelemetry/resources": "^1.8.0",
"@opentelemetry/sdk-node": "^0.34.0",
"@opentelemetry/semantic-conventions": "^1.8.0",
"apollo-server-express": "^3.11.1",
"graphql": "^16.6.0",
"mysql2": "^2.3.3",
Expand Down
7 changes: 6 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import tracer from './tracer';

const { PORT = 5000 } = process.env;

async function bootstrap() {
await tracer.start();

const app = await NestFactory.create(AppModule);
await app.listen(3000);
await app.listen(PORT);
}
bootstrap();
17 changes: 0 additions & 17 deletions src/menu-items/dto/create-menu-item.input.ts

This file was deleted.

32 changes: 32 additions & 0 deletions src/menu-items/dto/menu-item.input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { Field, InputType, Int } from '@nestjs/graphql';
import { GraphQLJSONObject } from 'src/common/graphql/types/json.type';

export enum MenuItemAction {
CREATE = 'create',
UPDATE = 'update',
DELETE = 'delete',
}

@InputType()
export class MenuItemInput {
@Field(() => Int, { nullable: true })
id?: number;

@Field()
label: string;

@Field()
action: MenuItemAction;

@Field(() => Int)
order: number;

@Field(() => Int, { nullable: true })
parentId?: number;

@Field(() => [MenuItemInput], { nullable: true })
children?: MenuItemInput[];

@Field(() => GraphQLJSONObject, { nullable: true })
meta?: object;
}
8 changes: 0 additions & 8 deletions src/menu-items/dto/update-menu-item.input.ts

This file was deleted.

12 changes: 6 additions & 6 deletions src/menu-items/entities/menu-item.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ export class MenuItem {
meta?: object;

@Field(() => MenuItem, { nullable: true })
@OneToMany(() => MenuItem, (menuItem) => menuItem.parent)
children?: MenuItem[];
@OneToMany(() => MenuItem, (menuItem) => menuItem.parent, { lazy: true })
children?: Promise<MenuItem[]>;

@ManyToOne(() => MenuItem, (menuItem) => menuItem.children)
@ManyToOne(() => MenuItem, (menuItem) => menuItem.children, { lazy: true })
@JoinColumn()
parent?: MenuItem;
parent?: Promise<MenuItem>;

@Field(() => Int, { nullable: true })
@Column({ nullable: true })
parentId?: number;

@ManyToOne(() => Menu, (menu) => menu.items)
@ManyToOne(() => Menu, (menu) => menu.items, { lazy: true })
@JoinColumn()
menu?: Menu;
menu?: Promise<Menu>;
}
3 changes: 3 additions & 0 deletions src/menu-items/menu-items.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { MenuItem } from './entities/menu-item.entity';
import { MenuItemsService } from './menu-items.service';

@Module({
imports: [TypeOrmModule.forFeature([MenuItem])],
providers: [MenuItemsService],
exports: [MenuItemsService],
})
Expand Down
43 changes: 38 additions & 5 deletions src/menu-items/menu-items.service.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,59 @@
import { Injectable } from '@nestjs/common';
import { CreateMenuItemInput } from './dto/create-menu-item.input';
import { UpdateMenuItemInput } from './dto/update-menu-item.input';
import { InjectRepository } from '@nestjs/typeorm';
import { Menu } from 'src/menus/entities/menu.entity';
import { Repository } from 'typeorm';
import { MenuItemAction, MenuItemInput } from './dto/menu-item.input';
import { MenuItem } from './entities/menu-item.entity';

@Injectable()
export class MenuItemsService {
create(createMenuInput: CreateMenuItemInput) {
constructor(
@InjectRepository(MenuItem)
private menuItemRepository: Repository<MenuItem>,
) {}
create(createMenuInput: MenuItemInput) {
return 'This action adds a new menu item';
}

findAll(query: any) {
return `This action returns all menu items`;
// return `This action returns all menu items`;
return this.menuItemRepository.find({
where: [{ menu: { id: query.menuId } }],
});
}

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

update(id: number, updateMenuInput: UpdateMenuItemInput) {
update(id: number, updateMenuInput: MenuItemInput) {
return `This action updates a #${id} menu item`;
}

remove(id: number) {
return `This action removes a #${id} menu item`;
}

handle(menu: Menu, input: MenuItemInput) {
if (
input.action == MenuItemAction.CREATE ||
input.action == MenuItemAction.UPDATE
) {
const item = new MenuItem();

item.id = input.id;
item.label = input.label;
item.order = input.order;
item.menu = Promise.resolve(menu);

return this.menuItemRepository.save(item);
}

if (input.action == MenuItemAction.DELETE) {
this.menuItemRepository.delete(input.id);
return;
}

throw new Error('unexpected action');
}
}
6 changes: 5 additions & 1 deletion src/menus/dto/create-menu.input.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { InputType, Field } from '@nestjs/graphql';
import { Field, InputType } from '@nestjs/graphql';
import { MenuItemInput } from 'src/menu-items/dto/menu-item.input';

@InputType()
export class CreateMenuInput {
@Field()
name: string;

@Field(() => [MenuItemInput], { nullable: true })
items?: MenuItemInput[];
}
2 changes: 1 addition & 1 deletion src/menus/dto/update-menu.input.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Field, InputType, Int, PartialType } from '@nestjs/graphql';
import { CreateMenuInput } from './create-menu.input';
import { InputType, Field, Int, PartialType } from '@nestjs/graphql';

@InputType()
export class UpdateMenuInput extends PartialType(CreateMenuInput) {
Expand Down
4 changes: 2 additions & 2 deletions src/menus/entities/menu.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ export class Menu {
name: string;

@Field(() => [MenuItem], { nullable: true })
@OneToMany(() => MenuItem, (menuItem) => menuItem.menu)
items?: MenuItem[];
@OneToMany(() => MenuItem, (menuItem) => menuItem.menu, { lazy: true })
items?: Promise<MenuItem[]>;
}
4 changes: 3 additions & 1 deletion src/menus/menus.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ import { Module } from '@nestjs/common';
import { MenusService } from './menus.service';
import { MenusResolver } from './menus.resolver';
import { MenuItemsModule } from 'src/menu-items/menu-items.module';
import { Menu } from './entities/menu.entity';
import { TypeOrmModule } from '@nestjs/typeorm';

@Module({
imports: [MenuItemsModule],
imports: [TypeOrmModule.forFeature([Menu]), MenuItemsModule],
providers: [MenusResolver, MenusService],
})
export class MenusModule {}
25 changes: 13 additions & 12 deletions src/menus/menus.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ import { MenuItem } from 'src/menu-items/entities/menu-item.entity';

@Resolver(() => Menu)
export class MenusResolver {
constructor(
private readonly menusService: MenusService,
private readonly menuItemsService: MenuItemsService,
) {}
constructor(private readonly menusService: MenusService) {}

@Mutation(() => Menu)
createMenu(@Args('createMenuInput') createMenuInput: CreateMenuInput) {
Expand All @@ -41,14 +38,18 @@ export class MenusResolver {
return this.menusService.update(updateMenuInput.id, updateMenuInput);
}

@Mutation(() => Menu)
removeMenu(@Args('id', { type: () => Int }) id: number) {
return this.menusService.remove(id);
}
@Mutation(() => Boolean)
async removeMenu(@Args('id', { type: () => Int }) id: number) {
//return this.menusService.remove(id);
await this.menusService.remove(id);

@ResolveField('items', () => [MenuItem])
getItems(@Parent() menu: Menu) {
const { id } = menu;
return this.menuItemsService.findAll({ menuId: id });
return true;
}

// @ResolveField('items', () => [MenuItem])
// getItems(@Parent() menu: Menu) {
// //const { id } = menu;
// //return this.menuItemsService.findAll({ menuId: id });
// return menu.items;
// }
}
5 changes: 5 additions & 0 deletions src/menus/menus.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import { Test, TestingModule } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { Menu } from './entities/menu.entity';
import { MenusService } from './menus.service';

describe('MenusService', () => {
let service: MenusService;
let repository: Repository<Menu>;

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

service = module.get<MenusService>(MenusService);
repository = module.get<Repository<Menu>>(getRepositoryToken(Menu));
});

it('should be defined', () => {
Expand Down
Loading

0 comments on commit 4bad6d0

Please sign in to comment.