diff --git a/src/modules/cart/controllers/cart.controller.ts b/src/modules/cart/controllers/cart.controller.ts index 1546775..7fa07eb 100644 --- a/src/modules/cart/controllers/cart.controller.ts +++ b/src/modules/cart/controllers/cart.controller.ts @@ -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); + } } diff --git a/src/modules/cart/dto/set-description.dto.ts b/src/modules/cart/dto/set-description.dto.ts new file mode 100644 index 0000000..c206ad2 --- /dev/null +++ b/src/modules/cart/dto/set-description.dto.ts @@ -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; +} + diff --git a/src/modules/cart/interfaces/cart.interface.ts b/src/modules/cart/interfaces/cart.interface.ts index 6b7e867..5587039 100644 --- a/src/modules/cart/interfaces/cart.interface.ts +++ b/src/modules/cart/interfaces/cart.interface.ts @@ -19,6 +19,7 @@ export interface Cart { addressId?: string; paymentMethodId?: string; deliveryMethodId?: string; + description?: string; deliveryFee: number; subTotal: number; diff --git a/src/modules/cart/providers/cart.service.ts b/src/modules/cart/providers/cart.service.ts index a557f0e..464f5e2 100644 --- a/src/modules/cart/providers/cart.service.ts +++ b/src/modules/cart/providers/cart.service.ts @@ -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 { + 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) */ diff --git a/src/modules/orders/entities/order.entity.ts b/src/modules/orders/entities/order.entity.ts index 2cee2e1..6813474 100644 --- a/src/modules/orders/entities/order.entity.ts +++ b/src/modules/orders/entities/order.entity.ts @@ -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; diff --git a/src/modules/orders/orders.service.ts b/src/modules/orders/orders.service.ts index 0698839..628e103 100644 --- a/src/modules/orders/orders.service.ts +++ b/src/modules/orders/orders.service.ts @@ -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, }); diff --git a/src/modules/users/user.service.ts b/src/modules/users/user.service.ts index 1c37753..06c6d95 100644 --- a/src/modules/users/user.service.ts +++ b/src/modules/users/user.service.ts @@ -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, diff --git a/src/seeders/users.seeder.ts b/src/seeders/users.seeder.ts index 32b07b9..bde545e 100644 --- a/src/seeders/users.seeder.ts +++ b/src/seeders/users.seeder.ts @@ -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