adminFront/src/model/cart.ts

139 lines
3.8 KiB
TypeScript
Raw Normal View History

2023-03-06 13:23:13 +00:00
import { ServiceType, Privilege, Tariff } from "./tariff";
2023-02-18 14:00:49 +00:00
2023-03-06 13:23:13 +00:00
interface DiscountBase {
_id: string;
2023-02-18 14:00:49 +00:00
name: string;
2023-03-06 13:23:13 +00:00
description: string;
/** Этап применения скидки */
layer: number;
2023-02-18 14:00:49 +00:00
}
2023-03-06 13:23:13 +00:00
export interface PurchasesAmountDiscount extends DiscountBase {
conditionType: "purchasesAmount";
condition: {
purchasesAmount: number;
};
/** Множитель, на который умножается сумма при применении скидки */
factor: number;
2023-02-18 14:00:49 +00:00
}
2023-03-06 13:23:13 +00:00
export interface CartPurchasesAmountDiscount extends DiscountBase {
conditionType: "cartPurchasesAmount";
condition: {
cartPurchasesAmount: number;
};
/** Множитель, на который умножается сумма при применении скидки */
factor: number;
2023-02-22 15:07:53 +00:00
}
2023-03-06 13:23:13 +00:00
export interface PrivilegeDiscount extends DiscountBase {
conditionType: "privilege";
condition: {
privilege: {
id: string;
/** Скидка применяется, если значение больше или равно этому значению */
value: number;
};
};
target: {
products: Array<{
privilegeId: string;
/** Множитель, на который умножается сумма при применении скидки */
factor: number;
}>;
};
}
2023-02-28 13:13:55 +00:00
2023-03-06 13:23:13 +00:00
export interface ServiceDiscount extends DiscountBase {
conditionType: "service";
condition: {
service: {
id: ServiceType;
/** Скидка применяется, если значение больше или равно этому значению */
value: number;
2023-02-22 15:07:53 +00:00
};
2023-03-06 13:23:13 +00:00
};
target: {
service: ServiceType;
2023-02-27 13:30:44 +00:00
/** Множитель, на который умножается сумма при применении скидки */
2023-02-22 15:07:53 +00:00
factor: number;
2023-03-06 13:23:13 +00:00
};
}
2023-02-25 09:22:54 +00:00
2023-03-06 13:23:13 +00:00
export interface UserTypeDiscount extends DiscountBase {
conditionType: "userType";
condition: {
userType: string;
};
target: {
IsAllProducts: boolean;
2023-02-27 13:30:44 +00:00
/** Множитель, на который умножается сумма при применении скидки */
2023-02-22 15:07:53 +00:00
factor: number;
2023-03-06 13:23:13 +00:00
};
overwhelm: boolean;
}
2023-02-25 09:22:54 +00:00
2023-03-06 13:23:13 +00:00
export interface UserDiscount extends DiscountBase {
conditionType: "user";
condition: {
coupon: string;
user: string;
};
target: {
products: Array<{
privilegeId: string;
2023-02-27 13:30:44 +00:00
/** Множитель, на который умножается сумма при применении скидки */
2023-02-22 15:07:53 +00:00
factor: number;
2023-03-06 13:23:13 +00:00
}>;
};
overwhelm: boolean;
}
2023-02-25 09:22:54 +00:00
2023-03-06 13:23:13 +00:00
export type AnyDiscount =
| PurchasesAmountDiscount
| CartPurchasesAmountDiscount
| PrivilegeDiscount
| ServiceDiscount
| UserTypeDiscount
| UserDiscount;
2023-02-25 09:22:54 +00:00
2023-03-06 13:23:13 +00:00
export type DiscountConditionType = AnyDiscount["conditionType"];
2023-02-25 09:22:54 +00:00
2023-03-06 13:23:13 +00:00
export interface Promocode {
id: string;
name: string;
endless: boolean;
from: string;
dueTo: string;
privileges: Privilege[];
}
2023-02-25 09:22:54 +00:00
2023-03-06 13:23:13 +00:00
export interface CartItem {
id: string;
tariff: Tariff;
/** Посчитанная цена пункта корзины */
price: number;
}
2023-02-25 09:22:54 +00:00
2023-03-06 13:23:13 +00:00
/** Пункт корзины с уже примененными скидками */
export interface CartItemTotal {
/** Массив с id примененных скидок */
envolvedDiscounts: string[];
totalPrice: number;
tariff: Tariff;
}
2023-02-22 15:07:53 +00:00
2023-03-06 13:23:13 +00:00
export type ServiceToPriceMap = {
[Key in ServiceType]: {
customTariffs: number;
defaultTariffs: number;
2023-02-25 09:22:54 +00:00
}
2023-03-06 13:23:13 +00:00
};
2023-02-25 09:22:54 +00:00
2023-03-06 13:23:13 +00:00
export interface CartTotal {
items: CartItemTotal[];
totalPrice: number;
priceByService: ServiceToPriceMap;
envolvedCartDiscounts: string[];
2023-02-18 14:00:49 +00:00
}