adminFront/src/model/cart.ts
2023-03-14 15:47:05 +03:00

144 lines
4.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { ServiceType, Privilege, Tariff } from "./tariff";
interface DiscountBase {
_id: string;
name: string;
description: string;
/** Этап применения скидки */
layer: number;
}
export interface PurchasesAmountDiscount extends DiscountBase {
conditionType: "purchasesAmount";
condition: {
purchasesAmount: number;
};
/** Множитель, на который умножается сумма при применении скидки */
factor: number;
}
export interface CartPurchasesAmountDiscount extends DiscountBase {
conditionType: "cartPurchasesAmount";
condition: {
cartPurchasesAmount: number;
};
/** Множитель, на который умножается сумма при применении скидки */
factor: number;
}
export interface PrivilegeDiscount extends DiscountBase {
conditionType: "privilege";
condition: {
privilege: {
id: string;
/** Скидка применяется, если значение больше или равно этому значению */
value: number;
};
};
target: {
products: Array<{
privilegeId: string;
/** Множитель, на который умножается сумма при применении скидки */
factor: number;
}>;
};
}
export interface ServiceDiscount extends DiscountBase {
conditionType: "service";
condition: {
service: {
id: ServiceType;
/** Скидка применяется, если значение больше или равно этому значению */
value: number;
};
};
target: {
service: ServiceType;
/** Множитель, на который умножается сумма при применении скидки */
factor: number;
};
}
export interface UserTypeDiscount extends DiscountBase {
conditionType: "userType";
condition: {
userType: string;
};
target: {
IsAllProducts: boolean;
/** Множитель, на который умножается сумма при применении скидки */
factor: number;
};
overwhelm: boolean;
}
export interface UserDiscount extends DiscountBase {
conditionType: "user";
condition: {
coupon: string;
user: string;
};
target: {
products: Array<{
privilegeId: string;
/** Множитель, на который умножается сумма при применении скидки */
factor: number;
}>;
};
overwhelm: boolean;
}
export type AnyDiscount =
| PurchasesAmountDiscount
| CartPurchasesAmountDiscount
| PrivilegeDiscount
| ServiceDiscount
| UserTypeDiscount
| UserDiscount;
export type DiscountConditionType = AnyDiscount["conditionType"];
export interface Promocode {
id: string;
name: string;
endless: boolean;
from: string;
dueTo: string;
privileges: Privilege[];
}
export interface CartItem {
id: string;
tariff: Tariff;
/** Посчитанная цена пункта корзины */
price: number;
}
/** Пункт корзины с уже примененными скидками */
export interface CartItemTotal {
/** Массив с id примененных скидок */
envolvedDiscounts: (PrivilegeDiscount | UserDiscount)[];
totalPrice: number;
tariff: Tariff;
}
export type ServiceToPriceMap = {
[Key in ServiceType]: number;
};
export type ServiceToDiscountMap = {
[Key in ServiceType]: ServiceDiscount | null;
};
export interface CartTotal {
items: CartItemTotal[];
totalPrice: number;
priceByService: ServiceToPriceMap;
/** Скидки по сервисам */
discountsByService: ServiceToDiscountMap;
/** Учтенные скидки типов userType, cartPurchasesAmount, totalPurchasesAmount */
envolvedCartDiscounts: (UserTypeDiscount | CartPurchasesAmountDiscount | PurchasesAmountDiscount)[];
couponState: "applied" | "not found" | null;
}