description
This commit is contained in:
@@ -6,6 +6,7 @@ import { ApplyCouponDto } from '../dto/apply-coupon.dto';
|
|||||||
import { SetAddressDto } from '../dto/set-address.dto';
|
import { SetAddressDto } from '../dto/set-address.dto';
|
||||||
import { SetPaymentMethodDto } from '../dto/set-payment-method.dto';
|
import { SetPaymentMethodDto } from '../dto/set-payment-method.dto';
|
||||||
import { SetDeliveryMethodDto } from '../dto/set-delivery-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 { ApiTags, ApiOperation, ApiResponse, ApiBearerAuth, ApiBody, ApiParam } from '@nestjs/swagger';
|
||||||
import { AuthGuard } from '../../auth/guards/auth.guard';
|
import { AuthGuard } from '../../auth/guards/auth.guard';
|
||||||
import { UserId } from 'src/common/decorators/user-id.decorator';
|
import { UserId } from 'src/common/decorators/user-id.decorator';
|
||||||
@@ -120,4 +121,15 @@ export class CartController {
|
|||||||
) {
|
) {
|
||||||
return this.cartService.setDeliveryMethod(userId, restaurantId, setDeliveryMethodDto);
|
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;
|
addressId?: string;
|
||||||
paymentMethodId?: string;
|
paymentMethodId?: string;
|
||||||
deliveryMethodId?: string;
|
deliveryMethodId?: string;
|
||||||
|
description?: string;
|
||||||
|
|
||||||
deliveryFee: number;
|
deliveryFee: number;
|
||||||
subTotal: number;
|
subTotal: number;
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { ApplyCouponDto } from '../dto/apply-coupon.dto';
|
|||||||
import { SetAddressDto } from '../dto/set-address.dto';
|
import { SetAddressDto } from '../dto/set-address.dto';
|
||||||
import { SetPaymentMethodDto } from '../dto/set-payment-method.dto';
|
import { SetPaymentMethodDto } from '../dto/set-payment-method.dto';
|
||||||
import { SetDeliveryMethodDto } from '../dto/set-delivery-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 { UserAddress } from '../../users/entities/user-address.entity';
|
||||||
import { User } from '../../users/entities/user.entity';
|
import { User } from '../../users/entities/user.entity';
|
||||||
import { PaymentMethod } from '../../payments/entities/payment-method.entity';
|
import { PaymentMethod } from '../../payments/entities/payment-method.entity';
|
||||||
@@ -590,6 +591,24 @@ export class CartService {
|
|||||||
return cart;
|
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)
|
* Recalculate cart totals (including coupon discount and tax)
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -74,6 +74,9 @@ export class Order extends BaseEntity {
|
|||||||
@Property({ type: 'int', default: 0 })
|
@Property({ type: 'int', default: 0 })
|
||||||
totalItems: number = 0;
|
totalItems: number = 0;
|
||||||
|
|
||||||
|
@Property({ type: 'text', nullable: true })
|
||||||
|
description?: string;
|
||||||
|
|
||||||
@Enum(() => OrderStatus)
|
@Enum(() => OrderStatus)
|
||||||
status!: OrderStatus;
|
status!: OrderStatus;
|
||||||
|
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ export class OrdersService {
|
|||||||
deliveryFee: cart.deliveryFee || 0,
|
deliveryFee: cart.deliveryFee || 0,
|
||||||
total: cart.total || 0,
|
total: cart.total || 0,
|
||||||
totalItems: cart.totalItems || 0,
|
totalItems: cart.totalItems || 0,
|
||||||
|
description: cart.description,
|
||||||
status: OrderStatus.Pending,
|
status: OrderStatus.Pending,
|
||||||
paymentStatus: PaymentStatusEnum.Pending,
|
paymentStatus: PaymentStatusEnum.Pending,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export class UserService {
|
|||||||
// firstName is required on the entity; use phone as a sensible default
|
// firstName is required on the entity; use phone as a sensible default
|
||||||
const _raw = {
|
const _raw = {
|
||||||
phone: normalizedPhone,
|
phone: normalizedPhone,
|
||||||
firstName: normalizedPhone,
|
firstName: new Date().toISOString(),
|
||||||
// keep dates undefined (no value) — cast through unknown to satisfy TS typing
|
// keep dates undefined (no value) — cast through unknown to satisfy TS typing
|
||||||
birthDate: undefined,
|
birthDate: undefined,
|
||||||
marriageDate: undefined,
|
marriageDate: undefined,
|
||||||
|
|||||||
@@ -34,7 +34,8 @@ export class UsersSeeder {
|
|||||||
|
|
||||||
// Create addresses for users
|
// Create addresses for users
|
||||||
for (const addressData of userAddressesData) {
|
for (const addressData of userAddressesData) {
|
||||||
const user = usersMap.get(addressData.userPhone);
|
const normalizedPhone = normalizePhone(addressData.userPhone);
|
||||||
|
const user = usersMap.get(normalizedPhone);
|
||||||
if (!user) continue;
|
if (!user) continue;
|
||||||
|
|
||||||
// Check if address already exists for this user
|
// Check if address already exists for this user
|
||||||
|
|||||||
Reference in New Issue
Block a user