This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Controller, Get } from '@nestjs/common'; | |
@Controller('posts') | |
export class PostsController { | |
@Get() | |
findAll(): string { | |
return 'This action returns all posts'; | |
} | |
@Get(:id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@nestjs/common'; | |
import { Post } from './interfaces/post.interface'; | |
@Injectable() | |
export class PostsService { | |
private readonly posts: Post[] = []; | |
create(post: Post) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface Post { | |
title: string; | |
body: string; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Module } from '@nestjs/common'; | |
import { PostsController } from './posts.controller'; | |
import { PostsService } from './posts.service'; | |
@Module({ | |
controllers: [PostsController], | |
providers: [PostsService], | |
}) | |
export class PostsModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Module } from '@nestjs/common'; | |
import { PostsModule } from './posts/posts.module'; | |
@Module({ | |
imports: [PostsModule], | |
}) | |
export class AppModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface IDatabaseConfigAttributes { | |
username?: string; | |
password?: string; | |
database?: string; | |
host?: string; | |
port?: number | string; | |
dialect?: string; | |
urlDatabase?: string; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as dotenv from 'dotenv'; | |
import { IDatabaseConfig } from './interfaces/dbConfig.interface'; | |
dotenv.config(); | |
export const databaseConfig: IDatabaseConfig = { | |
development: { | |
username: process.env.DB_USER, | |
password: process.env.DB_PASS, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DB_HOST=localhost | |
DB_PORT=5432 | |
DB_USER=database_user_name | |
DB_PASS=database_password | |
DB_DIALECT=postgres | |
DB_NAME_TEST=test_database_name | |
DB_NAME_DEVELOPMENT=development_database_name | |
DB_NAME_PRODUCTION=production_database_name | |
JWTKEY=random_secret_key | |
TOKEN_EXPIRATION=48h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Module } from '@nestjs/common'; | |
import { ConfigModule } from '@nestjs/config'; | |
@Module({ | |
imports: [ | |
ConfigModule.forRoot({ isGlobal: true }), | |
] | |
}) | |
export class AppModule { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Sequelize } from 'sequelize-typescript'; | |
import { SEQUELIZE, DEVELOPMENT, TEST, PRODUCTION } from '../constants'; | |
import { databaseConfig } from './database.config'; | |
export const databaseProviders = [{ | |
provide: SEQUELIZE, | |
useFactory: async () => { | |
let config; |
OlderNewer