From 2cf554caa40824ed71943bb81701eb901521067d Mon Sep 17 00:00:00 2001 From: morteza-mortezai Date: Thu, 11 Dec 2025 18:22:18 +0330 Subject: [PATCH] clean --- src/core/exceptions/response.interceptor.ts | 15 --------------- src/core/middlewares/logger.middleware.ts | 12 ++++++------ src/modules/admin/controllers/admin.controller.ts | 11 +---------- src/modules/auth/controllers/auth.controller.ts | 10 +--------- src/modules/cart/controllers/cart.controller.ts | 6 +----- .../contact/controllers/contact.controller.ts | 3 +-- .../coupons/controllers/coupon.controller.ts | 2 -- src/modules/foods/controllers/food.controller.ts | 2 -- .../controllers/restaurants.controller.ts | 12 +----------- .../review/controllers/review.controller.ts | 3 --- src/modules/roles/controllers/roles.controller.ts | 11 +---------- tsconfig.json | 2 +- 12 files changed, 13 insertions(+), 76 deletions(-) delete mode 100644 src/core/exceptions/response.interceptor.ts diff --git a/src/core/exceptions/response.interceptor.ts b/src/core/exceptions/response.interceptor.ts deleted file mode 100644 index 485a1d7..0000000 --- a/src/core/exceptions/response.interceptor.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common'; -import { map, Observable } from 'rxjs'; - -@Injectable() -export class ResponseInterceptor implements NestInterceptor { - intercept(context: ExecutionContext, next: CallHandler): Observable { - return next.handle().pipe( - map(data => ({ - success: true, - data, - timestamp: new Date().toISOString(), - })), - ); - } -} diff --git a/src/core/middlewares/logger.middleware.ts b/src/core/middlewares/logger.middleware.ts index 7234e54..1c84e35 100755 --- a/src/core/middlewares/logger.middleware.ts +++ b/src/core/middlewares/logger.middleware.ts @@ -1,19 +1,19 @@ -import { Injectable, Logger, NestMiddleware } from "@nestjs/common"; -import { FastifyReply, FastifyRequest } from "fastify"; +import { Injectable, Logger, NestMiddleware } from '@nestjs/common'; +import { FastifyReply, FastifyRequest } from 'fastify'; @Injectable() export class HTTPLogger implements NestMiddleware { private readonly logger = new Logger(HTTPLogger.name); // use(req: any, res: any, next: (error?: Error | any) => void) {} - use(req: FastifyRequest, rep: FastifyReply["raw"], next: () => void) { + use(req: FastifyRequest, rep: FastifyReply['raw'], next: () => void) { const { ip, method, originalUrl } = req; - const userAgent = req.headers["user-agent"] || ""; + const userAgent = req.headers['user-agent'] || ''; const startAt = process.hrtime(); - rep.on("finish", () => { + rep.on('finish', () => { const { statusCode } = rep; - const contentLength = rep.getHeader("content-length") || 0; + const contentLength = rep.getHeader('content-length') || 0; const dif = process.hrtime(startAt); const responseTime = dif[0] * 1e3 + dif[1] * 1e-6; this.logger.log( diff --git a/src/modules/admin/controllers/admin.controller.ts b/src/modules/admin/controllers/admin.controller.ts index f00bd1e..1e3b880 100644 --- a/src/modules/admin/controllers/admin.controller.ts +++ b/src/modules/admin/controllers/admin.controller.ts @@ -2,7 +2,7 @@ import { Controller, Post, Body, HttpCode, HttpStatus, Get, UseGuards, Patch, Pa import { AdminService } from '../providers/admin.service'; import { CreateAdminDto } from '../dto/create-admin.dto'; import { UpdateAdminDto } from '../dto/update-admin.dto'; -import { ApiTags, ApiOperation, ApiBody, ApiResponse, ApiBearerAuth, ApiParam } from '@nestjs/swagger'; +import { ApiTags, ApiOperation, ApiBody, ApiBearerAuth, ApiParam } from '@nestjs/swagger'; import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard'; import { RestId } from 'src/common/decorators'; import { AdminId } from 'src/common/decorators/admin-id.decorator'; @@ -17,7 +17,6 @@ export class AdminController { @Get() @ApiOperation({ summary: 'admin' }) - @ApiResponse({ status: 201, description: 'Admins' }) async getAll(@RestId() restId: string) { const admin = await this.adminService.findAllByRestaurantId(restId); return admin; @@ -25,7 +24,6 @@ export class AdminController { @Get('profile') @ApiOperation({ summary: 'admin' }) - @ApiResponse({ status: 201, description: 'Admins' }) async getMe(@AdminId() adminId: string, @RestId() restId: string) { const admin = await this.adminService.findById(adminId, restId); return admin; @@ -35,7 +33,6 @@ export class AdminController { @HttpCode(HttpStatus.CREATED) @ApiOperation({ summary: 'Create a new admin' }) @ApiBody({ type: CreateAdminDto }) - @ApiResponse({ status: 201, description: 'Admin created' }) async create(@Body() dto: CreateAdminDto, @RestId() restId: string) { const admin = await this.adminService.createAdminForMyRestaurant(restId, dto); return admin; @@ -45,24 +42,18 @@ export class AdminController { @ApiOperation({ summary: 'Update an admin' }) @ApiParam({ name: 'adminId', description: 'Admin ID' }) @ApiBody({ type: UpdateAdminDto }) - @ApiResponse({ status: 200, description: 'Admin updated successfully' }) - @ApiResponse({ status: 404, description: 'Admin not found' }) update(@Param('adminId') adminId: string, @Body() dto: UpdateAdminDto, @RestId() restId: string): Promise { return this.adminService.update(adminId, restId, dto); } @Get(':adminId') @ApiOperation({ summary: 'Get an admin by ID' }) @ApiParam({ name: 'id', description: 'Admin ID' }) - @ApiResponse({ status: 200, description: 'Admin found successfully' }) - @ApiResponse({ status: 404, description: 'Admin not found' }) getById(@Param('adminId') adminId: string, @RestId() restId: string): Promise { return this.adminService.findById(adminId, restId); } @Delete(':adminId') @ApiOperation({ summary: 'Delete an admin by ID' }) @ApiParam({ name: 'id', description: 'Admin ID' }) - @ApiResponse({ status: 200, description: 'Admin deleted successfully' }) - @ApiResponse({ status: 404, description: 'Admin not found' }) deleteById(@Param('adminId') adminId: string, @RestId() restId: string): Promise { return this.adminService.remove(adminId, restId); } diff --git a/src/modules/auth/controllers/auth.controller.ts b/src/modules/auth/controllers/auth.controller.ts index 4069c8a..5a5ef99 100644 --- a/src/modules/auth/controllers/auth.controller.ts +++ b/src/modules/auth/controllers/auth.controller.ts @@ -1,7 +1,7 @@ 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 { ApiTags, ApiOperation, ApiBody } from '@nestjs/swagger'; import { VerifyOtpDto } from '../dto/verify-otp.dto'; import { Throttle } from '@nestjs/throttler'; import { RefreshTokenRateLimit } from 'src/common/decorators/rate-limit.decorator'; @@ -16,8 +16,6 @@ export class AuthController { @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' }) - @ApiResponse({ status: 400, description: 'Invalid mobile number' }) otpRequest(@Body() dto: RequestOtpDto) { return this.authService.requestOtp(dto, false); } @@ -25,8 +23,6 @@ export class AuthController { @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' }) - @ApiResponse({ status: 400, description: 'Invalid OTP or expired' }) otpVerify(@Body() dto: VerifyOtpDto) { return this.authService.verifyOtp(dto.phone, dto.slug, dto.otp); // assuming dto has `otp` property } @@ -42,8 +38,6 @@ export class AuthController { @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); } @@ -51,8 +45,6 @@ export class AuthController { @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); } diff --git a/src/modules/cart/controllers/cart.controller.ts b/src/modules/cart/controllers/cart.controller.ts index b3a1e66..2d67553 100644 --- a/src/modules/cart/controllers/cart.controller.ts +++ b/src/modules/cart/controllers/cart.controller.ts @@ -8,7 +8,7 @@ import { SetPaymentMethodDto } from '../dto/set-payment-method.dto'; import { SetDeliveryMethodDto } from '../dto/set-delivery-method.dto'; import { SetDescriptionDto } from '../dto/set-description.dto'; import { SetTableNumberDto } from '../dto/set-table-number.dto'; -import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth, ApiBody, ApiParam } from '@nestjs/swagger'; +import { ApiTags, ApiOperation, ApiBearerAuth, ApiBody, ApiParam } from '@nestjs/swagger'; import { AuthGuard } from '../../auth/guards/auth.guard'; import { UserId } from 'src/common/decorators/user-id.decorator'; import { RestId } from 'src/common/decorators/rest-id.decorator'; @@ -67,15 +67,12 @@ export class CartController { @Delete('items/:foodId') @ApiOperation({ summary: 'Remove item from cart' }) @ApiParam({ name: 'foodId', description: 'Food ID in the cart' }) - @ApiResponse({ status: 200, description: 'Item removed from cart successfully' }) - @ApiResponse({ status: 404, description: 'Item not found in cart' }) async removeItem(@UserId() userId: string, @RestId() restaurantId: string, @Param('foodId') foodId: string) { return this.cartService.removeItem(userId, restaurantId, foodId); } @Delete() @ApiOperation({ summary: 'Clear entire cart' }) - @ApiResponse({ status: 200, description: 'Cart cleared successfully' }) async clearCart(@UserId() userId: string, @RestId() restaurantId: string) { return this.cartService.clearCart(userId, restaurantId); } @@ -89,7 +86,6 @@ export class CartController { @Delete('coupon') @ApiOperation({ summary: 'Remove coupon from cart' }) - @ApiResponse({ status: 200, description: 'Coupon removed successfully' }) async removeCoupon(@UserId() userId: string, @RestId() restaurantId: string) { return this.cartService.removeCoupon(userId, restaurantId); } diff --git a/src/modules/contact/controllers/contact.controller.ts b/src/modules/contact/controllers/contact.controller.ts index 204f88d..0a88cf0 100644 --- a/src/modules/contact/controllers/contact.controller.ts +++ b/src/modules/contact/controllers/contact.controller.ts @@ -15,7 +15,7 @@ import { ContactService } from '../providers/contact.service'; import { CreateContactDto } from '../dto/create-contact.dto'; import { FindContactsDto } from '../dto/find-contacts.dto'; import { UpdateContactStatusDto } from '../dto/update-contact-status.dto'; -import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth, ApiParam, ApiQuery } from '@nestjs/swagger'; +import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam, ApiQuery } from '@nestjs/swagger'; import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard'; @ApiTags('contact') @@ -25,7 +25,6 @@ export class ContactController { @Post('public/contact') @ApiOperation({ summary: 'Create a new contact (public endpoint)' }) - @ApiResponse({ status: 201, description: 'Contact created successfully' }) async create(@Body() createContactDto: CreateContactDto) { return this.contactService.create(createContactDto); } diff --git a/src/modules/coupons/controllers/coupon.controller.ts b/src/modules/coupons/controllers/coupon.controller.ts index 60f24ae..b627c75 100644 --- a/src/modules/coupons/controllers/coupon.controller.ts +++ b/src/modules/coupons/controllers/coupon.controller.ts @@ -6,7 +6,6 @@ import { FindCouponsDto } from '../dto/find-coupons.dto'; import { ApiTags, ApiOperation, - ApiResponse, ApiCreatedResponse, ApiOkResponse, ApiNotFoundResponse, @@ -93,7 +92,6 @@ export class CouponController { @Delete('admin/coupons/:id') @ApiOperation({ summary: 'Delete (soft) a coupon' }) @ApiParam({ name: 'id', required: true }) - @ApiResponse({ status: 200, description: 'Coupon deleted' }) remove(@Param('id') id: string) { return this.couponService.remove(id); } diff --git a/src/modules/foods/controllers/food.controller.ts b/src/modules/foods/controllers/food.controller.ts index 9b3b430..82ee387 100644 --- a/src/modules/foods/controllers/food.controller.ts +++ b/src/modules/foods/controllers/food.controller.ts @@ -6,7 +6,6 @@ import { FindFoodsDto } from '../dto/find-foods.dto'; import { ApiTags, ApiOperation, - ApiResponse, ApiCreatedResponse, ApiOkResponse, ApiNotFoundResponse, @@ -83,7 +82,6 @@ export class FoodController { @Delete('admin/foods/:id') @ApiOperation({ summary: 'Delete (soft) a food' }) @ApiParam({ name: 'id', required: true }) - @ApiResponse({ status: 200, description: 'Food deleted' }) remove(@Param('id') id: string) { return this.foodsService.remove(id); } diff --git a/src/modules/restaurants/controllers/restaurants.controller.ts b/src/modules/restaurants/controllers/restaurants.controller.ts index dc2f39e..a121bd0 100644 --- a/src/modules/restaurants/controllers/restaurants.controller.ts +++ b/src/modules/restaurants/controllers/restaurants.controller.ts @@ -3,15 +3,7 @@ import { RestaurantsService } from '../providers/restaurants.service'; import { CreateRestaurantDto } from '../dto/create-restaurant.dto'; import { UpdateRestaurantDto } from '../dto/update-restaurant.dto'; import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard'; -import { - ApiBearerAuth, - ApiBody, - ApiNotFoundResponse, - ApiOperation, - ApiParam, - ApiResponse, - ApiTags, -} from '@nestjs/swagger'; +import { ApiBearerAuth, ApiBody, ApiNotFoundResponse, ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger'; import { RestId } from 'src/common/decorators'; @ApiTags('restaurants') @@ -32,7 +24,6 @@ export class RestaurantsController { @Post('admin/restaurants') @ApiOperation({ summary: 'Create a new restaurant' }) @ApiBody({ type: CreateRestaurantDto }) - @ApiResponse({ status: 201, description: 'Restaurant created' }) create(@Body() createRestaurantDto: CreateRestaurantDto) { return this.restaurantsService.create(createRestaurantDto); } @@ -41,7 +32,6 @@ export class RestaurantsController { // @UseGuards(AdminAuthGuard) // @ApiBearerAuth() // @ApiOperation({ summary: 'Get all restaurants' }) - // @ApiResponse({ status: 200, description: 'Restaurants found' }) // findAll() { // return this.restaurantsService.findAll(); // } diff --git a/src/modules/review/controllers/review.controller.ts b/src/modules/review/controllers/review.controller.ts index eab1af1..16e84ad 100644 --- a/src/modules/review/controllers/review.controller.ts +++ b/src/modules/review/controllers/review.controller.ts @@ -7,7 +7,6 @@ import { ChangeStatusDto } from '../dto/change-status.dto'; import { ApiTags, ApiOperation, - ApiResponse, ApiCreatedResponse, ApiOkResponse, ApiQuery, @@ -87,7 +86,6 @@ export class ReviewController { @Delete('public/reviews/:id') @ApiOperation({ summary: 'Delete a review (own reviews only)' }) @ApiParam({ name: 'id', required: true }) - @ApiResponse({ status: 200, description: 'Review deleted' }) remove(@Param('id') id: string, @UserId() userId: string) { return this.reviewService.remove(id, userId, false); } @@ -146,7 +144,6 @@ export class ReviewController { @Delete('admin/reviews/:id') @ApiOperation({ summary: 'Delete a review (admin)' }) @ApiParam({ name: 'id', required: true }) - @ApiResponse({ status: 200, description: 'Review deleted' }) removeAdmin(@Param('id') id: string, @UserId() userId: string) { return this.reviewService.remove(id, userId, true); } diff --git a/src/modules/roles/controllers/roles.controller.ts b/src/modules/roles/controllers/roles.controller.ts index 0d60006..b4e6c7a 100644 --- a/src/modules/roles/controllers/roles.controller.ts +++ b/src/modules/roles/controllers/roles.controller.ts @@ -1,5 +1,5 @@ import { Controller, Get, Post, Body, Param, Patch, Delete, UseGuards } from '@nestjs/common'; -import { ApiTags, ApiOperation, ApiBody, ApiResponse, ApiBearerAuth } from '@nestjs/swagger'; +import { ApiTags, ApiOperation, ApiBody, ApiBearerAuth } from '@nestjs/swagger'; import { RolesService } from '../providers/roles.service'; import { PermissionsService } from '../providers/permissions.service'; import { CreateRoleDto } from '../dto/create-role.dto'; @@ -21,14 +21,12 @@ export class RolesController { @Get() @ApiOperation({ summary: 'Get all through restaurant roles with pagination and filters' }) - @ApiResponse({ status: 200, description: 'Restaurant roles retrieved successfully' }) findAll(@RestId() restId: string) { return this.roleService.findAllGeneralAndRestaurantRoles(restId); } @Get('permissions') @ApiOperation({ summary: 'Get all permissions that the admin has' }) - @ApiResponse({ status: 200, description: 'Permissions retrieved successfully' }) async findAllPermissions(@AdminId() adminId: string, @RestId() restId: string) { const adminPermissionNames = await this.permissionService.getAdminFullPermissions(adminId, restId); @@ -39,15 +37,12 @@ export class RolesController { @Post() @ApiOperation({ summary: 'Create a new role' }) @ApiBody({ type: CreateRoleDto }) - @ApiResponse({ status: 201, description: 'Role created successfully' }) create(@Body() dto: CreateRoleDto, @RestId() restId: string) { return this.roleService.createRestaurantRole(dto, restId); } @Get(':id') @ApiOperation({ summary: 'Get a specific role by ID' }) - @ApiResponse({ status: 200, description: 'Role retrieved successfully' }) - @ApiResponse({ status: 404, description: 'Role not found' }) findOne(@Param('id') id: string, @RestId() restId: string) { return this.roleService.findOne(restId, id); } @@ -55,16 +50,12 @@ export class RolesController { @Patch(':id') @ApiOperation({ summary: 'Update a role' }) @ApiBody({ type: UpdateRoleDto }) - @ApiResponse({ status: 200, description: 'Role updated successfully' }) - @ApiResponse({ status: 404, description: 'Role not found' }) update(@Param('id') id: string, @Body() dto: UpdateRoleDto, @RestId() restId: string) { return this.roleService.update(restId, id, dto); } @Delete(':id') @ApiOperation({ summary: 'Delete a role' }) - @ApiResponse({ status: 200, description: 'Role deleted successfully' }) - @ApiResponse({ status: 404, description: 'Role not found' }) remove(@Param('id') id: string, @RestId() restId: string) { return this.roleService.remove(restId, id); } diff --git a/tsconfig.json b/tsconfig.json index 98b93ab..d26a8e3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -17,7 +17,7 @@ "skipLibCheck": true, "strictNullChecks": true, "forceConsistentCasingInFileNames": true, - "noImplicitAny": false, + "noImplicitAny": true, "strictBindCallApply": false, "noFallthroughCasesInSwitch": false, "baseUrl": "./",