feat: adding some features to the user

This commit is contained in:
2026-07-19 17:07:27 +03:30
parent 1476770ec8
commit d9494da48f
9 changed files with 40 additions and 62 deletions
-22
View File
@@ -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!');
});
});
});
-12
View File
@@ -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();
}
}
-4
View File
@@ -1,6 +1,4 @@
import { Module } from '@nestjs/common';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { TypeOrmModule } from '@nestjs/typeorm';
import { ConfigModule, ConfigService } from '@nestjs/config';
import Joi from 'joi';
@@ -17,7 +15,5 @@ import { databaseConfig } from './config/typeorm.config';
TypeOrmModule.forRootAsync(databaseConfig()),
UsersModule
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
-8
View File
@@ -1,8 +0,0 @@
import { Injectable } from '@nestjs/common';
@Injectable()
export class AppService {
getHello(): string {
return 'Hello World!';
}
}
+2
View File
@@ -1,6 +1,8 @@
import * as Joi from 'joi';
export const validationSchema = Joi.object({
APP_PORT: Joi.number().required(),
DB_HOST: Joi.string().required(),
DB_PORT: Joi.number().required(),
DB_USER: Joi.string().required(),
+18 -12
View File
@@ -1,27 +1,33 @@
import { NestFactory, Reflector } from '@nestjs/core';
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 { ConfigService } from '@nestjs/config';
async function bootstrap() {
const logger = new Logger('APP');
const app = await NestFactory.create(AppModule);
app.useGlobalPipes(
new ValidationPipe(
{
whitelist: true,
forbidNonWhitelisted: true,
transform: true
}
)
new ValidationPipe({
whitelist: true,
forbidNonWhitelisted: true,
transform: true,
}),
);
app.useGlobalInterceptors(
new ClassSerializerInterceptor(app.get(Reflector))
);
app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector)));
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();
-2
View File
@@ -22,7 +22,6 @@ export class CreateUserDto {
lastName: string;
@ApiProperty({ example: 'mahdirafie@gmail.com' })
@MaxLength(20)
@IsEmail()
@MaxLength(100)
email: string;
@@ -36,6 +35,5 @@ export class CreateUserDto {
@ApiProperty({ example: 'MahdiPassword@5!' })
@IsString()
@MinLength(8)
@Exclude()
password: string;
}
+17 -2
View File
@@ -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')
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);
}
}
+3
View File
@@ -1,5 +1,6 @@
import { Entity, Column } from "typeorm";
import { BaseEntity } from "src/common/entities/base.entity";
import { Exclude } from "class-transformer";
@Entity('users')
export class User extends BaseEntity {
@@ -18,6 +19,7 @@ export class User extends BaseEntity {
@Column({
select: false
})
@Exclude()
password: string;
@Column({
@@ -25,5 +27,6 @@ export class User extends BaseEntity {
nullable: true,
select: false
})
@Exclude()
refreshToken: string;
}