This commit is contained in:
2025-12-13 10:35:15 +03:30
parent 85b4e5bb6a
commit 3eb6b889a4
20 changed files with 114 additions and 20 deletions
@@ -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, ApiBearerAuth, ApiParam } from '@nestjs/swagger';
import { ApiTags, ApiOperation, ApiBody, ApiBearerAuth, ApiParam, ApiHeader } 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';
@@ -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, ApiBearerAuth, ApiBody, ApiParam } from '@nestjs/swagger';
import { ApiTags, ApiOperation, ApiBearerAuth, ApiBody, ApiParam, ApiHeader } 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';
@@ -22,12 +22,14 @@ export class CartController {
@Get()
@ApiOperation({ summary: 'Get cart for current user and restaurant' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
async findOne(@UserId() userId: string, @RestId() restaurantId: string) {
return this.cartService.getOrCreateCart(userId, restaurantId);
}
@Post('items/:foodId/increment')
@ApiOperation({ summary: 'Increment item quantity in cart by 1' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiParam({ name: 'foodId', description: 'Food ID to increment in cart' })
async incrementItem(@UserId() userId: string, @RestId() restaurantId: string, @Param('foodId') foodId: string) {
return this.cartService.incrementItem(userId, restaurantId, foodId);
@@ -35,6 +37,7 @@ export class CartController {
@Post('items/:foodId/decrement')
@ApiOperation({ summary: 'Decrement item quantity in cart by 1 (removes item if quantity reaches 0)' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiParam({ name: 'foodId', description: 'Food ID to decrement in cart' })
async decrementItem(@UserId() userId: string, @RestId() restaurantId: string, @Param('foodId') foodId: string) {
return this.cartService.decrementItem(userId, restaurantId, foodId);
@@ -42,6 +45,7 @@ export class CartController {
@Post('items/bulk')
@ApiOperation({ summary: 'Bulk add items to cart (increments quantity if items exist)' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiBody({ type: BulkAddItemsToCartDto })
bulkAddItems(
@UserId() userId: string,
@@ -53,6 +57,7 @@ export class CartController {
@Patch('items/:foodId')
@ApiOperation({ summary: 'Update item quantity in cart' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiParam({ name: 'foodId', description: 'Food ID in the cart' })
@ApiBody({ type: UpdateItemQuantityDto })
async updateItemQuantity(
@@ -66,6 +71,7 @@ export class CartController {
@Delete('items/:foodId')
@ApiOperation({ summary: 'Remove item from cart' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiParam({ name: 'foodId', description: 'Food ID in the cart' })
async removeItem(@UserId() userId: string, @RestId() restaurantId: string, @Param('foodId') foodId: string) {
return this.cartService.removeItem(userId, restaurantId, foodId);
@@ -73,12 +79,14 @@ export class CartController {
@Delete()
@ApiOperation({ summary: 'Clear entire cart' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
async clearCart(@UserId() userId: string, @RestId() restaurantId: string) {
return this.cartService.clearCart(userId, restaurantId);
}
@Post('apply-coupon')
@ApiOperation({ summary: 'Apply coupon to cart' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiBody({ type: ApplyCouponDto })
async applyCoupon(@UserId() userId: string, @RestId() restaurantId: string, @Body() applyCouponDto: ApplyCouponDto) {
return this.cartService.applyCoupon(userId, restaurantId, applyCouponDto);
@@ -86,12 +94,14 @@ export class CartController {
@Delete('coupon')
@ApiOperation({ summary: 'Remove coupon from cart' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
async removeCoupon(@UserId() userId: string, @RestId() restaurantId: string) {
return this.cartService.removeCoupon(userId, restaurantId);
}
@Patch('address')
@ApiOperation({ summary: 'Set address for cart' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiBody({ type: SetAddressDto })
async setAddress(@UserId() userId: string, @RestId() restaurantId: string, @Body() setAddressDto: SetAddressDto) {
return this.cartService.setAddress(userId, restaurantId, setAddressDto);
@@ -99,6 +109,7 @@ export class CartController {
@Patch('payment-method')
@ApiOperation({ summary: 'Set payment method for cart' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiBody({ type: SetPaymentMethodDto })
async setPaymentMethod(
@UserId() userId: string,
@@ -110,6 +121,7 @@ export class CartController {
@Patch('delivery-method')
@ApiOperation({ summary: 'Set delivery method for cart' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiBody({ type: SetDeliveryMethodDto })
setDeliveryMethod(
@UserId() userId: string,
@@ -121,6 +133,7 @@ export class CartController {
@Patch('description')
@ApiOperation({ summary: 'Set description for cart' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiBody({ type: SetDescriptionDto })
setDescription(
@UserId() userId: string,
@@ -132,6 +145,7 @@ export class CartController {
@Patch('table-number')
@ApiOperation({ summary: 'Set table number for cart (required when delivery method is DineIn)' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiBody({ type: SetTableNumberDto })
setTableNumber(
@UserId() userId: string,
@@ -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, ApiBearerAuth, ApiParam, ApiQuery } from '@nestjs/swagger';
import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam, ApiQuery, ApiHeader } from '@nestjs/swagger';
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
@ApiTags('contact')
@@ -25,6 +25,7 @@ export class ContactController {
@Post('public/contact')
@ApiOperation({ summary: 'Create a new contact (public endpoint)' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
async create(@Body() createContactDto: CreateContactDto) {
return this.contactService.create(createContactDto);
}
@@ -13,6 +13,7 @@ import {
ApiBody,
ApiParam,
ApiBearerAuth,
ApiHeader,
} from '@nestjs/swagger';
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
import { RestId } from 'src/common/decorators';
@@ -27,6 +28,7 @@ export class CouponController {
@ApiBearerAuth()
@Get('public/coupons/me')
@ApiOperation({ summary: 'Get paginated list of restaurant coupons' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiOkResponse({ description: 'Paginated list of restaurant coupons' })
@ApiQuery({ name: 'page', required: false, type: Number })
@ApiQuery({ name: 'limit', required: false, type: Number })
@@ -8,6 +8,7 @@ import {
ApiParam,
ApiBody,
ApiBearerAuth,
ApiHeader,
} from '@nestjs/swagger';
import { DeliveryService } from '../providers/delivery.service';
import { CreateDeliveryDto } from '../dto/create-delivery.dto';
@@ -26,6 +27,7 @@ export class DeliveryController {
@ApiBearerAuth()
@Get('public/delivery-methods/restaurant')
@ApiOperation({ summary: 'Get restaurant delivery methods' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiOkResponse({
description: 'List of restaurant delivery methods',
type: [Delivery],
@@ -12,6 +12,7 @@ import {
ApiBody,
ApiQuery,
ApiBearerAuth,
ApiHeader,
} from '@nestjs/swagger';
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
import { UseGuards } from '@nestjs/common';
@@ -24,6 +25,7 @@ export class CategoryController {
@Get('public/categories/restaurant/:slug')
@ApiOperation({ summary: 'Get all categories by restaurant slug' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiParam({ name: 'slug', required: true, description: 'Restaurant Slug' })
@ApiOkResponse({ description: 'List of all categories for the restaurant' })
findAllByRestaurant(@Param('slug') slug: string) {
@@ -13,6 +13,7 @@ import {
ApiBody,
ApiParam,
ApiBearerAuth,
ApiHeader,
} from '@nestjs/swagger';
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
import { RestId } from 'src/common/decorators';
@@ -24,6 +25,7 @@ export class FoodController {
@Get('public/foods/restaurant/:slug')
@ApiOperation({ summary: 'Get all foods by restaurant slug' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiParam({ name: 'slug', required: true, description: 'Restaurant Slug' })
@ApiOkResponse({ description: 'List of all foods for the restaurant' })
findAllByRestaurant(@Param('slug') slug: string) {
@@ -1,5 +1,5 @@
import { Controller, Post, Get, Body, Param, UseGuards, Query, Patch, Delete } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam, ApiQuery } from '@nestjs/swagger';
import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam, ApiQuery, ApiHeader } from '@nestjs/swagger';
import { NotificationService } from '../services/notification.service';
import { NotificationPreferenceService } from '../services/notification-preference.service';
import { CreatePreferenceDto } from '../dto/create-preference.dto';
@@ -21,6 +21,7 @@ export class NotificationsController {
@ApiBearerAuth()
@Get('public/notifications')
@ApiOperation({ summary: 'Get user restaurant notifications' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiQuery({ name: 'limit', required: false, type: Number })
async getUserNotifications(@UserId() userId: string, @RestId() restaurantId: string, @Query('limit') limit?: number) {
return await this.notificationService.findByUserAndRestaurant(
@@ -1,5 +1,5 @@
import { Controller, Get, Post, Param, UseGuards, Patch, Query } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam } from '@nestjs/swagger';
import { ApiTags, ApiOperation, ApiBearerAuth, ApiParam, ApiHeader } from '@nestjs/swagger';
import { OrdersService } from '../providers/orders.service';
import { AuthGuard } from '../../auth/guards/auth.guard';
import { UserId } from '../../../common/decorators/user-id.decorator';
@@ -16,6 +16,7 @@ export class OrdersController {
@ApiBearerAuth()
@Post('public/checkout')
@ApiOperation({ summary: 'Checkout : create order and payment record' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
checkout(@UserId() userId: string, @RestId() restaurantId: string) {
return this.ordersService.checkout(userId, restaurantId);
}
@@ -24,6 +25,7 @@ export class OrdersController {
@ApiBearerAuth()
@Get('public/orders')
@ApiOperation({ summary: 'Get all orders with pagination and filters' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
findAll(@RestId() restId: string, @Query() dto: FindOrdersDto, @UserId() userId: string) {
return this.ordersService.findAllForUser(restId, dto, userId);
}
@@ -31,6 +33,7 @@ export class OrdersController {
@UseGuards(AuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Get an order By id for User' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiParam({ name: 'orderId', description: 'Order ID' })
@Get('public/orders/:orderId')
findOne(@Param('orderId') orderId: string, @RestId() restId: string) {
@@ -41,6 +44,7 @@ export class OrdersController {
@ApiBearerAuth()
@Patch('public/orders/:id/cancel')
@ApiOperation({ summary: 'Cancel an order By User' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiParam({ name: 'id', description: 'Order ID' })
cancelOrder(@Param('id') id: string, @RestId() restId: string) {
return this.ordersService.cancelOrderAsUser(id, restId);
@@ -57,7 +57,7 @@ export class PagerController {
@UseGuards(OptionalAuthGuard)
@Get('public/pager')
@ApiOperation({ summary: 'Get all pager requests for the current session' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiHeader({ name: 'Authorization', required: false, description: 'Bearer token (optional authentication)' })
async findAll(@Req() request: FastifyRequest) {
const cookieId = request.cookies['pagerId'] || undefined;
@@ -1,6 +1,14 @@
import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common';
import { PaymentsService } from '../services/payments.service';
import { ApiTags, ApiOperation, ApiNotFoundResponse, ApiBody, ApiParam, ApiBearerAuth } from '@nestjs/swagger';
import {
ApiTags,
ApiOperation,
ApiNotFoundResponse,
ApiBody,
ApiParam,
ApiBearerAuth,
ApiHeader,
} from '@nestjs/swagger';
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
import { PaymentMethodService } from '../services/payment-method.service';
import { CreatePaymentMethodDto } from '../dto/create-payment-method.dto';
@@ -21,6 +29,7 @@ export class PaymentsController {
@ApiBearerAuth()
@Get('public/payments/methods/restaurant')
@ApiOperation({ summary: 'Get the restaurant payment methods' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiNotFoundResponse({ description: 'Restaurant payment methods not found' })
getTheRestaurantPaymentMethods(@RestId() restId: string) {
return this.paymentMethodService.findByRestaurant(restId);
@@ -30,6 +39,7 @@ export class PaymentsController {
@ApiBearerAuth()
@Get('public/payments')
@ApiOperation({ summary: 'Get all the restaurant payments for user' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
findAllByRestaurant(@UserId() userId: string, @RestId() restId: string) {
return this.paymentsService.findAllByRestaurantId(restId, userId);
}
@@ -117,6 +127,7 @@ export class PaymentsController {
@Post('public/payments/verify')
@ApiOperation({ summary: 'Verify a payment' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiBody({ type: VerifyPaymentDto })
@ApiNotFoundResponse({ description: 'Payment not found' })
verifyPayment(@Body() verifyPaymentDto: VerifyPaymentDto) {
@@ -3,7 +3,15 @@ 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, ApiTags } from '@nestjs/swagger';
import {
ApiBearerAuth,
ApiBody,
ApiNotFoundResponse,
ApiOperation,
ApiParam,
ApiTags,
ApiHeader,
} from '@nestjs/swagger';
import { RestId } from 'src/common/decorators';
@ApiTags('restaurants')
@@ -13,6 +21,7 @@ export class RestaurantsController {
@Get('public/restaurants/:slug')
@ApiOperation({ summary: 'Get restaurant specification by slug' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiParam({ name: 'slug', required: true, description: 'Restaurant slug' })
@ApiNotFoundResponse({ description: 'Restaurant not found' })
findBySlug(@Param('slug') slug: string) {
@@ -9,6 +9,7 @@ import {
ApiBody,
ApiBearerAuth,
ApiQuery,
ApiHeader,
} from '@nestjs/swagger';
import { ScheduleService } from '../providers/schedule.service';
import { CreateScheduleDto } from '../dto/create-schedule.dto';
@@ -25,6 +26,7 @@ export class ScheduleController {
@Get('public/schedules/restaurant/:slug')
@ApiOperation({ summary: 'Get schedule of a restaurant by slug' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiParam({ name: 'slug', description: 'Restaurant Slug' })
@ApiOkResponse({ description: 'Today schedule of the restaurant', type: Schedule })
async getTodaySchedules(@Param('slug') slug: string): Promise<Schedule[]> {
@@ -13,6 +13,7 @@ import {
ApiBody,
ApiParam,
ApiBearerAuth,
ApiHeader,
} from '@nestjs/swagger';
import { AuthGuard } from 'src/modules/auth/guards/auth.guard';
import { AdminAuthGuard } from 'src/modules/auth/guards/adminAuth.guard';
@@ -29,6 +30,7 @@ export class ReviewController {
@ApiBearerAuth()
@Post('public/reviews')
@ApiOperation({ summary: 'Create a new review and rating' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiCreatedResponse({ description: 'The review has been successfully created.' })
@ApiBody({ type: CreateReviewDto })
create(@Body() createReviewDto: CreateReviewDto, @UserId() userId: string) {
@@ -37,6 +39,7 @@ export class ReviewController {
@Get('public/reviews/:foodId')
@ApiOperation({ summary: 'Get all reviews of food by id(public - only approved)' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiOkResponse({ description: 'List of approved reviews' })
@ApiParam({ name: 'foodId', required: true, type: String })
@ApiQuery({ name: 'page', required: false, type: Number })
@@ -50,6 +53,7 @@ export class ReviewController {
@Get('public/reviews/restuarant/:restuarantSlug')
@ApiOperation({ summary: 'Get all reviews of restuarant by slug(public - only approved)' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiOkResponse({ description: 'List of approved reviews' })
@ApiParam({ name: 'restuarantSlug', required: true, type: String })
@ApiQuery({ name: 'page', required: false, type: Number })
@@ -74,6 +78,7 @@ export class ReviewController {
@ApiBearerAuth()
@Patch('public/reviews/:reviewId')
@ApiOperation({ summary: 'Update a review (own reviews only)' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiParam({ name: 'reviewId', required: true })
@ApiBody({ type: UpdateReviewDto })
@ApiOkResponse({ description: 'The updated review' })
@@ -85,6 +90,7 @@ export class ReviewController {
@ApiBearerAuth()
@Delete('public/reviews/:id')
@ApiOperation({ summary: 'Delete a review (own reviews only)' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiParam({ name: 'id', required: true })
remove(@Param('id') id: string, @UserId() userId: string) {
return this.reviewService.remove(id, userId, false);
@@ -1,5 +1,5 @@
import { Controller, Get, Post, Body, Param, Patch, Delete, UseGuards } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiBody, ApiBearerAuth } from '@nestjs/swagger';
import { ApiTags, ApiOperation, ApiBody, ApiBearerAuth, ApiHeader } from '@nestjs/swagger';
import { RolesService } from '../providers/roles.service';
import { PermissionsService } from '../providers/permissions.service';
import { CreateRoleDto } from '../dto/create-role.dto';
@@ -1,6 +1,6 @@
import { type File, FileInterceptor, FilesInterceptor } from '@nest-lab/fastify-multer';
import { Controller, Post, UploadedFile, UploadedFiles, UseGuards, UseInterceptors } from '@nestjs/common';
import { ApiBody, ApiConsumes, ApiOperation, ApiBearerAuth, ApiTags } from '@nestjs/swagger';
import { ApiBody, ApiConsumes, ApiOperation, ApiBearerAuth, ApiTags, ApiHeader } from '@nestjs/swagger';
import { UploadMultipleFileDto, UploadSingleFileDto } from '../DTO/upload-file.dto';
import { UploaderService } from '../providers/uploader.service';
@@ -1,5 +1,5 @@
import { Controller, Get, UseGuards, Patch, Body, ValidationPipe, Post, Query, Delete, Param } from '@nestjs/common';
import { ApiTags, ApiBearerAuth, ApiOperation, ApiBody, ApiOkResponse } from '@nestjs/swagger';
import { ApiTags, ApiBearerAuth, ApiOperation, ApiBody, ApiOkResponse, ApiHeader } from '@nestjs/swagger';
import { AuthGuard } from 'src/modules/auth/guards/auth.guard';
import { UserService } from '../providers/user.service';
import { UpdateUserDto } from '../dto/update-user.dto';
@@ -19,6 +19,7 @@ export class UsersController {
@UseGuards(AuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Get the current authenticated user profile' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@Get('public/user/me')
async getUser(@UserId() userId: string) {
const user = await this.userService.findById(userId);
@@ -27,6 +28,7 @@ export class UsersController {
@UseGuards(AuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Update the authenticated user profile' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiBody({ type: UpdateUserDto })
@Patch('public/user/update')
async updateUser(
@@ -40,6 +42,7 @@ export class UsersController {
@UseGuards(AuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Get all addresses for the authenticated user' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiOkResponse({ description: 'List of user addresses' })
@Get('public/user/addresses')
async getUserAddresses(@UserId() userId: string) {
@@ -50,6 +53,7 @@ export class UsersController {
@UseGuards(AuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Create a new address for the authenticated user' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiBody({ type: CreateUserAddressDto })
@ApiOkResponse({ description: 'Created user address' })
@Post('public/user/addresses')
@@ -64,6 +68,7 @@ export class UsersController {
@UseGuards(AuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Get a single address by ID for the authenticated user' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiOkResponse({ description: 'User address details' })
@Get('public/user/addresses/:addressId')
async getUserAddress(@UserId() userId: string, @Param('addressId') addressId: string) {
@@ -74,6 +79,7 @@ export class UsersController {
@UseGuards(AuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Update an address for the authenticated user' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiBody({ type: UpdateUserAddressDto })
@ApiOkResponse({ description: 'Updated user address' })
@Patch('public/user/addresses/:addressId')
@@ -89,6 +95,7 @@ export class UsersController {
@UseGuards(AuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Delete an address for the authenticated user' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiOkResponse({ description: 'Address deleted successfully' })
@Delete('public/user/addresses/:addressId')
async deleteUserAddress(@UserId() userId: string, @Param('addressId') addressId: string) {
@@ -99,6 +106,7 @@ export class UsersController {
@UseGuards(AuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Set an address as default for the authenticated user' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiOkResponse({ description: 'Address set as default' })
@Patch('public/user/addresses/:addressId/default')
async setDefaultAddress(@UserId() userId: string, @Param('addressId') addressId: string) {
@@ -122,6 +130,7 @@ export class UsersController {
@UseGuards(AuthGuard)
@ApiBearerAuth()
@ApiOperation({ summary: 'Convert user score (points) to wallet balance' })
@ApiHeader({ name: 'X-Slug', required: true, description: 'Restaurant slug identifier', example: 'zhivan' })
@ApiBody({ type: ConvertScoreToWalletDto })
@Post('public/user/convert-score-to-wallet')
async convertScoreToWallet(@UserId() userId: string, @Body() dto: ConvertScoreToWalletDto, @RestId() restId: string) {
@@ -320,7 +320,6 @@ export class UserService {
const walletIncreaseAmount =
(Number(pointsToConvert) * Number(restaurant.score.purchaseAmount)) / Number(restaurant.score.purchaseScore);
// Convert points to wallet (1:1 ratio - can be made configurable)
// Update user's wallet and points
user.wallet = (user.wallet || 0) + walletIncreaseAmount;