cart and coupon

This commit is contained in:
2025-12-06 20:26:37 +03:30
parent a7d28ab882
commit e342c00e25
9 changed files with 114 additions and 122 deletions
+3 -13
View File
@@ -12,7 +12,7 @@ import {
} from '@mikro-orm/core';
import { BaseEntity } from '../../../common/entities/base.entity';
import { PaymentStatusEnum } from '../../payments/interface/payment';
import { OrderStatus } from '../interface/order-status';
import { OrderCouponDetail, OrderStatus } from '../interface/order-status';
import { User } from '../../users/entities/user.entity';
import { Restaurant } from '../../restaurants/entities/restaurant.entity';
import { UserAddress } from '../../users/entities/user-address.entity';
@@ -51,17 +51,7 @@ export class Order extends BaseEntity {
couponDiscount: number = 0;
@Property({ type: 'jsonb', nullable: true })
couponDetail: {
couponId: string;
couponName: string;
couponCode: string;
type: 'PERCENTAGE' | 'FIXED' | 'DELIVERY' | 'ITEM';
value: number;
maxDiscount?: number;
calculatedDiscount: number;
ruleVersion?: string;
} | null = null;
couponDetail?: OrderCouponDetail | null;
@Property({ type: 'decimal', precision: 10, scale: 0, default: 0 })
itemsDiscount: number = 0;
@@ -76,7 +66,7 @@ export class Order extends BaseEntity {
tax: number = 0;
@Property({ type: 'decimal', precision: 10, scale: 0, default: 0 })
shipmentFee: number = 0;
deliveryFee: number = 0;
@Property({ type: 'decimal', precision: 10, scale: 0 })
total!: number;
+13 -1
View File
@@ -1,3 +1,5 @@
import type { CouponType } from 'src/modules/coupons/entities/coupon.entity';
export enum OrderStatus {
Pending = 'pending',
@@ -5,7 +7,7 @@ export enum OrderStatus {
Confirmed = 'confirmed',
Preparing = 'preparing',
RejectedByRestaurant = 'rejectedByRestaurant',
CancelledByUser = 'cancelledByUser',
CancelledBySystem = 'cancelledBySystem',
@@ -17,3 +19,13 @@ export enum OrderStatus {
Delivered = 'delivered',
}
export interface OrderCouponDetail {
couponId: string;
couponName: string;
couponCode: string;
type: CouponType;
value: number;
maxDiscount?: number;
}
+2 -2
View File
@@ -33,7 +33,7 @@ export class OrdersService {
) {}
async checkout(userId: string, restaurantId: string) {
const cart = await this.cartService.findOne(userId, restaurantId);
const cart = await this.cartService.findOneOrFail(userId, restaurantId);
const { order } = await this.createOrder(userId, restaurantId, cart);
@@ -64,7 +64,7 @@ export class OrdersService {
totalDiscount: cart.totalDiscount || 0,
subTotal: cart.subTotal || 0,
tax: cart.tax || 0,
shipmentFee: cart.shipmentFee || 0,
deliveryFee: cart.deliveryFee || 0,
total: cart.total || 0,
totalItems: cart.totalItems || 0,
status: OrderStatus.Pending,