rename modules

This commit is contained in:
2025-11-25 09:28:55 +03:30
parent bd8c64f7c4
commit fb4ed33692
6 changed files with 64 additions and 84 deletions
+1 -2
View File
@@ -10,7 +10,6 @@ import { TokensService } from './services/tokens.service';
import { RestaurantsModule } from '../restaurants/restaurants.module';
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { User } from '../users/entities/user.entity';
import { AdminAuthController } from './controllers/admin-auth.controller';
import { AdminAuthGuard } from './guards/adminAuth.guard';
import { RefreshToken } from './entities/refresh-token.entity';
@@ -32,7 +31,7 @@ import { RefreshToken } from './entities/refresh-token.entity';
forwardRef(() => RestaurantsModule),
MikroOrmModule.forFeature([User, RefreshToken]),
],
controllers: [AuthController, AdminAuthController],
controllers: [AuthController],
providers: [AuthService, TokensService, AdminAuthGuard],
exports: [AdminAuthGuard],
})
@@ -1,40 +0,0 @@
import { Controller, Post, Body } from '@nestjs/common';
import { AuthService } from '../services/auth.service';
import { RequestOtpDto } from '../dto/request-otp.dto';
import { ApiTags, ApiOperation, ApiBody, ApiResponse } from '@nestjs/swagger';
import { VerifyOtpDto } from '../dto/verify-otp.dto';
import { Throttle } from '@nestjs/throttler';
import { RefreshTokenRateLimit } from 'src/common/decorators/rate-limit.decorator';
import { RefreshTokenDto } from '../dto/refresh-token.dto';
@ApiTags('admin/auth')
@Controller('admin/auth')
export class AdminAuthController {
constructor(private readonly authService: AuthService) {}
@Throttle({ default: { limit: 3, ttl: 180_000 } })
@Post('otp/request')
@ApiOperation({ summary: 'Request OTP for login or signup' })
@ApiBody({ type: RequestOtpDto, description: 'Mobile number to receive OTP' })
@ApiResponse({ status: 201, description: 'OTP requested successfully' })
@ApiResponse({ status: 400, description: 'Invalid mobile number' })
otpRequest(@Body() dto: RequestOtpDto) {
return this.authService.requestOtp(dto, true);
}
@Post('otp/verify')
@ApiOperation({ summary: 'Verify OTP code' })
@ApiBody({ type: VerifyOtpDto, description: 'Mobile number and OTP code' })
@ApiResponse({ status: 200, description: 'OTP verified successfully' })
@ApiResponse({ status: 400, description: 'Invalid OTP or expired' })
otpVerify(@Body() dto: VerifyOtpDto) {
return this.authService.verifyOtpAdmin(dto.phone, dto.slug, dto.otp); // assuming dto has `otp` property
}
@RefreshTokenRateLimit()
@ApiOperation({ summary: 'refresh the admin access token / refresh token' })
@Post('refresh')
refreshToken(@Body() refreshTokenDto: RefreshTokenDto) {
return this.authService.refreshToken(refreshTokenDto.refreshToken);
}
}
@@ -8,12 +8,12 @@ import { RefreshTokenRateLimit } from 'src/common/decorators/rate-limit.decorato
import { RefreshTokenDto } from '../dto/refresh-token.dto';
@ApiTags('auth')
@Controller('auth')
@Controller()
export class AuthController {
constructor(private readonly authService: AuthService) {}
@Throttle({ default: { limit: 3, ttl: 180_000 } })
@Post('otp/request')
@Post('public/auth/otp/request')
@ApiOperation({ summary: 'Request OTP for login or signup' })
@ApiBody({ type: RequestOtpDto, description: 'Mobile number to receive OTP' })
@ApiResponse({ status: 201, description: 'OTP requested successfully' })
@@ -22,7 +22,7 @@ export class AuthController {
return this.authService.requestOtp(dto, false);
}
@Post('otp/verify')
@Post('public/auth/otp/verify')
@ApiOperation({ summary: 'Verify OTP code' })
@ApiBody({ type: VerifyOtpDto, description: 'Mobile number and OTP code' })
@ApiResponse({ status: 200, description: 'OTP verified successfully' })
@@ -33,8 +33,34 @@ export class AuthController {
@RefreshTokenRateLimit()
@ApiOperation({ summary: 'refresh the user access token / refresh token' })
@Post('refresh')
@Post('public/auth/refresh')
refreshToken(@Body() refreshTokenDto: RefreshTokenDto) {
return this.authService.refreshToken(refreshTokenDto.refreshToken);
}
@Throttle({ default: { limit: 3, ttl: 180_000 } })
@Post('admin/auth/otp/request')
@ApiOperation({ summary: 'Request OTP for login or signup' })
@ApiBody({ type: RequestOtpDto, description: 'Mobile number to receive OTP' })
@ApiResponse({ status: 201, description: 'OTP requested successfully' })
@ApiResponse({ status: 400, description: 'Invalid mobile number' })
otpRequestAdmin(@Body() dto: RequestOtpDto) {
return this.authService.requestOtp(dto, true);
}
@Post('admin/auth/otp/verify')
@ApiOperation({ summary: 'Verify OTP code' })
@ApiBody({ type: VerifyOtpDto, description: 'Mobile number and OTP code' })
@ApiResponse({ status: 200, description: 'OTP verified successfully' })
@ApiResponse({ status: 400, description: 'Invalid OTP or expired' })
otpVerifyAdmin(@Body() dto: VerifyOtpDto) {
return this.authService.verifyOtpAdmin(dto.phone, dto.slug, dto.otp);
}
@RefreshTokenRateLimit()
@ApiOperation({ summary: 'refresh the admin access token / refresh token' })
@Post('admin/auth/refresh')
refreshTokenAdmin(@Body() refreshTokenDto: RefreshTokenDto) {
return this.authService.refreshToken(refreshTokenDto.refreshToken);
}
}
@@ -1,25 +0,0 @@
import { Controller, Get, UseGuards, Query, ValidationPipe } from '@nestjs/common';
import { ApiTags, ApiBearerAuth, ApiOperation, ApiOkResponse } from '@nestjs/swagger';
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
import { UserService } from '../user.service';
import { FindUsersDto } from '../dto/find-user.dto';
import { RestId } from 'src/common/decorators';
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@ApiTags('Admin/User')
@Controller('admin/user')
export class UsersController {
constructor(private readonly userService: UserService) {}
@ApiOperation({ summary: 'Get paginated list of users with filters' })
@ApiOkResponse({ description: 'Paginated list of users' })
@Get('/')
async findAll(
@Query(new ValidationPipe({ transform: true, whitelist: true }))
query: FindUsersDto,
@RestId() restId: string,
) {
return this.userService.findAll(restId, query);
}
}
@@ -1,28 +1,32 @@
import { Controller, Get, UseGuards, Patch, Body, ValidationPipe, Post } from '@nestjs/common';
import { Controller, Get, UseGuards, Patch, Body, ValidationPipe, Post, Query } from '@nestjs/common';
import { ApiTags, ApiBearerAuth, ApiOperation, ApiBody, ApiOkResponse } from '@nestjs/swagger';
import { AuthGuard } from 'src/modules/auth/guards/auth.guard';
import { UserService } from '../user.service';
import { UpdateUserDto } from '../dto/update-user.dto';
import { CreateUserAddressDto } from '../dto/create-user-address.dto';
import { UserId } from 'src/common/decorators/user-id.decorator';
import { RestId } from 'src/common/decorators';
import { FindUsersDto } from '../dto/find-user.dto';
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
@UseGuards(AuthGuard)
@ApiBearerAuth()
@ApiTags('User')
@Controller('user')
export class PublicUserController {
@Controller()
export class UsersController {
constructor(private readonly userService: UserService) {}
@UseGuards(AuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Get the current authenticated user profile' })
@Get('/me')
@Get('public/user/me')
async getUser(@UserId() userId: string) {
const user = await this.userService.findById(userId);
return user;
}
@UseGuards(AuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Update the authenticated user profile' })
@ApiBody({ type: UpdateUserDto })
@Patch('/')
@Patch('public/user/update')
async updateUser(
@UserId() userId: string,
@Body(new ValidationPipe({ transform: true, whitelist: true })) dto: UpdateUserDto,
@@ -31,18 +35,22 @@ export class PublicUserController {
return user;
}
@UseGuards(AuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Get all addresses for the authenticated user' })
@ApiOkResponse({ description: 'List of user addresses' })
@Get('/addresses')
@Get('public/user/addresses')
async getUserAddresses(@UserId() userId: string) {
const addresses = await this.userService.getUserAddresses(userId);
return addresses;
}
@UseGuards(AuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Create a new address for the authenticated user' })
@ApiBody({ type: CreateUserAddressDto })
@ApiOkResponse({ description: 'Created user address' })
@Post('/addresses')
@Post('public/user/addresses')
async createUserAddress(
@UserId() userId: string,
@Body(new ValidationPipe({ transform: true, whitelist: true })) dto: CreateUserAddressDto,
@@ -50,4 +58,17 @@ export class PublicUserController {
const address = await this.userService.createUserAddress(userId, dto);
return address;
}
@UseGuards(AdminAuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Get paginated list of restuarant users with filters' })
@ApiOkResponse({ description: 'Paginated list of users' })
@Get('admin/users')
async findAllRestaurantUsers(
@Query(new ValidationPipe({ transform: true, whitelist: true }))
query: FindUsersDto,
@RestId() restId: string,
) {
return this.userService.findAll(restId, query);
}
}
+2 -3
View File
@@ -1,7 +1,6 @@
import { Module } from '@nestjs/common';
import { UserService } from './user.service';
import { UsersController } from './controllers/user.controller';
import { PublicUserController } from './controllers/public-user.controller';
import { UsersController } from './controllers/users.controller';
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { User } from './entities/user.entity';
import { UserAddress } from './entities/user-address.entity';
@@ -10,7 +9,7 @@ import { UserRepository } from './repositories/user.repository';
@Module({
providers: [UserService, UserRepository],
controllers: [UsersController, PublicUserController],
controllers: [UsersController],
imports: [MikroOrmModule.forFeature([User, UserAddress]), JwtModule],
exports: [UserService, UserRepository],
})