description

This commit is contained in:
2025-12-07 11:33:37 +03:30
parent 6b7ead553a
commit 14967bec6e
8 changed files with 49 additions and 2 deletions
@@ -6,6 +6,7 @@ import { ApplyCouponDto } from '../dto/apply-coupon.dto';
import { SetAddressDto } from '../dto/set-address.dto';
import { SetPaymentMethodDto } from '../dto/set-payment-method.dto';
import { SetDeliveryMethodDto } from '../dto/set-delivery-method.dto';
import { SetDescriptionDto } from '../dto/set-description.dto';
import { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth, ApiBody, ApiParam } from '@nestjs/swagger';
import { AuthGuard } from '../../auth/guards/auth.guard';
import { UserId } from 'src/common/decorators/user-id.decorator';
@@ -120,4 +121,15 @@ export class CartController {
) {
return this.cartService.setDeliveryMethod(userId, restaurantId, setDeliveryMethodDto);
}
@Patch('description')
@ApiOperation({ summary: 'Set description for cart' })
@ApiBody({ type: SetDescriptionDto })
setDescription(
@UserId() userId: string,
@RestId() restaurantId: string,
@Body() setDescriptionDto: SetDescriptionDto,
) {
return this.cartService.setDescription(userId, restaurantId, setDescriptionDto);
}
}
@@ -0,0 +1,10 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsOptional, IsString } from 'class-validator';
export class SetDescriptionDto {
@ApiProperty({ description: 'Cart description or notes', required: false, example: 'Please deliver to the back door' })
@IsOptional()
@IsString()
description?: string;
}
@@ -19,6 +19,7 @@ export interface Cart {
addressId?: string;
paymentMethodId?: string;
deliveryMethodId?: string;
description?: string;
deliveryFee: number;
subTotal: number;
@@ -10,6 +10,7 @@ import { ApplyCouponDto } from '../dto/apply-coupon.dto';
import { SetAddressDto } from '../dto/set-address.dto';
import { SetPaymentMethodDto } from '../dto/set-payment-method.dto';
import { SetDeliveryMethodDto } from '../dto/set-delivery-method.dto';
import { SetDescriptionDto } from '../dto/set-description.dto';
import { UserAddress } from '../../users/entities/user-address.entity';
import { User } from '../../users/entities/user.entity';
import { PaymentMethod } from '../../payments/entities/payment-method.entity';
@@ -590,6 +591,24 @@ export class CartService {
return cart;
}
/**
* Set description for cart
*/
async setDescription(
userId: string,
restaurantId: string,
setDescriptionDto: SetDescriptionDto,
): Promise<Cart> {
const cart = await this.findOneOrFail(userId, restaurantId);
cart.description = setDescriptionDto.description;
cart.updatedAt = new Date().toISOString();
await this.saveCart(cart);
return cart;
}
/**
* Recalculate cart totals (including coupon discount and tax)
*/
@@ -74,6 +74,9 @@ export class Order extends BaseEntity {
@Property({ type: 'int', default: 0 })
totalItems: number = 0;
@Property({ type: 'text', nullable: true })
description?: string;
@Enum(() => OrderStatus)
status!: OrderStatus;
+1
View File
@@ -67,6 +67,7 @@ export class OrdersService {
deliveryFee: cart.deliveryFee || 0,
total: cart.total || 0,
totalItems: cart.totalItems || 0,
description: cart.description,
status: OrderStatus.Pending,
paymentStatus: PaymentStatusEnum.Pending,
});
+1 -1
View File
@@ -26,7 +26,7 @@ export class UserService {
// firstName is required on the entity; use phone as a sensible default
const _raw = {
phone: normalizedPhone,
firstName: normalizedPhone,
firstName: new Date().toISOString(),
// keep dates undefined (no value) — cast through unknown to satisfy TS typing
birthDate: undefined,
marriageDate: undefined,
+2 -1
View File
@@ -34,7 +34,8 @@ export class UsersSeeder {
// Create addresses for users
for (const addressData of userAddressesData) {
const user = usersMap.get(addressData.userPhone);
const normalizedPhone = normalizePhone(addressData.userPhone);
const user = usersMap.get(normalizedPhone);
if (!user) continue;
// Check if address already exists for this user