Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 5 additions & 29 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,17 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "tsconfig.json",
"sourceType": "module"
},
"plugins": ["@typescript-eslint/eslint-plugin", "import-helpers"],
"plugins": ["import-helpers"],
"extends": [
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
"@techmmunity/eslint-config/common",
"@techmmunity/eslint-config/typescript",
"@techmmunity/eslint-config/jest"
],
"root": true,
"env": {
"node": true,
"jest": true
},
"ignorePatterns": [".eslintrc.js"],
"rules": {
"@typescript-eslint/explicit-member-accessibility": ["error"],
"no-case-declarations": 0,
"accessor-pairs": ["warn", { "setWithoutGet": false }],
"no-param-reassign": "error",
"no-new": "off",
"no-prototype-builtins": "off",
"no-restricted-syntax": "off",
"max-classes-per-file": "off",
"no-underscore-dangle": "off",
"@typescript-eslint/camelcase": "off",
"prettier/prettier": "error",
"class-methods-use-this": "off",
"@typescript-eslint/no-unused-vars": 0,
"@typescript-eslint/interface-name-prefix": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-use-before-define": [
"error",
{ "functions": false }
],
"import-helpers/order-imports": [
"warn",
{
Expand Down
6 changes: 6 additions & 0 deletions .lintstagedrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"*.{ts,tsx}": [
"npx prettier --write src",
"eslint src/**/*.ts --fix-dry-run"
]
}
55 changes: 55 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Compiled Output
/dist
/node_modules

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# OS
.DS_Store

# Tests
/coverage
/.nyc_output

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
.settings/
*.sublime-workspace

# IDE - VSCode
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json

# Enviroment
*.env*
!.env.docker

# Core
src/core

# Local Database
/mongo-volume

# Auto Generated Files
src/schemas.gql

# Docker
docker/

# tsconfig
tsconfig*
!tsconfig.json
!tsconfig.build.json
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"bierner.markdown-preview-github-styles",
"pkief.material-icon-theme",
"esbenp.prettier-vscode",
"gruntfuggly.todo-tree"
"gruntfuggly.todo-tree",
"shardulm94.trailing-spaces"
]
}
24 changes: 7 additions & 17 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
// Disable Tab To Space Conversion
"editor.insertSpaces": false,

// Make Prettier The Default Code Formatter
"editor.defaultFormatter": "esbenp.prettier-vscode",

// Config Default End Of Line Formatting
"files.eol": "\n",

Expand All @@ -26,30 +23,23 @@

// Make VSCode understand this files as files of this languages
"files.associations": {
".env.hmg": "env",
".env.docker": "env",
".env.test": "env"
},
".prettierignore": "ignore",
".lintstagedrc": "json",
".env.*": "env"
},
"material-icon-theme.languages.associations": {
"env": "tune"
},

// ================ Languages General Config ====================

// TypeScript
"typescript.updateImportsOnFileMove.enabled": "always",
"typescript.tsserver.log": "verbose",
"typescript.suggest.autoImports": true,
"[typescript]": {
"editor.defaultFormatter": "vscode.typescript-language-features"
},
// JavaScript
"javascript.updateImportsOnFileMove.enabled": "always",
"javascript.suggest.autoImports": true,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
// JSON
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features"
},

// =========== Plugins & Extensions General Config ===============

