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, Post, Body } from '@nestjs/common'; | |
import { UserService } from './user.service'; | |
import { User } from './user.entity'; | |
@Controller('user') | |
export class UserController { | |
constructor(private readonly userService: UserService) {} | |
@Get() | |
public async getUsers(): Promise<User[]> { |
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, Inject } from '@nestjs/common'; | |
import { USER_REPOSITORY } from '../utils/constants'; | |
import { User } from './user.entity'; | |
import { CreateUserDto } from './dto/index'; | |
@Injectable() | |
export class UserService { | |
constructor( | |
@Inject(USER_REPOSITORY) private readonly userRepository: typeof User, | |
) {} |
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 { UserService } from './user.service'; | |
import { UserController } from './user.controller'; | |
import { DatabaseModule } from '../database/database.module'; | |
import { userProviders } from './user.providers'; | |
@Module({ | |
imports: [DatabaseModule], | |
controllers: [UserController], | |
providers: [UserService, ...userProviders], |
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 class CreateUserDto { | |
readonly name: string; | |
readonly age: number; | |
readonly email: 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 { User } from './user.entity'; | |
import { USER_REPOSITORY } from '../utils/constants'; | |
export const userProviders = [ | |
{ | |
provide: USER_REPOSITORY, | |
useValue: User, | |
}, | |
]; |
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 { | |
Table, | |
Column, | |
Model, | |
DataType, | |
CreatedAt, | |
UpdatedAt, | |
DeletedAt, | |
} from 'sequelize-typescript'; | |
import { IDefineOptions } from 'sequelize-typescript/lib/interfaces/IDefineOptions'; |
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 { databaseProviders } from './database.providers'; | |
@Module({ | |
providers: [...databaseProviders], | |
exports: [...databaseProviders], | |
}) | |
export class DatabaseModule {} |
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'; | |
/** | |
* SEQUELIZE variable is stored in a file named | |
* 'constants' so it can be easily reused anywhere | |
* without being subject to human error. | |
*/ | |
import { SEQUELIZE } from '../utils/constants'; | |
import { User } from '../user/user.entity'; |
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
const Sequelize = require('sequelize') | |
const sequelize = new Sequelize( | |
process.env.DB_NAME, | |
process.env.DB_USERNAME, | |
process.env.DB_PASSWORD, | |
{ | |
host: process.env.DB_HOST, | |
port: process.env.DB_PORT, | |
dialect: process.env.DB_DIALECT, |
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
const express = require('express') | |
const bodyParser = require('body-parser') | |
const serverless = require('serverless-http') | |
const app = express() | |
/* Body Parser */ | |
app.use(bodyParser.json()) | |
app.use(bodyParser.urlencoded({ extended: false })) |
NewerOlder