Skip to content

Commit

Permalink
feature: update kerna workspaces and finish graphql services by count…
Browse files Browse the repository at this point in the history
…ries
  • Loading branch information
ldiego73 committed May 25, 2020
1 parent 0751afa commit e8d679a
Show file tree
Hide file tree
Showing 47 changed files with 9,306 additions and 199 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
node_modules/
yarn-error.log
7 changes: 2 additions & 5 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
{
"version": "1.0.0",
"packages": [
"libs/*",
"microservices/**"
],
"npmClient": "yarn"
"npmClient": "yarn",
"useWorkspaces": true
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Sequelize, Dialect } from 'sequelize';
import { readEnv } from '@micro/country-config';
import { readEnv } from '@micro/countries-config';

const env = readEnv();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BaseCommand } from '../base.command';
import * as Commander from 'commander';
import prompts, { PromptObject, Answers } from 'prompts';
import { CountryDto } from '@micro/country-core';
import { CreateCountryUseCase } from '@micro/country-core/lib/application/use-cases/create-country';
import { CountryDto } from '@micro/countries-core';
import { CreateCountryUseCase } from '@micro/countries-core/lib/application/use-cases/create-country';

export class CreateCommand extends BaseCommand {
private useCase: CreateCountryUseCase;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createCountryUseCase } from '@micro/country-core';
import { createCountryUseCase } from '@micro/countries-core';
import { CreateCommand } from './create.command';