Expand Down
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
coverageDirectory: "../coverage",
testEnvironment: "node",
moduleDirectories: ["node_modules", "src"],
clearMocks: true,
resetMocks: true,
// coverageThreshold: {
// global: {
// branches: 100,
Expand Down
26 changes: 12 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"@nestjs/swagger": "^4.8.0",
"@nestjs/terminus": "^7.1.2",
"@nestjs/typeorm": "^7.1.5",
"@techmmunity/database-error-handler": "^0.0.5",
"moment-timezone": "^0.5.33",
"node-fetch": "^2.6.1",
"pg": "^8.6.0",
Expand All @@ -27,44 +28,41 @@
"@nestjs/cli": "^7.6.0",
"@nestjs/schematics": "^7.3.1",
"@nestjs/testing": "^7.6.15",
"@techmmunity/eslint-config": "^1.2.1",
"@types/express": "^4.17.8",
"@types/jest": "^26.0.23",
"@types/node": "^15.0.1",
"@types/node-fetch": "^2.5.10",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^4.22.0",
"@typescript-eslint/parser": "^4.22.0",
"env-cmd": "^10.1.0",
"eslint": "^7.25.0",
"eslint-config-prettier": "8.3.0",
"eslint-plugin-import": "^2.22.1",
"@typescript-eslint/eslint-plugin": "^4.25.0",
"@typescript-eslint/parser": "^4.25.0",
"eslint": "^7.27.0",
"eslint-plugin-filenames": "^1.3.2",
"eslint-plugin-import": "^2.23.4",
"eslint-plugin-import-helpers": "^1.1.0",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-jest-formatting": "^3.0.0",
"eslint-plugin-prefer-arrow": "^1.2.3",
"eslint-plugin-prettier": "^3.4.0",
"eslint-plugin-sonarjs": "^0.7.0",
"husky": "^6.0.0",
"jest": "^26.6.3",
"lint-staged": "^10.5.4",
"prettier": "^2.1.2",
"prettier": "^2.3.0",
"supertest": "^6.0.0",
"ts-jest": "^26.5.5",
"ts-loader": "^9.1.1",
"ts-node": "^9.0.0",
"tsconfig-paths": "^3.9.0",
"typescript": "^4.2.4"
},
"lint-staged": {
"*.{ts,tsx}": [
"npx prettier --write src",
"eslint src/**/*.ts --fix-dry-run"
]
},
"scripts": {
"clear": "rimraf dist && rimraf tsconfig.build.tsbuildinfo && rimraf tsconfig.tsbuildinfo",
"clear:dev": "yarn clear && yarn dev",
"prebuild": "rimraf dist",
"build": "nest build",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
"start": "nest start",
"dev": "env-cmd yarn dev:docker",
"dev:docker": "nest start --watch --exec 'node -r tsconfig-paths/register'",
"start:debug": "nest start --debug --watch",
"start:prod": "node dist/main",
Expand Down
4 changes: 1 addition & 3 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@ import { V1Module } from "v1/v1.module";
@Module({
imports: [V1Module],
})
export class AppModule {
//
}
export class AppModule {}
8 changes: 4 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Logger } from "@nestjs/common";
import { NestFactory } from "@nestjs/core";
import { Swagger } from "swagger";
import { setSwagger } from "swagger";
import {
initializeTransactionalContext,
patchTypeORMRepositoryWithBaseRepository,
Expand All @@ -10,17 +10,17 @@ import { AppModule } from "./app.module";

const { PORT } = process.env;

async function server() {
const server = async () => {
initializeTransactionalContext();
patchTypeORMRepositoryWithBaseRepository();

const logger = new Logger("Main");

const app = await NestFactory.create(AppModule);

Swagger(app);
setSwagger(app);

app.listen(PORT, () => logger.log("Server Ready"));
}
};

server();
2 changes: 1 addition & 1 deletion src/swagger.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { INestApplication } from "@nestjs/common";
import { SwaggerModule, DocumentBuilder } from "@nestjs/swagger";

export const Swagger = (app: INestApplication) => {
export const setSwagger = (app: INestApplication) => {
const config = new DocumentBuilder()
.setTitle("Base Service")
.setDescription("")
Expand Down
8 changes: 4 additions & 4 deletions src/types/entity.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export type DefaultOmitEntityFields =
| "_id"
| "reload"
| "createdAt"
| "hasId"
| "recover"
| "softRemove"
| "reload"
| "remove"
| "save"
| "hasId"
| "createdAt"
| "softRemove"
| "updatedAt";
9 changes: 5 additions & 4 deletions src/types/env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
declare global {
namespace NodeJS {
interface ProcessEnv {
NODE_ENV: "dev" | "production" | "homolog" | "test";
NODE_ENV: "dev" | "homolog" | "production" | "test";
PORT: string;
POSTGRES_USER: string;
POSTGRES_PASSWORD: string;
Expand All @@ -13,7 +13,8 @@ declare global {
}
}

// If this file has no import/export statements (i.e. is a script)
// convert it into a module by adding an empty export statement.
// eslint-disable-next-line prettier/prettier
/*
* If this file has no import/export statements (i.e. is a script)
* convert it into a module by adding an empty export statement.
*/
export {};
18 changes: 8 additions & 10 deletions src/v1/api/health/health.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,23 @@ import {

import { ApiHealthIndicator } from "./health.indicator";

import { ApiConfig } from "v1/config";
import { CONFIG } from "v1/config";

@ApiTags("Health")
@Controller(`${ApiConfig.version}/health`)
@ApiTags(`${CONFIG.version} - Health`)
@Controller(`${CONFIG.version}/health`)
export class HealthController {
public constructor(
private health: HealthCheckService,
private db: TypeOrmHealthIndicator,
private api: ApiHealthIndicator,
) {
//
}
private readonly health: HealthCheckService,
private readonly db: TypeOrmHealthIndicator,
private readonly api: ApiHealthIndicator,
) {}

@Get()
@HealthCheck()
public check() {
return this.health.check([
() => this.db.pingCheck("database"),
() => this.api.pingCheck(`api/${ApiConfig.version}`),
() => this.api.pingCheck(`api/${CONFIG.version}`),
]);
}
}
1 change: 1 addition & 0 deletions src/v1/api/health/health.indicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { HealthIndicator } from "@nestjs/terminus";

@Injectable()
export class ApiHealthIndicator extends HealthIndicator {
// eslint-disable-next-line require-await
public async pingCheck(key: string) {
return this.getStatus(key, true);
}
Expand Down
4 changes: 1 addition & 3 deletions src/v1/api/health/health.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@ import { HealthController } from "./health.controller";
controllers: [HealthController],
providers: [ApiHealthIndicator],
})
export class HealthModule {
//
}
export class HealthModule {}
2 changes: 1 addition & 1 deletion src/v1/api/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { HealthModule } from "./health/health.module";

export const Api = [HealthModule];
export const API = [HealthModule];
2 changes: 1 addition & 1 deletion src/v1/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const ApiConfig = {
export const CONFIG = {
version: "v1",
};
2 changes: 1 addition & 1 deletion src/v1/config/limits.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export const Limits = {
export const LIMITS = {
ids: {
uuid: {
length: 36,
Expand Down
Loading