clean
This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
|
||||
import { map, Observable } from 'rxjs';
|
||||
|
||||
@Injectable()
|
||||
export class ResponseInterceptor<T> implements NestInterceptor<T, any> {
|
||||
intercept(context: ExecutionContext, next: CallHandler<T>): Observable<any> {
|
||||
return next.handle().pipe(
|
||||
map(data => ({
|
||||
success: true,
|
||||
data,
|
||||
timestamp: new Date().toISOString(),
|
||||
})),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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(
|
||||
|
||||
@@ -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<Admin> {
|
||||
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<Admin | null> {
|
||||
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<void> {
|
||||
return this.adminService.remove(adminId, restId);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
// }
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@
|
||||
"skipLibCheck": true,
|
||||
"strictNullChecks": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noImplicitAny": false,
|
||||
"noImplicitAny": true,
|
||||
"strictBindCallApply": false,
|
||||
"noFallthroughCasesInSwitch": false,
|
||||
"baseUrl": "./",
|
||||
|
||||
Reference in New Issue
Block a user