Skip to content

Instantly share code, notes, and snippets.

View rskhan167's full-sized avatar

Rasool Khan rskhan167

View GitHub Profile
@rskhan167
rskhan167 / user.controller.ts
Last active October 13, 2021 15:38
Nestjs Series - Part 3
import { Controller, Post, Body, Get, Param } from '@nestjs/common';
import { ApiOkResponse } from '@nestjs/swagger';
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) {}
@rskhan167
rskhan167 / nest-cli.json
Created October 13, 2021 15:21
Nestjs Series
{
"collection": "@nestjs/schematics",
"sourceRoot": "src",
"compilerOptions": {
"plugins": [
{
"name": "@nestjs/swagger/plugin",
"options": {
"dtoFileNameSuffix": [".entity.ts", ".dto.ts"],
"controllerFileNameSuffix": [".controller.ts"]
@rskhan167
rskhan167 / main.ts
Created October 13, 2021 15:00
Nestjs Series
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')
@rskhan167
rskhan167 / app.module.ts
Created September 27, 2021 09:19
Nest series
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],
@rskhan167
rskhan167 / main.ts
Created September 19, 2021 13:34
Nestjs Series
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();
@rskhan167
rskhan167 / user.service.ts
Created September 19, 2021 13:24
Nestjs Series
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(
import { IsNotEmpty, IsString, IsOptional } from 'class-validator';
export class CreateUserDto {
@IsNotEmpty()
@IsString()
name: string;
@IsNotEmpty()
@IsString()
email: string;
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) {}
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");',
);
@rskhan167
rskhan167 / user.entity.ts
Created September 19, 2021 11:39
Nestjs Series
import { Property, Entity, Unique, PrimaryKey } from '@mikro-orm/core';
import { IsEmail } from 'class-validator';
@Entity()
export class User {
@PrimaryKey()
id!: number;
@Property()
name: string;