const createCommand = new CreateCommand(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { BaseCommand } from '../base.command';
import * as Commander from 'commander';
import { DeleteCountryUseCase } from '@micro/country-core/lib/application/use-cases/delete-country';
import { DeleteCountryUseCase } from '@micro/countries-core/lib/application/use-cases/delete-country';
import prompts from 'prompts';
import { IsoDto } from '@micro/country-core';
import { IsoDto } from '@micro/countries-core';

export class DeleteCommand extends BaseCommand {
private useCase: DeleteCountryUseCase;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { deleteCountryUseCase } from '@micro/country-core/lib/application/use-cases/delete-country';
import { deleteCountryUseCase } from '@micro/countries-core/lib/application/use-cases/delete-country';
import { DeleteCommand } from './delete.command';

const deleteCommand = new DeleteCommand(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BaseCommand } from '../base.command';
import * as Commander from 'commander';
import { FindCountryUseCase } from '@micro/country-core/lib/application/use-cases/find-country';
import { IsoDto } from '@micro/country-core/lib/application/dtos';
import { FindCountryUseCase } from '@micro/countries-core/lib/application/use-cases/find-country';
import { IsoDto } from '@micro/countries-core/lib/application/dtos';
import prompts from 'prompts';

export class FindCommand extends BaseCommand {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { findCountryUseCase } from '@micro/country-core/lib/application/use-cases/find-country';
import { findCountryUseCase } from '@micro/countries-core/lib/application/use-cases/find-country';
import { FindCommand } from './find.command';

const findCommand = new FindCommand(findCountryUseCase).create();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { listCountryUseCase } from '@micro/country-core/lib/application/use-cases/list-country';
import { listCountryUseCase } from '@micro/countries-core/lib/application/use-cases/list-country';
import { ListCommand } from './list.command';

const listCommand = new ListCommand(listCountryUseCase).create();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { BaseCommand } from '../base.command';
import * as Commander from 'commander';
import { ListCountryUseCase } from '@micro/country-core/lib/application/use-cases/list-country';
import { ListCountryUseCase } from '@micro/countries-core/lib/application/use-cases/list-country';

export class ListCommand extends BaseCommand {
private useCase: ListCountryUseCase;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { updateCountryUseCase } from '@micro/country-core/lib/application/use-cases/update-country';
import { updateCountryUseCase } from '@micro/countries-core/lib/application/use-cases/update-country';
import { UpdateCommand } from './update.command';
import { findCountryUseCase } from '@micro/country-core';
import { findCountryUseCase } from '@micro/countries-core';

const updateCommand = new UpdateCommand(
updateCountryUseCase,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { BaseCommand } from '../base.command';
import * as Commander from 'commander';
import { UpdateCountryUseCase } from '@micro/country-core/lib/application/use-cases/update-country';
import { FindCountryUseCase, IsoDto, CountryDto } from '@micro/country-core';
import { UpdateCountryUseCase } from '@micro/countries-core/lib/application/use-cases/update-country';
import { FindCountryUseCase, IsoDto, CountryDto } from '@micro/countries-core';
import prompts, { PromptObject, Answers } from 'prompts';

export class UpdateCommand extends BaseCommand {
Expand Down
12 changes: 12 additions & 0 deletions microservices/countries/interfaces/graphql/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
max_line_length = off
trim_trailing_whitespace = false
3 changes: 2 additions & 1 deletion microservices/countries/interfaces/graphql/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules/
reports/
lib/
.env
cert/
.env
7 changes: 7 additions & 0 deletions microservices/countries/interfaces/graphql/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"endOfLine": "auto",
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "es5"
}
9 changes: 9 additions & 0 deletions microservices/countries/interfaces/graphql/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
MIT License

Copyright (c) 2020 Luis Diego

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
52 changes: 52 additions & 0 deletions microservices/countries/interfaces/graphql/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "@micro/countries-graphql",
"version": "1.0.0",
"description": "Country GraphQL Interface",
"author": {
"name": "Luis Diego",
"email": "[email protected]",
"url": "http://github.com/ldiego73"
},
"license": "MIT",
"main": "lib/main.js",
"types": "lib/main.d.ts",
"files": [
"lib/"
],
"scripts": {
"clean": "rimraf lib",
"develop": "nest start --watch",
"prebuild": "yarn clean",
"build": "nest build"
},
"dependencies": {
"@micro/countries-config": "^1.0.0",
"@micro/countries-core": "^1.0.0",
"@micro/logger": "^1.0.0",
"@nestjs/cli": "^7.1.5",
"@nestjs/common": "^7.1.0",
"@nestjs/core": "^7.1.0",
"@nestjs/graphql": "^7.3.11",
"@nestjs/platform-fastify": "^7.1.0",
"apollo-server-fastify": "^2.13.1",
"fastify-compress": "^2.0.1",
"fastify-cors": "^3.0.3",
"fastify-rate-limit": "^3.0.1",
"graphql": "^15.0.0",
"graphql-tools": "^6.0.1",
"reflect-metadata": "^0.1.13",
"rxjs": "^6.5.5"
},
"devDependencies": {
"@nestjs/cli": "^7.1.5",
"@types/node": "^14.0.1",
"fastify-helmet": "^3.0.2",
"rimraf": "^3.0.2",
"ts-loader": "^7.0.4",
"ts-node": "^8.10.1",
"typescript": "^3.8.3",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11",
"webpack-node-externals": "^1.7.2"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './options';
17 changes: 17 additions & 0 deletions microservices/countries/interfaces/graphql/src/core/options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import fs from 'fs';
import path from 'path';
import { ServerOptionsAsSecureHttp } from 'fastify';

const readCert = (cert: string): Buffer =>
fs.readFileSync(path.join(process.cwd(), cert));

export const options = (
key: string,
cert: string
): ServerOptionsAsSecureHttp => ({
https: {
allowHTTP1: true,
key: readCert(key),
cert: readCert(cert),
},
});
37 changes: 37 additions & 0 deletions microservices/countries/interfaces/graphql/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { NestFactory } from '@nestjs/core';
import {
FastifyAdapter,
NestFastifyApplication,
} from '@nestjs/platform-fastify';
import helmet from 'fastify-helmet';
import cors from 'fastify-cors';
import compression from 'fastify-compress';
import rateLimit from 'fastify-rate-limit';

import { readEnv } from '@micro/countries-config';
import { Logger } from '@micro/logger';

import { options } from './core';
import { AppModule } from './modules/app.module';

const env = readEnv();
const { key, cert } = env.server.https!;
const log = Logger.create('Server');

async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
new FastifyAdapter(options(key, cert))
);

app.register(helmet);
app.register(cors);
app.register(compression, { encodings: ['gzip', 'deflate'] });
app.register(rateLimit, { max: 100, timeWindow: '1 minute' });

await app.listen(3000);

log.info(`Server listening at ${await app.getUrl()}`);
}

bootstrap();
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Field, InputType } from '@nestjs/graphql';

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

@Field()
iso!: string;

@Field()
currency!: string;

@Field()
status!: boolean;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Field, ObjectType } from '@nestjs/graphql';

@ObjectType()
export class Country {
@Field()
name!: string;

@Field()
iso!: string;

@Field()
currency!: string;

@Field()
status!: boolean;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './country.input';
export * from './country.model';
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Module } from '@nestjs/common';
import { GraphQLModule } from '@nestjs/graphql';
import path from 'path';

import { ListModule } from './list/list.module';
import { FindModule } from './find/find.module';
import { CreateModule } from './create/create.module';
import { DeleteModule } from './delete/delete.module';
import { UpdateModule } from './update/create.module';

const modules = [
ListModule,
FindModule,
CreateModule,
DeleteModule,
UpdateModule,
];

@Module({
imports: [
...modules,
GraphQLModule.forRoot({
autoSchemaFile: path.join(process.cwd(), 'src/schema.gql'),
}),
],
})
export class AppModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Module } from '@nestjs/common';
import { CreateResolver } from './create.resolver';
import { CreateService } from './create.service';

@Module({
providers: [CreateResolver, CreateService],
})
export class CreateModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Args, Mutation, Resolver } from '@nestjs/graphql';
import { CreateService } from './create.service';
import { CountryInput } from '../../models';

@Resolver()
export class CreateResolver {
constructor(private readonly service: CreateService) {}

@Mutation(returns => Boolean)
async create(@Args('input') input: CountryInput) {
return await this.service.execute(input);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Injectable } from '@nestjs/common';
import {
CreateCountryUseCase,
createCountryUseCase,
} from '@micro/countries-core/lib/application/use-cases';
import { CountryDto } from '@micro/countries-core/lib/application/dtos';
import { CountryInput } from '../../models';

@Injectable()
export class CreateService {
private readonly useCase: CreateCountryUseCase;

constructor() {
this.useCase = createCountryUseCase;
}

async execute(country: CountryInput): Promise<any> {;
const dto = country as CountryDto;
const result = await this.useCase.execute(dto);

if (result.isFailure()) {
throw result.error.message;
}

return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Module } from '@nestjs/common';
import { DeleteResolver } from './delete.resolver';
import { DeleteService } from './delete.service';

@Module({
providers: [DeleteResolver, DeleteService],
})
export class DeleteModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Args, Mutation, Resolver } from '@nestjs/graphql';
import { DeleteService } from './delete.service';

@Resolver()
export class DeleteResolver {
constructor(private readonly service: DeleteService) {}

@Mutation(returns => Boolean)
async delete(@Args('iso') iso: string) {
return await this.service.execute(iso);
}
}
Loading

0 comments on commit e8d679a

Please sign in to comment.