convert project from microservices to rest apis

This commit is contained in:
faris Aljohari
2024-03-10 12:49:51 +03:00
parent b3179a5c1f
commit c5537b3230
72 changed files with 155 additions and 384 deletions

View File

@ -0,0 +1,16 @@
import { Controller, Post } from '@nestjs/common';
import { AuthenticationService } from '../services/authentication.service';
import { ApiTags } from '@nestjs/swagger';
@Controller({
version: '1',
path: 'authentication',
})
@ApiTags('Tuya Auth')
export class AuthenticationController {
constructor(private readonly authenticationService: AuthenticationService) {}
@Post('auth')
async Authentication() {
return await this.authenticationService.main();
}
}

View File

@ -0,0 +1,2 @@
export * from './authentication.controller';
export * from './user-auth.controller';

View File

@ -0,0 +1,96 @@
import {
Body,
Controller,
Delete,
HttpStatus,
Param,
Post,
UseGuards,
} from '@nestjs/common';
import { UserAuthService } from '../services/user-auth.service';
import { UserSignUpDto } from '../dtos/user-auth.dto';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { ResponseMessage } from '../../../libs/common/src/response/response.decorator';
import { UserLoginDto } from '../dtos/user-login.dto';
import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard';
import { ForgetPasswordDto, UserOtpDto, VerifyOtpDto } from '../dtos';
@Controller({
version: '1',
path: 'authentication',
})
@ApiTags('Auth')
export class UserAuthController {
constructor(private readonly userAuthService: UserAuthService) {}
@ResponseMessage('User Registered Successfully')
@Post('user/signup')
async signUp(@Body() userSignUpDto: UserSignUpDto) {
const signupUser = await this.userAuthService.signUp(userSignUpDto);
return {
statusCode: HttpStatus.CREATED,
data: {
id: signupUser.uuid,
default: () => 'gen_random_uuid()', // this is a default value for the uuid column
},
message: 'User Registered Successfully',
};
}
@ResponseMessage('user logged in successfully')
@Post('user/login')
async userLogin(@Body() data: UserLoginDto) {
const accessToken = await this.userAuthService.userLogin(data);
return {
statusCode: HttpStatus.CREATED,
data: accessToken,
message: 'User Loggedin Successfully',
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Delete('user/delete/:id')
async userDelete(@Param('id') id: string) {
await this.userAuthService.deleteUser(id);
return {
statusCode: HttpStatus.OK,
data: {
id,
},
message: 'User Deleted Successfully',
};
}
@Post('user/send-otp')
async sendOtp(@Body() otpDto: UserOtpDto) {
const otpCode = await this.userAuthService.generateOTP(otpDto);
return {
statusCode: HttpStatus.OK,
data: {
otp: otpCode,
},
message: 'Otp Send Successfully',
};
}
@Post('user/verify-otp')
async verifyOtp(@Body() verifyOtpDto: VerifyOtpDto) {
await this.userAuthService.verifyOTP(verifyOtpDto);
return {
statusCode: HttpStatus.OK,
data: {},
message: 'Otp Verified Successfully',
};
}
@Post('user/forget-password')
async forgetPassword(@Body() forgetPasswordDto: ForgetPasswordDto) {
await this.userAuthService.forgetPassword(forgetPasswordDto);
return {
statusCode: HttpStatus.OK,
data: {},
message: 'Password changed successfully',
};
}
}