This file contains hidden or 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 { MikroOrmModule } from '@mikro-orm/nestjs'; | |
import { AppController } from './app.controller'; | |
import { AppService } from './app.service'; | |
@Module({ | |
imports: [MikroOrmModule.forRoot()], | |
controllers: [AppController], | |
providers: [AppService], | |
}) |
This file contains hidden or 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 { Logger } from '@nestjs/common'; | |
import { Options } from '@mikro-orm/core'; | |
import { SqlHighlighter } from '@mikro-orm/sql-highlighter'; | |
import { TsMorphMetadataProvider } from '@mikro-orm/reflection'; | |
const logger = new Logger('MikroORM'); | |
const config = { | |
entities: ['dist/**/*.entity.js'], | |
entitiesTs: ['src/**/*.entity.ts'], | |
dbName: process.env.DBNAME || 'movie-review', |
This file contains hidden or 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 { Property, Entity, Unique, PrimaryKey } from '@mikro-orm/core'; | |
import { IsEmail } from 'class-validator'; | |
@Entity() | |
export class User { | |
@PrimaryKey() | |
id!: number; | |
@Property() | |
name: string; |
This file contains hidden or 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 { Migration } from '@mikro-orm/migrations'; | |
export class Migration20210808123050 extends Migration { | |
async up(): Promise<void> { | |
this.addSql( | |
'create table "user" ("id" serial primary key, "name" varchar(255) not null, "email" varchar(255) not null, "password" varchar(255) not null, "profile_image" varchar(255) null, "created_at" timestamptz(0) not null, "updated_at" timestamptz(0) not null);', | |
); | |
this.addSql( | |
'alter table "user" add constraint "user_email_unique" unique ("email");', | |
); |
This file contains hidden or 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, Post, Body } from '@nestjs/common'; | |
import { CreateUserDto } from './dtos/create-user.dto'; | |
import { UserService } from './user.service'; | |
import { User } from './entities/user.entity'; | |
@Controller('user') | |
export class UserController { | |
constructor(private readonly userService: UserService) {} |
This file contains hidden or 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 { IsNotEmpty, IsString, IsOptional } from 'class-validator'; | |
export class CreateUserDto { | |
@IsNotEmpty() | |
@IsString() | |
name: string; | |
@IsNotEmpty() | |
@IsString() | |
email: string; |
This file contains hidden or 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 { InjectRepository } from '@mikro-orm/nestjs'; | |
import { User } from './entities/user.entity'; | |
import { CreateUserDto } from './dtos/create-user.dto'; | |
import { UserRepository } from './user.repository'; | |
@Injectable() | |
export class UserService { | |
constructor( |
This file contains hidden or 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 { NestFactory } from '@nestjs/core'; | |
import { AppModule } from './app.module'; | |
async function bootstrap() { | |
const app = await NestFactory.create(AppModule); | |
app.setGlobalPrefix('api'); | |
await app.listen(3000); | |
} | |
bootstrap(); |
This file contains hidden or 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 { MikroOrmModule } from '@mikro-orm/nestjs'; | |
import { AppController } from './app.controller'; | |
import { AppService } from './app.service'; | |
import { UserModule } from './user/user.module'; | |
@Module({ | |
imports: [MikroOrmModule.forRoot(), UserModule], | |
controllers: [AppController], |
This file contains hidden or 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 { NestFactory } from '@nestjs/core'; | |
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'; | |
import { AppModule } from './app.module'; | |
async function bootstrap() { | |
const app = await NestFactory.create(AppModule); | |
app.setGlobalPrefix('api'); | |
const swaggerConfig = new DocumentBuilder() | |
.setTitle('NestJS Tutorial') |
OlderNewer