feat: adding some features to the user
This commit is contained in:
@@ -1,22 +0,0 @@
|
|||||||
import { Test, TestingModule } from '@nestjs/testing';
|
|
||||||
import { AppController } from './app.controller';
|
|
||||||
import { AppService } from './app.service';
|
|
||||||
|
|
||||||
describe('AppController', () => {
|
|
||||||
let appController: AppController;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
const app: TestingModule = await Test.createTestingModule({
|
|
||||||
controllers: [AppController],
|
|
||||||
providers: [AppService],
|
|
||||||
}).compile();
|
|
||||||
|
|
||||||
appController = app.get<AppController>(AppController);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('root', () => {
|
|
||||||
it('should return "Hello World!"', () => {
|
|
||||||
expect(appController.getHello()).toBe('Hello World!');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
import { Controller, Get } from '@nestjs/common';
|
|
||||||
import { AppService } from './app.service';
|
|
||||||
|
|
||||||
@Controller()
|
|
||||||
export class AppController {
|
|
||||||
constructor(private readonly appService: AppService) {}
|
|
||||||
|
|
||||||
@Get()
|
|
||||||
getHello(): string {
|
|
||||||
return this.appService.getHello();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,4 @@
|
|||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { AppController } from './app.controller';
|
|
||||||
import { AppService } from './app.service';
|
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||||
import Joi from 'joi';
|
import Joi from 'joi';
|
||||||
@@ -17,7 +15,5 @@ import { databaseConfig } from './config/typeorm.config';
|
|||||||
TypeOrmModule.forRootAsync(databaseConfig()),
|
TypeOrmModule.forRootAsync(databaseConfig()),
|
||||||
UsersModule
|
UsersModule
|
||||||
],
|
],
|
||||||
controllers: [AppController],
|
|
||||||
providers: [AppService],
|
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class AppService {
|
|
||||||
getHello(): string {
|
|
||||||
return 'Hello World!';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
import * as Joi from 'joi';
|
import * as Joi from 'joi';
|
||||||
|
|
||||||
export const validationSchema = Joi.object({
|
export const validationSchema = Joi.object({
|
||||||
|
APP_PORT: Joi.number().required(),
|
||||||
|
|
||||||
DB_HOST: Joi.string().required(),
|
DB_HOST: Joi.string().required(),
|
||||||
DB_PORT: Joi.number().required(),
|
DB_PORT: Joi.number().required(),
|
||||||
DB_USER: Joi.string().required(),
|
DB_USER: Joi.string().required(),
|
||||||
|
|||||||
+18
-12
@@ -1,27 +1,33 @@
|
|||||||
import { NestFactory, Reflector } from '@nestjs/core';
|
import { NestFactory, Reflector } from '@nestjs/core';
|
||||||
import { AppModule } from './app.module';
|
import { AppModule } from './app.module';
|
||||||
import { ClassSerializerInterceptor, ValidationPipe } from '@nestjs/common';
|
import { ClassSerializerInterceptor, Logger, ValidationPipe } from '@nestjs/common';
|
||||||
import { setupSwagger } from './config/swagger.config';
|
import { setupSwagger } from './config/swagger.config';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
|
const logger = new Logger('APP');
|
||||||
|
|
||||||
const app = await NestFactory.create(AppModule);
|
const app = await NestFactory.create(AppModule);
|
||||||
|
|
||||||
app.useGlobalPipes(
|
app.useGlobalPipes(
|
||||||
new ValidationPipe(
|
new ValidationPipe({
|
||||||
{
|
whitelist: true,
|
||||||
whitelist: true,
|
forbidNonWhitelisted: true,
|
||||||
forbidNonWhitelisted: true,
|
transform: true,
|
||||||
transform: true
|
}),
|
||||||
}
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
app.useGlobalInterceptors(
|
app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector)));
|
||||||
new ClassSerializerInterceptor(app.get(Reflector))
|
|
||||||
);
|
|
||||||
|
|
||||||
setupSwagger(app);
|
setupSwagger(app);
|
||||||
|
|
||||||
await app.listen(process.env.PORT ?? 3000);
|
const configService = app.get<ConfigService>(ConfigService);
|
||||||
|
|
||||||
|
|
||||||
|
const PORT = configService.getOrThrow<number>('APP_PORT');
|
||||||
|
await app.listen(PORT, '0.0.0.0', () => {
|
||||||
|
logger.log(`Server running at http://localhost:${PORT}`);
|
||||||
|
logger.log(`Swagger is serving at http://localhost:${PORT}/api-docs`);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
bootstrap();
|
bootstrap();
|
||||||
|
|||||||
@@ -22,7 +22,6 @@ export class CreateUserDto {
|
|||||||
lastName: string;
|
lastName: string;
|
||||||
|
|
||||||
@ApiProperty({ example: 'mahdirafie@gmail.com' })
|
@ApiProperty({ example: 'mahdirafie@gmail.com' })
|
||||||
@MaxLength(20)
|
|
||||||
@IsEmail()
|
@IsEmail()
|
||||||
@MaxLength(100)
|
@MaxLength(100)
|
||||||
email: string;
|
email: string;
|
||||||
@@ -36,6 +35,5 @@ export class CreateUserDto {
|
|||||||
@ApiProperty({ example: 'MahdiPassword@5!' })
|
@ApiProperty({ example: 'MahdiPassword@5!' })
|
||||||
@IsString()
|
@IsString()
|
||||||
@MinLength(8)
|
@MinLength(8)
|
||||||
@Exclude()
|
|
||||||
password: string;
|
password: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,21 @@
|
|||||||
import { Controller } from '@nestjs/common';
|
import { Body, Controller, Get, Post } from '@nestjs/common';
|
||||||
|
import { ApiOperation, ApiResponse } from '@nestjs/swagger';
|
||||||
|
import { CreateUserDto } from '../DTO/create-user.dto';
|
||||||
|
import { User } from '../entities/user.entity';
|
||||||
|
import { UsersService } from '../providers/users.service';
|
||||||
|
|
||||||
@Controller('users')
|
@Controller('users')
|
||||||
export class UsersController {
|
export class UsersController {
|
||||||
|
|
||||||
|
constructor(
|
||||||
|
private readonly userService: UsersService
|
||||||
|
) {}
|
||||||
|
|
||||||
|
@Post('signup')
|
||||||
|
@ApiOperation({summary: 'Create a new user!'})
|
||||||
|
@ApiResponse({status: 201, description: 'User created successfully!'})
|
||||||
|
@ApiResponse({status: 400, description: 'Bad Request from User!'})
|
||||||
|
signupUser(@Body() body: CreateUserDto): Promise<User> {
|
||||||
|
return this.userService.signupUser(body);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Entity, Column } from "typeorm";
|
import { Entity, Column } from "typeorm";
|
||||||
import { BaseEntity } from "src/common/entities/base.entity";
|
import { BaseEntity } from "src/common/entities/base.entity";
|
||||||
|
import { Exclude } from "class-transformer";
|
||||||
|
|
||||||
@Entity('users')
|
@Entity('users')
|
||||||
export class User extends BaseEntity {
|
export class User extends BaseEntity {
|
||||||
@@ -18,6 +19,7 @@ export class User extends BaseEntity {
|
|||||||
@Column({
|
@Column({
|
||||||
select: false
|
select: false
|
||||||
})
|
})
|
||||||
|
@Exclude()
|
||||||
password: string;
|
password: string;
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
@@ -25,5 +27,6 @@ export class User extends BaseEntity {
|
|||||||
nullable: true,
|
nullable: true,
|
||||||
select: false
|
select: false
|
||||||
})
|
})
|
||||||
|
@Exclude()
|
||||||
refreshToken: string;
|
refreshToken: string;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user