change types

This commit is contained in:
nflnkr 2023-03-06 16:23:13 +03:00
parent da5341b71c
commit ce56656c9e
2 changed files with 172 additions and 228 deletions

@ -1,177 +1,139 @@
import { ServiceType, Tariffs } from "./tariff";
import { ServiceType, Privilege, Tariff } from "./tariff";
/** @deprecated */
export interface CartSummary {
mbs: number;
points: number;
days: number;
}
/** @deprecated */
export interface Promocode {
id: number;
interface DiscountBase {
_id: string;
name: string;
endless: boolean;
from: string;
dueTo: string;
privileges: Array<Privileges>;
description: string;
/** Этап применения скидки */
layer: number;
}
/** @deprecated */
export interface Privileges {
good: ServiceType,
discount: number;
}
/** @deprecated */
export interface Discount {
id: number;
name: string;
endless: boolean;
from: string;
dueTo: string;
privileges: Array<Privileges>;
active: boolean;
basketMore: number;
incomeMore: number;
toTime: number;
toCapacity: number;
}
export namespace Cart {
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: Tariffs.ServiceType;
/** Скидка применяется, если значение больше или равно этому значению */
value: number;
};
};
target: {
service: Tariffs.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 interface Promocode {
id: number;
name: string;
endless: boolean;
from: string;
dueTo: string;
privileges: Tariffs.Privilege[];
}
export interface CartItem {
tariff: Tariffs.Tariff;
/** Посчитанная цена пункта корзины */
price: number;
}
/** Пункт корзины с уже примененными скидками */
export interface CartItemTotal {
/** Массив с id примененных скидок */
envolvedDiscounts: string[];
totalPrice: number;
tariff: Tariffs.Tariff;
}
export type ServiceToPriceMap = {
[Key in Tariffs.ServiceType]: {
customTariffs: number;
defaultTariffs: number;
}
export interface PurchasesAmountDiscount extends DiscountBase {
conditionType: "purchasesAmount";
condition: {
purchasesAmount: number;
};
/** Множитель, на который умножается сумма при применении скидки */
factor: number;
}
export interface CartTotal {
items: CartItemTotal[];
totalPrice: number;
priceByService: ServiceToPriceMap;
envolvedCartDiscounts: string[];
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: string[];
totalPrice: number;
tariff: Tariff;
}
export type ServiceToPriceMap = {
[Key in ServiceType]: {
customTariffs: number;
defaultTariffs: number;
}
};
export interface CartTotal {
items: CartItemTotal[];
totalPrice: number;
priceByService: ServiceToPriceMap;
envolvedCartDiscounts: string[];
}

@ -1,64 +1,46 @@
/** @deprecated */
export type ServiceType =
| "Шаблонизатор документов"
| "Опросник"
| "Сокращатель ссылок"
| "АБ тесты";
/** @deprecated */
export const SERVICE_LIST = [
{
serviceKey: "templategen",
displayName: "Шаблонизатор документов"
},
{
serviceKey: "squiz",
displayName: "Опросник"
},
{
serviceKey: "dwarfener",
displayName: "Сокращатель ссылок"
}
] as const;
export type ServiceType = typeof SERVICE_LIST[number]["serviceKey"];
export type PrivilegeType =
| "unlim"
| "gencount"
| "activequiz"
| "abcount"
| "extended";
export interface Privilege {
serviceKey: ServiceType;
name: PrivilegeType;
privilegeId: string;
description: string;
/** Единица измерения привелегии: время в днях/кол-во */
type: "day" | "count";
/** Стоимость одной единицы привелегии */
pricePerUnit: number;
}
export interface Tariff {
id: number;
id: string;
name: string;
type: string;
service: ServiceType | "";
disk: number;
time: number;
points: number;
price: number;
}
/** @deprecated */
export interface ArrayProps {
id: number;
name: string;
type: "package" | "tariff";
service: ServiceType | "";
disk: number;
time: number;
points: number;
price: number;
tariffs?: Array<Tariff>;
}
export const SERVICE_LIST = ["templategen", "squiz", "dwarfener"] as const;
export namespace Tariffs {
export type ServiceType = typeof SERVICE_LIST[number];
export type PrivilegeType =
| "unlim"
| "gencount"
| "activequiz"
| "abcount"
| "extended";
export interface Privilege {
serviceKey: ServiceType;
name: PrivilegeType;
privilegeId: string;
description: string;
/** Единица измерения привелегии: время в днях/кол-во */
type: "day" | "count";
/** Стоимость одной единицы привелегии */
pricePerUnit: number;
}
export interface Tariff {
privilege: Privilege;
/** Количество единиц привелегии */
amount: number;
/** Кастомная цена, если есть, то используется вместо privilege.price */
customPricePerUnit?: number;
}
privilege: Privilege;
/** Количество единиц привелегии */
amount: number;
/** Кастомная цена, если есть, то используется вместо privilege.price */
customPricePerUnit?: number;
}