add cart calculation functions and tests
add custom tariff types
This commit is contained in:
nflnkr 2024-03-27 13:21:49 +03:00
parent a3a934e404
commit 341bee7ea9
17 changed files with 5374 additions and 2672 deletions

@ -0,0 +1,19 @@
import { CustomPrivilegeWithAmount } from "./privilege";
type ServiceKey = string;
export type PrivilegeWithoutPrice = Omit<CustomPrivilegeWithAmount, "price">;
export type CustomTariffUserValues = Record<string, number>;
export type CustomTariffUserValuesMap = Record<ServiceKey, CustomTariffUserValues>;
export type ServiceKeyToPriceMap = Record<ServiceKey, number>;
export interface CreateTariffBody {
name: string;
price?: number;
isCustom: boolean;
privileges: PrivilegeWithoutPrice[];
}

@ -0,0 +1,21 @@
import { expect, test, describe } from "vitest";
import { calcCart } from "./calcCart";
import { testDiscounts } from "./mockData/discounts";
import { cartTestResults } from "./mockData/results";
import { testTariffs } from "./mockData/tariffs";
describe("Cart calculation", () => {
for (let i = 0; i < cartTestResults.length; i++) {
test(`Cart calculation №${i}`, () => {
const usedTariffsMask = cartTestResults[i][1];
const isNkoApplied = Boolean(usedTariffsMask.pop());
const tariffs = testTariffs.filter((_, index) => (usedTariffsMask[index] === 1));
const cart = calcCart(tariffs, testDiscounts, 0, "someuserid", isNkoApplied);
expect(cart.priceAfterDiscounts).toBeCloseTo(cartTestResults[i][0]);
});
}
});

188
lib/utils/cart/calcCart.ts Normal file

@ -0,0 +1,188 @@
import { CartData, PrivilegeCartData, TariffCartData } from "../../model/cart";
import { Discount } from "../../model/discount";
import { Tariff } from "../../model/tariff";
import { findCartDiscount, findDiscountFactor, findLoyaltyDiscount, findNkoDiscount, findPrivilegeDiscount, findServiceDiscount } from "./utils";
export function calcCart(tariffs: Tariff[], discounts: Discount[], purchasesAmount: number, userId: string, isUserNko?: boolean): CartData {
const cartData: CartData = {
services: [],
priceBeforeDiscounts: 0,
priceAfterDiscounts: 0,
allAppliedDiscounts: [],
};
const privilegeAmountById = new Map<string, number>();
const servicePriceByKey = new Map<string, number>();
const allAppliedDiscounts = new Set<Discount>();
tariffs.forEach(tariff => {
if (tariff.privileges === undefined) return;
if (
(tariff.price || 0) > 0
&& tariff.privileges.length !== 1
) throw new Error("Price is defined for tariff with several privileges");
let serviceData = cartData.services.find(service => (service.serviceKey === "custom" && tariff.isCustom));
if (!serviceData && !tariff.isCustom) serviceData = cartData.services.find(service => service.serviceKey === tariff.privileges[0]?.serviceKey);
if (!serviceData) {
serviceData = {
serviceKey: tariff.isCustom ? "custom" : tariff.privileges[0]?.serviceKey,
tariffs: [],
price: 0,
};
cartData.services.push(serviceData);
}
const tariffCartData: TariffCartData = {
price: tariff.price ?? 0,
isCustom: tariff.isCustom,
privileges: [],
id: tariff._id,
name: tariff.name,
};
serviceData.tariffs.push(tariffCartData);
tariff.privileges.forEach(privilege => {
let privilegePrice = privilege.amount * privilege.price;
if (!tariff.price) tariffCartData.price += privilegePrice;
else privilegePrice = tariff.price;
const privilegeCartData: PrivilegeCartData = {
serviceKey: privilege.serviceKey,
privilegeId: privilege.privilegeId,
description: privilege.description,
price: privilegePrice,
amount: privilege.amount,
};
privilegeAmountById.set(
privilege.privilegeId,
privilege.amount + (privilegeAmountById.get(privilege.privilegeId) ?? 0)
);
servicePriceByKey.set(
privilege.serviceKey,
privilegePrice + (servicePriceByKey.get(privilege.serviceKey) ?? 0)
);
tariffCartData.privileges.push(privilegeCartData);
});
serviceData.price += tariffCartData.price;
});
cartData.priceBeforeDiscounts = Array.from(servicePriceByKey.values()).reduce((a, b) => a + b, 0);
cartData.priceAfterDiscounts = cartData.priceBeforeDiscounts;
const nkoDiscount = findNkoDiscount(discounts);
if (isUserNko && nkoDiscount) {
cartData.allAppliedDiscounts = [nkoDiscount];
cartData.services.forEach(service => {
service.tariffs.forEach(tariff => {
tariff.privileges.forEach(privilege => {
const discountAmount = privilege.price * (1 - findDiscountFactor(nkoDiscount));
privilege.price -= discountAmount;
tariff.price -= discountAmount;
service.price -= discountAmount;
cartData.priceAfterDiscounts -= discountAmount;
});
});
});
return cartData;
}
cartData.services.forEach(service => {
service.tariffs.forEach(tariff => {
tariff.privileges.forEach(privilege => {
const privilegeTotalAmount = privilegeAmountById.get(privilege.privilegeId) ?? 0;
const discount = findPrivilegeDiscount(privilege.privilegeId, privilegeTotalAmount, discounts, userId);
if (!discount) return;
allAppliedDiscounts.add(discount);
const discountAmount = privilege.price * (1 - findDiscountFactor(discount));
privilege.price -= discountAmount;
tariff.price -= discountAmount;
service.price -= discountAmount;
cartData.priceAfterDiscounts -= discountAmount;
const serviceTotalPrice = servicePriceByKey.get(privilege.serviceKey);
if (!serviceTotalPrice) throw new Error(`Service key ${privilege.serviceKey} not found in servicePriceByKey`);
servicePriceByKey.set(privilege.serviceKey, serviceTotalPrice - discountAmount);
});
});
});
cartData.services.forEach(service => {
service.tariffs.map(tariff => {
tariff.privileges.forEach(privilege => {
const serviceTotalPrice = servicePriceByKey.get(privilege.serviceKey);
if (!serviceTotalPrice) throw new Error(`Service key ${privilege.serviceKey} not found in servicePriceByKey`);
const discount = findServiceDiscount(privilege.serviceKey, serviceTotalPrice, discounts, userId);
if (!discount) return;
allAppliedDiscounts.add(discount);
const discountAmount = privilege.price * (1 - findDiscountFactor(discount));
privilege.price -= discountAmount;
tariff.price -= discountAmount;
service.price -= discountAmount;
cartData.priceAfterDiscounts -= discountAmount;
});
});
});
const userDiscount = discounts.find(discount => discount.Condition.User === userId);
const cartDiscount = findCartDiscount(cartData.priceAfterDiscounts, discounts);
if (cartDiscount) {
cartData.services.forEach(service => {
if (service.serviceKey === userDiscount?.Condition.Group) return;
service.tariffs.forEach(tariff => {
tariff.privileges.forEach(privilege => {
allAppliedDiscounts.add(cartDiscount);
const discountAmount = privilege.price * (1 - findDiscountFactor(cartDiscount));
privilege.price -= discountAmount;
tariff.price -= discountAmount;
service.price -= discountAmount;
cartData.priceAfterDiscounts -= discountAmount;
});
});
});
}
const loyalDiscount = findLoyaltyDiscount(purchasesAmount, discounts);
if (loyalDiscount) {
cartData.services.forEach(service => {
if (service.serviceKey === userDiscount?.Condition.Group) return;
service.tariffs.forEach(tariff => {
tariff.privileges.forEach(privilege => {
allAppliedDiscounts.add(loyalDiscount);
const discountAmount = privilege.price * (1 - findDiscountFactor(loyalDiscount));
privilege.price -= discountAmount;
tariff.price -= discountAmount;
service.price -= discountAmount;
cartData.priceAfterDiscounts -= discountAmount;
});
});
});
}
cartData.allAppliedDiscounts = Array.from(allAppliedDiscounts);
return cartData;
}

@ -0,0 +1,52 @@
import { CustomTariffUserValues } from "../../model/customTariffs";
import { Discount } from "../../model/discount";
import { CustomPrivilegeWithAmount } from "../../model/privilege";
import { Tariff } from "../../model/tariff";
import { calcCart } from "./calcCart";
export function calcCustomTariffPrice(
customTariffUserValues: CustomTariffUserValues,
servicePrivileges: CustomPrivilegeWithAmount[],
cartTariffs: Tariff[],
discounts: Discount[],
purchasesAmount: number,
isUserNko: boolean,
userId: string,
) {
const privileges = new Array<CustomPrivilegeWithAmount>();
const priceBeforeDiscounts = servicePrivileges.reduce((price, privilege) => {
const amount = customTariffUserValues?.[privilege._id] ?? 0;
return price + privilege.price * amount;
}, 0);
Object.keys(customTariffUserValues).forEach(privilegeId => {
const pwa = servicePrivileges.find(p => p._id === privilegeId);
if (!pwa) return;
if (customTariffUserValues[privilegeId] > 0) privileges.push({
...pwa,
amount: customTariffUserValues[privilegeId]
});
});
const customTariff: Tariff = {
_id: crypto.randomUUID(),
name: "",
price: 0,
description: "",
isCustom: true,
isDeleted: false,
privileges: privileges,
};
const cart = calcCart([...cartTariffs, customTariff], discounts, purchasesAmount, userId, isUserNko);
const customService = cart.services.flatMap(service => service.tariffs).find(tariff => tariff.id === customTariff._id);
if (!customService) throw new Error("Custom service not found in cart");
return {
priceBeforeDiscounts,
priceAfterDiscounts: customService.price,
};
}

@ -1,22 +0,0 @@
import { Discount } from "../../model";
export function findCartDiscount(
cartPurchasesAmount: number,
discounts: Discount[],
): Discount | null {
const applicableDiscounts = discounts.filter(discount => {
return (
discount.Layer === 3 &&
cartPurchasesAmount >= Number(discount.Condition.CartPurchasesAmount)
);
});
if (!applicableDiscounts.length) return null;
const maxValueDiscount = applicableDiscounts.reduce((prev, current) => {
return Number(current.Condition.CartPurchasesAmount) > Number(prev.Condition.CartPurchasesAmount) ? current : prev;
});
return maxValueDiscount;
}

@ -1,10 +0,0 @@
import { Discount } from "../../model";
export function findDiscountFactor(discount: Discount | null | undefined): number {
if (!discount) return 1;
if (discount.Layer === 1) return discount.Target.Products[0].Factor;
return discount.Target.Factor;
}

@ -1,6 +1,2 @@
export * from "./cartDiscount";
export * from "./findDiscountFactor";
export * from "./loyaltyDiscount";
export * from "./nkoDiscount";
export * from "./privilegeDiscount";
export * from "./serviceDiscount";
export * from "./calcCart";
export * from "./utils";

@ -1,23 +0,0 @@
import { Discount } from "../../model";
export function findLoyaltyDiscount(
purchasesAmount: number,
discounts: Discount[],
): Discount | null {
const applicableDiscounts = discounts.filter(discount => {
return (
discount.Layer === 4 &&
discount.Condition.UserType !== "nko" &&
purchasesAmount >= Number(discount.Condition.PurchasesAmount)
);
});
if (!applicableDiscounts.length) return null;
const maxValueDiscount = applicableDiscounts.reduce((prev, current) => {
return Number(current.Condition.PurchasesAmount) > Number(prev.Condition.PurchasesAmount) ? current : prev;
});
return maxValueDiscount;
}

@ -0,0 +1,901 @@
import { Discount } from "../../../model/discount";
export const testDiscounts: Discount[] = [
{
"ID": "6521d98b166f36879928ebbf",
"Name": "NKO",
"Layer": 4,
"Description": "скидка ветеранам НКО",
"Condition": {
"Period": {
"From": "2023-10-07T21:00:45.829Z",
"To": "2023-11-06T21:00:45.829Z"
},
"User": "",
"UserType": "nko",
"Coupon": "",
"PurchasesAmount": "0",
"CartPurchasesAmount": "0",
"Product": "",
"Term": "0",
"Usage": "0",
"PriceFrom": "0",
"Group": ""
},
"Target": {
"Products": [],
"Factor": 0.4,
"TargetScope": "Sum",
"TargetGroup": "",
"Overhelm": true
},
"Audit": {
"UpdatedAt": "2023-11-10T23:20:32.619Z",
"CreatedAt": "2023-09-16T20:10:26.048Z",
"Deleted": false
},
"Deprecated": false
},
{
"ID": "657b9b73153787e41052c25b",
"Name": "1000 шаблонов",
"Layer": 1,
"Description": "Тариф на 1000 шаблонов",
"Condition": {
"Period": {
"From": "2023-12-15T00:18:57.999Z",
"To": "2024-01-14T00:18:58Z"
},
"User": "",
"UserType": "",
"Coupon": "",
"PurchasesAmount": "0",
"CartPurchasesAmount": "0",
"Product": "templateCnt",
"Term": "1000",
"Usage": "0",
"PriceFrom": "0",
"Group": ""
},
"Target": {
"Products": [
{
"ID": "templateCnt",
"Factor": 0.7,
"Overhelm": false
}
],
"Factor": 0.7,
"TargetScope": "Sum",
"TargetGroup": "",
"Overhelm": false
},
"Audit": {
"UpdatedAt": "2023-12-15T00:18:59.138Z",
"CreatedAt": "2023-12-15T00:18:59.138Z",
"Deleted": false
},
"Deprecated": false
},
{
"ID": "657b9cb0153787e41052c25c",
"Name": "десять тысяч шаблонов",
"Layer": 1,
"Description": "Тариф 10 000",
"Condition": {
"Period": {
"From": "2023-12-15T00:24:15.555Z",
"To": "2024-01-14T00:24:15.555Z"
},
"User": "",
"UserType": "",
"Coupon": "",
"PurchasesAmount": "0",
"CartPurchasesAmount": "0",
"Product": "templateCnt",
"Term": "10000",
"Usage": "0",
"PriceFrom": "0",
"Group": ""
},
"Target": {
"Products": [
{
"ID": "templateCnt",
"Factor": 0.5,
"Overhelm": false
}
],
"Factor": 0.5,
"TargetScope": "Sum",
"TargetGroup": "",
"Overhelm": false
},
"Audit": {
"UpdatedAt": "2023-12-15T00:24:16.562Z",
"CreatedAt": "2023-12-15T00:24:16.562Z",
"Deleted": false
},
"Deprecated": false
},
{
"ID": "657b9e67153787e41052c25d",
"Name": "3 месяца",
"Layer": 1,
"Description": "Тариф 3 месяца",
"Condition": {
"Period": {
"From": "2023-12-15T00:31:34.807Z",
"To": "2024-01-14T00:31:34.807Z"
},
"User": "",
"UserType": "",
"Coupon": "",
"PurchasesAmount": "0",
"CartPurchasesAmount": "0",
"Product": "templateUnlimTime",
"Term": "90",
"Usage": "0",
"PriceFrom": "0",
"Group": ""
},
"Target": {
"Products": [
{
"ID": "templateUnlimTime",
"Factor": 0.8,
"Overhelm": false
}
],
"Factor": 0.8,
"TargetScope": "Sum",
"TargetGroup": "",
"Overhelm": false
},
"Audit": {
"UpdatedAt": "2023-12-15T00:31:35.601Z",
"CreatedAt": "2023-12-15T00:31:35.601Z",
"Deleted": false
},
"Deprecated": false
},
{
"ID": "657b9e8a153787e41052c25e",
"Name": "год",
"Layer": 1,
"Description": "Тариф год",
"Condition": {
"Period": {
"From": "2023-12-15T00:32:09.329Z",
"To": "2024-01-14T00:32:09.329Z"
},
"User": "",
"UserType": "",
"Coupon": "",
"PurchasesAmount": "0",
"CartPurchasesAmount": "0",
"Product": "templateUnlimTime",
"Term": "365",
"Usage": "0",
"PriceFrom": "0",
"Group": ""
},
"Target": {
"Products": [
{
"ID": "templateUnlimTime",
"Factor": 0.65,
"Overhelm": false
}
],
"Factor": 0.65,
"TargetScope": "Sum",
"TargetGroup": "",
"Overhelm": false
},
"Audit": {
"UpdatedAt": "2023-12-15T00:32:10.123Z",
"CreatedAt": "2023-12-15T00:32:10.123Z",
"Deleted": false
},
"Deprecated": false
},
{
"ID": "657b9eb4153787e41052c25f",
"Name": "3 года",
"Layer": 1,
"Description": "Тариф 3 года",
"Condition": {
"Period": {
"From": "2023-12-15T00:32:51.379Z",
"To": "2024-01-14T00:32:51.379Z"
},
"User": "",
"UserType": "",
"Coupon": "",
"PurchasesAmount": "0",
"CartPurchasesAmount": "0",
"Product": "templateUnlimTime",
"Term": "1095",
"Usage": "0",
"PriceFrom": "0",
"Group": ""
},
"Target": {
"Products": [
{
"ID": "templateUnlimTime",
"Factor": 0.5,
"Overhelm": false
}
],
"Factor": 0.5,
"TargetScope": "Sum",
"TargetGroup": "",
"Overhelm": false
},
"Audit": {
"UpdatedAt": "2023-12-15T00:32:52.174Z",
"CreatedAt": "2023-12-15T00:32:52.174Z",
"Deleted": false
},
"Deprecated": false
},
{
"ID": "657f5028153787e41052c266",
"Name": "10т.р",
"Layer": 4,
"Description": "купил больше чем на 10 тыров",
"Condition": {
"Period": {
"From": "2023-12-17T19:48:47.466Z",
"To": "2024-01-16T19:48:47.466Z"
},
"User": "",
"UserType": "",
"Coupon": "",
"PurchasesAmount": "10000",
"CartPurchasesAmount": "0",
"Product": "",
"Term": "0",
"Usage": "0",
"PriceFrom": "0",
"Group": ""
},
"Target": {
"Products": [
{
"ID": "",
"Factor": 0,
"Overhelm": false
}
],
"Factor": 0.98,
"TargetScope": "Sum",
"TargetGroup": "",
"Overhelm": false
},
"Audit": {
"UpdatedAt": "2023-12-17T19:48:46.072Z",
"CreatedAt": "2023-12-17T19:46:48.854Z",
"Deleted": false
},
"Deprecated": false
},
{
"ID": "657f50c3153787e41052c268",
"Name": "1т.р",
"Layer": 4,
"Description": "купил больше чем на 1 тыр",
"Condition": {
"Period": {
"From": "2023-12-17T19:49:24.782Z",
"To": "2024-01-16T19:49:24.782Z"
},
"User": "",
"UserType": "",
"Coupon": "",
"PurchasesAmount": "100000",
"CartPurchasesAmount": "0",
"Product": "",
"Term": "0",
"Usage": "0",
"PriceFrom": "0",
"Group": ""
},
"Target": {
"Products": [
{
"ID": "",
"Factor": 0,
"Overhelm": false
}
],
"Factor": 0.99,
"TargetScope": "Sum",
"TargetGroup": "",
"Overhelm": false
},
"Audit": {
"UpdatedAt": "2023-12-17T19:49:23.384Z",
"CreatedAt": "2023-12-17T19:49:23.384Z",
"Deleted": false
},
"Deprecated": false
},
{
"ID": "657f50e4153787e41052c269",
"Name": "100т.р",
"Layer": 4,
"Description": "купил больше чем на 100 тыров",
"Condition": {
"Period": {
"From": "2023-12-17T19:49:57.462Z",
"To": "2024-01-16T19:49:57.462Z"
},
"User": "",
"UserType": "",
"Coupon": "",
"PurchasesAmount": "10000000",
"CartPurchasesAmount": "0",
"Product": "",
"Term": "0",
"Usage": "0",
"PriceFrom": "0",
"Group": ""
},
"Target": {
"Products": [
{
"ID": "",
"Factor": 0,
"Overhelm": false
}
],
"Factor": 0.95,
"TargetScope": "Sum",
"TargetGroup": "",
"Overhelm": false
},
"Audit": {
"UpdatedAt": "2023-12-17T19:49:56.066Z",
"CreatedAt": "2023-12-17T19:49:56.066Z",
"Deleted": false
},
"Deprecated": false
},
{
"ID": "657f511b153787e41052c26a",
"Name": "1 т.р",
"Layer": 3,
"Description": "Больще 1т.р",
"Condition": {
"Period": {
"From": "2023-12-17T19:50:52.764Z",
"To": "2024-01-16T19:50:52.764Z"
},
"User": "",
"UserType": "",
"Coupon": "",
"PurchasesAmount": "0",
"CartPurchasesAmount": "100000",
"Product": "",
"Term": "0",
"Usage": "0",
"PriceFrom": "0",
"Group": ""
},
"Target": {
"Products": [
{
"ID": "",
"Factor": 0,
"Overhelm": false
}
],
"Factor": 0.95,
"TargetScope": "Sum",
"TargetGroup": "",
"Overhelm": false
},
"Audit": {
"UpdatedAt": "2023-12-17T19:50:51.408Z",
"CreatedAt": "2023-12-17T19:50:51.408Z",
"Deleted": false
},
"Deprecated": false
},
{
"ID": "657f512d153787e41052c26b",
"Name": "5 т.р",
"Layer": 3,
"Description": "Больще 5т.р",
"Condition": {
"Period": {
"From": "2023-12-17T19:51:11.104Z",
"To": "2024-01-16T19:51:11.104Z"
},
"User": "",
"UserType": "",
"Coupon": "",
"PurchasesAmount": "0",
"CartPurchasesAmount": "500000",
"Product": "",
"Term": "0",
"Usage": "0",
"PriceFrom": "0",
"Group": ""
},
"Target": {
"Products": [
{
"ID": "",
"Factor": 0,
"Overhelm": false
}
],
"Factor": 0.93,
"TargetScope": "Sum",
"TargetGroup": "",
"Overhelm": false
},
"Audit": {
"UpdatedAt": "2023-12-17T19:51:09.707Z",
"CreatedAt": "2023-12-17T19:51:09.707Z",
"Deleted": false
},
"Deprecated": false
},
{
"ID": "657f5144153787e41052c26c",
"Name": "10 т.р",
"Layer": 3,
"Description": "Больше 10т.р",
"Condition": {
"Period": {
"From": "2023-12-17T19:51:33.502Z",
"To": "2024-01-16T19:51:33.502Z"
},
"User": "",
"UserType": "",
"Coupon": "",
"PurchasesAmount": "0",
"CartPurchasesAmount": "1000000",
"Product": "",
"Term": "0",
"Usage": "0",
"PriceFrom": "0",
"Group": ""
},
"Target": {
"Products": [
{
"ID": "",
"Factor": 0,
"Overhelm": false
}
],
"Factor": 0.91,
"TargetScope": "Sum",
"TargetGroup": "",
"Overhelm": false
},
"Audit": {
"UpdatedAt": "2023-12-17T19:51:32.105Z",
"CreatedAt": "2023-12-17T19:51:32.105Z",
"Deleted": false
},
"Deprecated": false
},
{
"ID": "657f515a153787e41052c26d",
"Name": "50 т.р",
"Layer": 3,
"Description": "Больше 50т.р",
"Condition": {
"Period": {
"From": "2023-12-17T19:51:56.316Z",
"To": "2024-01-16T19:51:56.316Z"
},
"User": "",
"UserType": "",
"Coupon": "",
"PurchasesAmount": "0",
"CartPurchasesAmount": "5000000",
"Product": "",
"Term": "0",
"Usage": "0",
"PriceFrom": "0",
"Group": ""
},
"Target": {
"Products": [
{
"ID": "",
"Factor": 0,
"Overhelm": false
}
],
"Factor": 0.89,
"TargetScope": "Sum",
"TargetGroup": "",
"Overhelm": false
},
"Audit": {
"UpdatedAt": "2023-12-17T19:51:54.919Z",
"CreatedAt": "2023-12-17T19:51:54.919Z",
"Deleted": false
},
"Deprecated": false
},
{
"ID": "65872fb4153787e41052c26e",
"Name": "Лямчик",
"Layer": 4,
"Description": "Купил больше чем на миллиона",
"Condition": {
"Period": {
"From": "2023-12-23T19:06:27.521Z",
"To": "2024-01-22T19:06:27.521Z"
},
"User": "",
"UserType": "",
"Coupon": "",
"PurchasesAmount": "100000000",
"CartPurchasesAmount": "0",
"Product": "",
"Term": "0",
"Usage": "0",
"PriceFrom": "0",
"Group": ""
},
"Target": {
"Products": [
{
"ID": "",
"Factor": 0,
"Overhelm": false
}
],
"Factor": 0.9,
"TargetScope": "Sum",
"TargetGroup": "",
"Overhelm": false
},
"Audit": {
"UpdatedAt": "2023-12-23T19:06:28.253Z",
"CreatedAt": "2023-12-23T19:06:28.253Z",
"Deleted": false
},
"Deprecated": false
},
{
"ID": "6588c6e9153787e41052c26f",
"Name": "больше 5т.р",
"Layer": 2,
"Description": "Шаблонизатор:Больше 5т.р",
"Condition": {
"Period": {
"From": "2023-12-25T00:03:53.024Z",
"To": "2024-01-24T00:03:53.024Z"
},
"User": "",
"UserType": "",
"Coupon": "",
"PurchasesAmount": "0",
"CartPurchasesAmount": "0",
"Product": "",
"Term": "0",
"Usage": "0",
"PriceFrom": "500000",
"Group": "templategen"
},
"Target": {
"Products": [
{
"ID": "",
"Factor": 0,
"Overhelm": false
}
],
"Factor": 0.98,
"TargetScope": "Sum",
"TargetGroup": "templategen",
"Overhelm": false
},
"Audit": {
"UpdatedAt": "2023-12-25T00:03:53.269Z",
"CreatedAt": "2023-12-25T00:03:53.269Z",
"Deleted": false
},
"Deprecated": false
},
{
"ID": "6588c70c153787e41052c270",
"Name": "больше 10 т.р",
"Layer": 2,
"Description": "Шаблонизатор:Больше 10 т.р",
"Condition": {
"Period": {
"From": "2023-12-25T00:04:28.279Z",
"To": "2024-01-24T00:04:28.279Z"
},
"User": "",
"UserType": "",
"Coupon": "",
"PurchasesAmount": "0",
"CartPurchasesAmount": "0",
"Product": "",
"Term": "0",
"Usage": "0",
"PriceFrom": "1000000",
"Group": "templategen"
},
"Target": {
"Products": [
{
"ID": "",
"Factor": 0,
"Overhelm": false
}
],
"Factor": 0.97,
"TargetScope": "Sum",
"TargetGroup": "templategen",
"Overhelm": false
},
"Audit": {
"UpdatedAt": "2023-12-25T00:04:28.442Z",
"CreatedAt": "2023-12-25T00:04:28.442Z",
"Deleted": false
},
"Deprecated": false
},
{
"ID": "6588c724153787e41052c271",
"Name": "больше 100 т.р",
"Layer": 2,
"Description": "Шаблонизатор:Больше 100 т.р",
"Condition": {
"Period": {
"From": "2023-12-25T00:04:52.461Z",
"To": "2024-01-24T00:04:52.461Z"
},
"User": "",
"UserType": "",
"Coupon": "",
"PurchasesAmount": "0",
"CartPurchasesAmount": "0",
"Product": "",
"Term": "0",
"Usage": "0",
"PriceFrom": "10000000",
"Group": "templategen"
},
"Target": {
"Products": [
{
"ID": "",
"Factor": 0,
"Overhelm": false
}
],
"Factor": 0.95,
"TargetScope": "Sum",
"TargetGroup": "templategen",
"Overhelm": false
},
"Audit": {
"UpdatedAt": "2023-12-25T00:04:52.625Z",
"CreatedAt": "2023-12-25T00:04:52.625Z",
"Deleted": false
},
"Deprecated": false
},
{
"ID": "65a49c215389294d1c348511",
"Name": "1000 заявок",
"Layer": 1,
"Description": "Полное прохождение 1000 опросов респондентом",
"Condition": {
"Period": {
"From": "2024-01-15T02:44:49.156Z",
"To": "2024-02-14T02:44:49.156Z"
},
"User": "",
"UserType": "",
"Coupon": "",
"PurchasesAmount": "0",
"CartPurchasesAmount": "0",
"Product": "quizCnt",
"Term": "1000",
"Usage": "0",
"PriceFrom": "0",
"Group": ""
},
"Target": {
"Products": [
{
"ID": "quizCnt",
"Factor": 0.7,
"Overhelm": false
}
],
"Factor": 0.7,
"TargetScope": "Sum",
"TargetGroup": "",
"Overhelm": false
},
"Audit": {
"UpdatedAt": "2024-01-15T02:44:48.995Z",
"CreatedAt": "2024-01-15T02:44:48.995Z",
"Deleted": false
},
"Deprecated": false
},
{
"ID": "65a49c4f5389294d1c348512",
"Name": "10000 заявок",
"Layer": 1,
"Description": "Полное прохождение 10000 опросов респондентом",
"Condition": {
"Period": {
"From": "2024-01-15T02:45:37.236Z",
"To": "2024-02-14T02:45:37.236Z"
},
"User": "",
"UserType": "",
"Coupon": "",
"PurchasesAmount": "0",
"CartPurchasesAmount": "0",
"Product": "quizCnt",
"Term": "10000",
"Usage": "0",
"PriceFrom": "0",
"Group": ""
},
"Target": {
"Products": [
{
"ID": "quizCnt",
"Factor": 0.5,
"Overhelm": false
}
],
"Factor": 0.5,
"TargetScope": "Sum",
"TargetGroup": "",
"Overhelm": false
},
"Audit": {
"UpdatedAt": "2024-01-15T02:45:35.984Z",
"CreatedAt": "2024-01-15T02:45:35.984Z",
"Deleted": false
},
"Deprecated": false
},
{
"ID": "65a49d1a5389294d1c348513",
"Name": "3 месяца",
"Layer": 1,
"Description": "3 Месяца безлимита",
"Condition": {
"Period": {
"From": "2024-01-15T02:48:59.617Z",
"To": "2024-02-14T02:48:59.617Z"
},
"User": "",
"UserType": "",
"Coupon": "",
"PurchasesAmount": "0",
"CartPurchasesAmount": "0",
"Product": "quizUnlimTime",
"Term": "90",
"Usage": "0",
"PriceFrom": "0",
"Group": ""
},
"Target": {
"Products": [
{
"ID": "quizUnlimTime",
"Factor": 0.8,
"Overhelm": false
}
],
"Factor": 0.8,
"TargetScope": "Sum",
"TargetGroup": "",
"Overhelm": false
},
"Audit": {
"UpdatedAt": "2024-01-15T02:48:58.560Z",
"CreatedAt": "2024-01-15T02:48:58.560Z",
"Deleted": false
},
"Deprecated": false
},
{
"ID": "65a49d335389294d1c348514",
"Name": "Год",
"Layer": 1,
"Description": "Год безлимита",
"Condition": {
"Period": {
"From": "2024-01-15T02:49:24.266Z",
"To": "2024-02-14T02:49:24.266Z"
},
"User": "",
"UserType": "",
"Coupon": "",
"PurchasesAmount": "0",
"CartPurchasesAmount": "0",
"Product": "quizUnlimTime",
"Term": "365",
"Usage": "0",
"PriceFrom": "0",
"Group": ""
},
"Target": {
"Products": [
{
"ID": "quizUnlimTime",
"Factor": 0.65,
"Overhelm": false
}
],
"Factor": 0.65,
"TargetScope": "Sum",
"TargetGroup": "",
"Overhelm": false
},
"Audit": {
"UpdatedAt": "2024-01-15T02:49:23.024Z",
"CreatedAt": "2024-01-15T02:49:23.024Z",
"Deleted": false
},
"Deprecated": false
},
{
"ID": "65a49d4f5389294d1c348515",
"Name": "3 Года",
"Layer": 1,
"Description": "3 Года безлимита",
"Condition": {
"Period": {
"From": "2024-01-15T02:49:52.264Z",
"To": "2024-02-14T02:49:52.264Z"
},
"User": "",
"UserType": "",
"Coupon": "",
"PurchasesAmount": "0",
"CartPurchasesAmount": "0",
"Product": "quizUnlimTime",
"Term": "1095",
"Usage": "0",
"PriceFrom": "0",
"Group": ""
},
"Target": {
"Products": [
{
"ID": "quizUnlimTime",
"Factor": 0.5,
"Overhelm": false
}
],
"Factor": 0.5,
"TargetScope": "Sum",
"TargetGroup": "",
"Overhelm": false
},
"Audit": {
"UpdatedAt": "2024-01-15T02:49:51.024Z",
"CreatedAt": "2024-01-15T02:49:51.024Z",
"Deleted": false
},
"Deprecated": false
}
];

@ -0,0 +1,84 @@
type CartTestResult = [
/** Cart price */
number,
/** Used tariff mask, last number shows if nko applied */
number[],
];
export const cartTestResults: CartTestResult[] = [
[750184.5, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0]],
[680, [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]],
[232560, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]],
[910227.5, [0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0]],
[1274000, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]],
[95000, [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],
[465000, [0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1,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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]],
[1295070.1400000001, [1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0]],
];

@ -0,0 +1,812 @@
import { Tariff } from "../../../model/tariff";
export const testTariffs: Tariff[] = [
{
"_id": "64f06be63fae7d590bf6426c",
"name": "Безлимит, Количество Шаблонов, 2023-08-31T10:31:02.472Z",
"isCustom": true,
"privileges": [
{
"name": "Безлимит",
"privilegeId": "64e88d30c4c82e949d5c443d",
"serviceKey": "templategen",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 10,
"amount": 130
},
{
"name": "Количество Шаблонов",
"privilegeId": "64e88d30c4c82e949d5c443e",
"serviceKey": "templategen",
"description": "Количество шаблонов, которые может сделать пользователь сервиса",
"type": "count",
"value": "шаблон",
"price": 5,
"amount": 2100
}
],
"isDeleted": false,
"createdAt": "2023-08-31T10:31:02.570Z",
"updatedAt": "2023-08-31T10:31:02.570Z"
},
{
"_id": "64f06be93fae7d590bf64271",
"name": "Безлимит, Количество Шаблонов, 2023-08-31T10:31:05.703Z",
"isCustom": true,
"privileges": [
{
"name": "Безлимит",
"privilegeId": "64e88d30c4c82e949d5c443d",
"serviceKey": "templategen",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 10,
"amount": 130
},
{
"name": "Количество Шаблонов",
"privilegeId": "64e88d30c4c82e949d5c443e",
"serviceKey": "templategen",
"description": "Количество шаблонов, которые может сделать пользователь сервиса",
"type": "count",
"value": "шаблон",
"price": 5,
"amount": 2100
}
],
"isDeleted": false,
"createdAt": "2023-08-31T10:31:05.732Z",
"updatedAt": "2023-08-31T10:31:05.732Z"
},
{
"_id": "64f06be93fae7d590bf64276",
"name": "Безлимит, Количество Шаблонов, 2023-08-31T10:31:05.874Z",
"isCustom": true,
"privileges": [
{
"name": "Безлимит",
"privilegeId": "64e88d30c4c82e949d5c443d",
"serviceKey": "templategen",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 10,
"amount": 130
},
{
"name": "Количество Шаблонов",
"privilegeId": "64e88d30c4c82e949d5c443e",
"serviceKey": "templategen",
"description": "Количество шаблонов, которые может сделать пользователь сервиса",
"type": "count",
"value": "шаблон",
"price": 5,
"amount": 2100
}
],
"isDeleted": false,
"createdAt": "2023-08-31T10:31:05.884Z",
"updatedAt": "2023-08-31T10:31:05.884Z"
},
{
"_id": "64f06c103fae7d590bf6427b",
"name": "Безлимит, Количество Шаблонов, 2023-08-31T10:31:44.015Z",
"isCustom": true,
"privileges": [
{
"name": "Безлимит",
"privilegeId": "64e88d30c4c82e949d5c443d",
"serviceKey": "templategen",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 10,
"amount": 130
},
{
"name": "Количество Шаблонов",
"privilegeId": "64e88d30c4c82e949d5c443e",
"serviceKey": "templategen",
"description": "Количество шаблонов, которые может сделать пользователь сервиса",
"type": "count",
"value": "шаблон",
"price": 5,
"amount": 2100
}
],
"isDeleted": false,
"createdAt": "2023-08-31T10:31:44.198Z",
"updatedAt": "2023-08-31T10:31:44.198Z"
},
{
"_id": "64f06c123fae7d590bf64280",
"name": "Безлимит, Количество Шаблонов, 2023-08-31T10:31:16.087Z",
"isCustom": true,
"privileges": [
{
"name": "Безлимит",
"privilegeId": "64e88d30c4c82e949d5c443d",
"serviceKey": "templategen",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 10,
"amount": 130
},
{
"name": "Количество Шаблонов",
"privilegeId": "64e88d30c4c82e949d5c443e",
"serviceKey": "templategen",
"description": "Количество шаблонов, которые может сделать пользователь сервиса",
"type": "count",
"value": "шаблон",
"price": 5,
"amount": 2100
}
],
"isDeleted": false,
"createdAt": "2023-08-31T10:31:46.954Z",
"updatedAt": "2023-08-31T10:31:46.954Z"
},
{
"_id": "64f61a713fae7d590bf6494c",
"name": "Размер Диска, Безлимит, 2023-09-04T17:57:05.862Z",
"isCustom": true,
"privileges": [
{
"name": "Размер Диска",
"privilegeId": "64e88d30c4c82e949d5c443c",
"serviceKey": "templategen",
"description": "Обьём ПенаДиска для хранения шаблонов и результатов шаблонизации",
"type": "count",
"value": "МБ",
"price": 555,
"amount": 1500
},
{
"name": "Безлимит",
"privilegeId": "64e88d30c4c82e949d5c443d",
"serviceKey": "templategen",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 10,
"amount": 220
}
],
"isDeleted": false,
"createdAt": "2023-09-04T17:57:05.987Z",
"updatedAt": "2023-09-04T17:57:05.987Z"
},
{
"_id": "64ff6eb75913fc89c5667d85",
"name": "Безлимит, 2023-09-11T19:47:03.383Z",
"isCustom": true,
"privileges": [
{
"name": "Безлимит",
"privilegeId": "64e88d30c4c82e949d5c443d",
"serviceKey": "templategen",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 10,
"amount": 170
}
],
"isDeleted": false,
"createdAt": "2023-09-11T19:47:03.546Z",
"updatedAt": "2023-09-11T19:47:03.546Z"
},
{
"_id": "657b9b11215b615d2e35741f",
"name": "100 шаблонов",
"price": 0,
"isCustom": false,
"privileges": [
{
"name": "Количество Шаблонов",
"privilegeId": "templateCnt",
"serviceKey": "templategen",
"description": "Количество шаблонов, которые может сделать пользователь сервиса",
"type": "count",
"value": "шаблон",
"price": 1000,
"amount": 100
}
],
"isDeleted": false,
"createdAt": "2023-12-15T00:17:21.104Z",
"updatedAt": "2023-12-15T00:17:21.104Z"
},
{
"_id": "657b9b1a215b615d2e357424",
"name": "1000 шаблонов",
"price": 0,
"isCustom": false,
"privileges": [
{
"name": "Количество Шаблонов",
"privilegeId": "templateCnt",
"serviceKey": "templategen",
"description": "Количество шаблонов, которые может сделать пользователь сервиса",
"type": "count",
"value": "шаблон",
"price": 1000,
"amount": 1000
}
],
"isDeleted": false,
"createdAt": "2023-12-15T00:17:30.813Z",
"updatedAt": "2023-12-15T00:17:30.813Z"
},
{
"_id": "657b9b98215b615d2e35743a",
"name": "10000 шаблонов",
"price": 0,
"isCustom": false,
"privileges": [
{
"name": "Количество Шаблонов",
"privilegeId": "templateCnt",
"serviceKey": "templategen",
"description": "Количество шаблонов, которые может сделать пользователь сервиса",
"type": "count",
"value": "шаблон",
"price": 1000,
"amount": 10000
}
],
"isDeleted": false,
"createdAt": "2023-12-15T00:19:36.848Z",
"updatedAt": "2023-12-15T00:19:36.848Z"
},
{
"_id": "657b9bd0215b615d2e357445",
"name": "1 день",
"price": 10000,
"isCustom": false,
"privileges": [
{
"name": "Безлимит",
"privilegeId": "templateUnlimTime",
"serviceKey": "templategen",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 1700,
"amount": 1
}
],
"isDeleted": false,
"createdAt": "2023-12-15T00:20:32.586Z",
"updatedAt": "2023-12-15T00:20:32.586Z"
},
{
"_id": "657b9c15215b615d2e35745f",
"name": "Месяц",
"price": 0,
"isCustom": false,
"privileges": [
{
"name": "Безлимит",
"privilegeId": "templateUnlimTime",
"serviceKey": "templategen",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 1700,
"amount": 30
}
],
"isDeleted": false,
"createdAt": "2023-12-15T00:21:41.878Z",
"updatedAt": "2023-12-15T00:21:41.878Z"
},
{
"_id": "657b9c25215b615d2e357464",
"name": "3 месяца",
"price": 0,
"isCustom": false,
"privileges": [
{
"name": "Безлимит",
"privilegeId": "templateUnlimTime",
"serviceKey": "templategen",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 1700,
"amount": 90
}
],
"isDeleted": false,
"createdAt": "2023-12-15T00:21:57.114Z",
"updatedAt": "2023-12-15T00:21:57.114Z"
},
{
"_id": "657b9c4d215b615d2e357469",
"name": "Год",
"price": 0,
"isCustom": false,
"privileges": [
{
"name": "Безлимит",
"privilegeId": "templateUnlimTime",
"serviceKey": "templategen",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 1700,
"amount": 365
}
],
"isDeleted": false,
"createdAt": "2023-12-15T00:22:37.456Z",
"updatedAt": "2023-12-15T00:22:37.456Z"
},
{
"_id": "657b9c59215b615d2e35746e",
"name": "3 года",
"price": 0,
"isCustom": false,
"privileges": [
{
"name": "Безлимит",
"privilegeId": "templateUnlimTime",
"serviceKey": "templategen",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 1700,
"amount": 1095
}
],
"isDeleted": false,
"createdAt": "2023-12-15T00:22:49.492Z",
"updatedAt": "2023-12-15T00:22:49.492Z"
},
{
"_id": "65af14358507c326f5a2db91",
"name": "Безлимит Опросов, Количество Заявок, 2024-01-23T01:19:49.676Z",
"isCustom": true,
"privileges": [
{
"name": "Безлимит Опросов",
"privilegeId": "quizUnlimTime",
"serviceKey": "squiz",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 3400,
"amount": 30
},
{
"name": "Количество Заявок",
"privilegeId": "quizCnt",
"serviceKey": "squiz",
"description": "Количество полных прохождений опросов",
"type": "count",
"value": "заявка",
"price": 2000,
"amount": 100
}
],
"isDeleted": false,
"createdAt": "2024-01-23T01:19:49.897Z",
"updatedAt": "2024-01-23T01:19:49.897Z"
},
{
"_id": "65af1b978507c326f5a2dbaa",
"name": "Безлимит Опросов, Количество Заявок, 2024-01-23T01:51:19.622Z",
"isCustom": true,
"privileges": [
{
"name": "Безлимит Опросов",
"privilegeId": "quizUnlimTime",
"serviceKey": "squiz",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 3400,
"amount": 3
},
{
"name": "Количество Заявок",
"privilegeId": "quizCnt",
"serviceKey": "squiz",
"description": "Количество полных прохождений опросов",
"type": "count",
"value": "заявка",
"price": 2000,
"amount": 100
}
],
"isDeleted": false,
"createdAt": "2024-01-23T01:51:19.814Z",
"updatedAt": "2024-01-23T01:51:19.814Z"
},
{
"_id": "65afd0518507c326f5a2e59d",
"name": "Безлимит Опросов, Количество Заявок, 2024-01-23T14:42:25.093Z",
"isCustom": true,
"privileges": [
{
"name": "Безлимит Опросов",
"privilegeId": "quizUnlimTime",
"serviceKey": "squiz",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 3400,
"amount": 70
},
{
"name": "Количество Заявок",
"privilegeId": "quizCnt",
"serviceKey": "squiz",
"description": "Количество полных прохождений опросов",
"type": "count",
"value": "заявка",
"price": 2000,
"amount": 850
}
],
"isDeleted": false,
"createdAt": "2024-01-23T14:42:25.154Z",
"updatedAt": "2024-01-23T14:42:25.154Z"
},
{
"_id": "65afd05e8507c326f5a2e5a2",
"name": "Безлимит Опросов, Количество Заявок, 2024-01-23T14:42:38.254Z",
"isCustom": true,
"privileges": [
{
"name": "Безлимит Опросов",
"privilegeId": "quizUnlimTime",
"serviceKey": "squiz",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 3400,
"amount": 70
},
{
"name": "Количество Заявок",
"privilegeId": "quizCnt",
"serviceKey": "squiz",
"description": "Количество полных прохождений опросов",
"type": "count",
"value": "заявка",
"price": 2000,
"amount": 850
}
],
"isDeleted": false,
"createdAt": "2024-01-23T14:42:38.338Z",
"updatedAt": "2024-01-23T14:42:38.339Z"
},
{
"_id": "65afd0738507c326f5a2e5a7",
"name": "Безлимит Опросов, Количество Заявок, 2024-01-23T14:42:58.966Z",
"isCustom": true,
"privileges": [
{
"name": "Безлимит Опросов",
"privilegeId": "quizUnlimTime",
"serviceKey": "squiz",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 3400,
"amount": 70
},
{
"name": "Количество Заявок",
"privilegeId": "quizCnt",
"serviceKey": "squiz",
"description": "Количество полных прохождений опросов",
"type": "count",
"value": "заявка",
"price": 2000,
"amount": 850
}
],
"isDeleted": false,
"createdAt": "2024-01-23T14:42:59.050Z",
"updatedAt": "2024-01-23T14:42:59.050Z"
},
{
"_id": "65afd08a8507c326f5a2e5ac",
"name": "Безлимит Опросов, Количество Заявок, 2024-01-23T14:43:22.214Z",
"isCustom": true,
"privileges": [
{
"name": "Безлимит Опросов",
"privilegeId": "quizUnlimTime",
"serviceKey": "squiz",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 3400,
"amount": 30
},
{
"name": "Количество Заявок",
"privilegeId": "quizCnt",
"serviceKey": "squiz",
"description": "Количество полных прохождений опросов",
"type": "count",
"value": "заявка",
"price": 2000,
"amount": 100
}
],
"isDeleted": false,
"createdAt": "2024-01-23T14:43:22.284Z",
"updatedAt": "2024-01-23T14:43:22.284Z"
},
{
"_id": "65b2d740c644401f2ff3ad26",
"name": "Безлимит Опросов, Количество Заявок, 2024-01-25T21:48:47.933Z",
"isCustom": true,
"privileges": [
{
"name": "Безлимит Опросов",
"privilegeId": "quizUnlimTime",
"serviceKey": "squiz",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 3400,
"amount": 100
},
{
"name": "Количество Заявок",
"privilegeId": "quizCnt",
"serviceKey": "squiz",
"description": "Количество полных прохождений опросов",
"type": "count",
"value": "заявка",
"price": 2000,
"amount": 3480
}
],
"isDeleted": false,
"createdAt": "2024-01-25T21:48:48.015Z",
"updatedAt": "2024-01-25T21:48:48.015Z"
},
{
"_id": "657b9b06215b615d2e35741a",
"name": "10 шаблонов",
"price": 20000,
"order": 1,
"isCustom": false,
"privileges": [
{
"name": "Количество Шаблонов",
"privilegeId": "templateCnt",
"serviceKey": "templategen",
"description": "Количество шаблонов, которые может сделать пользователь сервиса",
"type": "count",
"value": "шаблон",
"price": 1000,
"amount": 0
}
],
"isDeleted": false,
"createdAt": "2024-01-14T19:22:07.206Z",
"updatedAt": "2024-01-14T19:22:07.206Z"
},
{
"_id": "65a493550089bcd87ba53d4b",
"name": "10 заявок",
"description": "Полное прохождение 10 опросов респондентом",
"price": 0,
"order": 1,
"isCustom": false,
"privileges": [
{
"name": "Количество Заявок",
"privilegeId": "quizCnt",
"serviceKey": "squiz",
"description": "Количество полных прохождений опросов",
"type": "count",
"value": "заявка",
"price": 2000,
"amount": 10
}
],
"isDeleted": false,
"createdAt": "2024-01-15T02:07:17.403Z",
"updatedAt": "2024-01-15T02:07:17.403Z"
},
{
"_id": "65a493b60089bcd87ba53d5f",
"name": "1 день",
"description": "день безлимитного пользования сервисом",
"price": 10000,
"order": 1,
"isCustom": false,
"privileges": [
{
"name": "Безлимит Опросов",
"privilegeId": "quizUnlimTime",
"serviceKey": "squiz",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 3400,
"amount": 1
}
],
"isDeleted": false,
"createdAt": "2024-01-15T02:08:54.275Z",
"updatedAt": "2024-01-15T02:08:54.275Z"
},
{
"_id": "65a493640089bcd87ba53d50",
"name": "100 заявок",
"description": "Полное прохождение 100 опросов респондентом",
"price": 0,
"order": 2,
"isCustom": false,
"privileges": [
{
"name": "Количество Заявок",
"privilegeId": "quizCnt",
"serviceKey": "squiz",
"description": "Количество полных прохождений опросов",
"type": "count",
"value": "заявка",
"price": 2000,
"amount": 100
}
],
"isDeleted": false,
"createdAt": "2024-01-15T02:07:32.444Z",
"updatedAt": "2024-01-15T02:07:32.444Z"
},
{
"_id": "65a497890089bcd87ba53d64",
"name": "Месяц",
"description": "Месяц безлимитного пользования сервисом",
"price": 0,
"order": 2,
"isCustom": false,
"privileges": [
{
"name": "Безлимит Опросов",
"privilegeId": "quizUnlimTime",
"serviceKey": "squiz",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 3400,
"amount": 30
}
],
"isDeleted": false,
"createdAt": "2024-01-15T02:25:13.366Z",
"updatedAt": "2024-01-15T02:25:13.366Z"
},
{
"_id": "65a493740089bcd87ba53d55",
"name": "1000 заявок",
"description": "Полное прохождение 1000 опросов респондентом",
"price": 0,
"order": 3,
"isCustom": false,
"privileges": [
{
"name": "Количество Заявок",
"privilegeId": "quizCnt",
"serviceKey": "squiz",
"description": "Количество полных прохождений опросов",
"type": "count",
"value": "заявка",
"price": 2000,
"amount": 1000
}
],
"isDeleted": false,
"createdAt": "2024-01-15T02:07:48.095Z",
"updatedAt": "2024-01-15T02:07:48.095Z"
},
{
"_id": "65a4987e0089bcd87ba53d75",
"name": "3 Месяца",
"description": "3 Месяца безлимитного пользования сервисом",
"price": 0,
"order": 3,
"isCustom": false,
"privileges": [
{
"name": "Безлимит Опросов",
"privilegeId": "quizUnlimTime",
"serviceKey": "squiz",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 3400,
"amount": 90
}
],
"isDeleted": false,
"createdAt": "2024-01-15T02:29:18.577Z",
"updatedAt": "2024-01-15T02:29:18.577Z"
},
{
"_id": "65a498cc0089bcd87ba53d92",
"name": "Год",
"description": "Год безлимитного пользования сервисом",
"price": 0,
"order": 3,
"isCustom": false,
"privileges": [
{
"name": "Безлимит Опросов",
"privilegeId": "quizUnlimTime",
"serviceKey": "squiz",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 3400,
"amount": 365
}
],
"isDeleted": false,
"createdAt": "2024-01-15T02:30:36.131Z",
"updatedAt": "2024-01-15T02:30:36.131Z"
},
{
"_id": "65a493830089bcd87ba53d5a",
"name": "10000 заявок",
"description": "Полное прохождение 10000 опросов респондентом",
"price": 0,
"order": 4,
"isCustom": false,
"privileges": [
{
"name": "Количество Заявок",
"privilegeId": "quizCnt",
"serviceKey": "squiz",
"description": "Количество полных прохождений опросов",
"type": "count",
"value": "заявка",
"price": 2000,
"amount": 10000
}
],
"isDeleted": false,
"createdAt": "2024-01-15T02:08:03.341Z",
"updatedAt": "2024-01-15T02:08:03.341Z"
},
{
"_id": "65a498f80089bcd87ba53d97",
"name": "3 Года",
"description": "3 Года безлимитного пользования сервисом",
"price": 0,
"order": 4,
"isCustom": false,
"privileges": [
{
"name": "Безлимит Опросов",
"privilegeId": "quizUnlimTime",
"serviceKey": "squiz",
"description": "Количество дней, в течении которых пользование сервисом безлимитно",
"type": "day",
"value": "день",
"price": 3400,
"amount": 1095
}
],
"isDeleted": false,
"createdAt": "2024-01-15T02:31:20.448Z",
"updatedAt": "2024-01-15T02:31:20.448Z"
}
];

@ -1,14 +0,0 @@
import { Discount } from "../../model/discount";
export function findNkoDiscount(discounts: Discount[]): Discount | null {
const applicableDiscounts = discounts.filter(discount => discount.Condition.UserType === "nko");
if (!applicableDiscounts.length) return null;
const maxValueDiscount = applicableDiscounts.reduce((prev, current) => {
return Number(current.Condition.CartPurchasesAmount) > Number(prev.Condition.CartPurchasesAmount) ? current : prev;
});
return maxValueDiscount;
}

@ -1,35 +0,0 @@
import { Discount } from "../../model";
export function findPrivilegeDiscount(
privilegeId: string,
privilegePrice: number,
discounts: Discount[],
userId: string,
): Discount | null {
const applicableDiscounts = discounts.filter(discount => {
if (discount.Condition.User !== "" && discount.Condition.User === userId) return true;
return (
discount.Layer === 1 &&
privilegeId === discount.Condition.Product &&
privilegePrice >= Number(discount.Condition.Term)
);
});
if (!applicableDiscounts.length) return null;
let maxValueDiscount: Discount = applicableDiscounts[0];
for (const discount of applicableDiscounts) {
if (discount.Condition.User !== "" && discount.Condition.User === userId) {
maxValueDiscount = discount;
break;
}
if (Number(discount.Condition.Term) > Number(maxValueDiscount.Condition.Term)) {
maxValueDiscount = discount;
}
}
return maxValueDiscount;
}

@ -1,35 +0,0 @@
import { Discount } from "../../model";
export function findServiceDiscount(
serviceKey: string,
currentPrice: number,
discounts: Discount[],
userId: string,
): Discount | null {
const applicableDiscounts = discounts.filter(discount => {
if (discount.Condition.User !== "" && discount.Condition.User === userId) return true;
return (
discount.Layer === 2 &&
discount.Condition.Group === serviceKey &&
currentPrice >= Number(discount.Condition.PriceFrom)
);
});
if (!applicableDiscounts.length) return null;
let maxValueDiscount: Discount = applicableDiscounts[0];
for (const discount of applicableDiscounts) {
if (discount.Condition.User !== "" && discount.Condition.User === userId) {
maxValueDiscount = discount;
break;
}
if (Number(discount.Condition.PriceFrom) > Number(maxValueDiscount.Condition.PriceFrom)) {
maxValueDiscount = discount;
}
}
return maxValueDiscount;
}

127
lib/utils/cart/utils.ts Normal file

@ -0,0 +1,127 @@
import { Discount } from "../../model/discount";
export function findDiscountFactor(discount: Discount | null | undefined): number {
if (!discount) return 1;
if (discount.Layer === 1) return discount.Target.Products[0].Factor;
return discount.Target.Factor;
}
export function findNkoDiscount(discounts: Discount[]): Discount | null {
const applicableDiscounts = discounts.filter(discount => discount.Condition.UserType === "nko");
if (!applicableDiscounts.length) return null;
const maxValueDiscount = applicableDiscounts.reduce((prev, current) => {
return Number(current.Condition.CartPurchasesAmount) > Number(prev.Condition.CartPurchasesAmount) ? current : prev;
});
return maxValueDiscount;
}
export function findPrivilegeDiscount(
privilegeId: string,
privilegeAmount: number,
discounts: Discount[],
userId: string,
): Discount | null {
const applicableDiscounts = discounts.filter(discount => {
return (
discount.Layer === 1
&& privilegeId === discount.Condition.Product
&& privilegeAmount >= Number(discount.Condition.Term)
&& (discount.Condition.User === "" || discount.Condition.User === userId)
);
});
if (!applicableDiscounts.length) return null;
let maxValueDiscount: Discount = applicableDiscounts[0];
for (const discount of applicableDiscounts) {
if (discount.Condition.User !== "" && discount.Condition.User === userId) {
maxValueDiscount = discount;
break;
}
if (Number(discount.Condition.Term) > Number(maxValueDiscount.Condition.Term)) {
maxValueDiscount = discount;
}
}
return maxValueDiscount;
}
export function findServiceDiscount(
serviceKey: string,
currentPrice: number,
discounts: Discount[],
userId: string,
): Discount | null {
const applicableDiscounts = discounts.filter(discount => {
return (
discount.Layer === 2
&& serviceKey === discount.Condition.Group
&& currentPrice >= Number(discount.Condition.PriceFrom)
&& (discount.Condition.User === "" || discount.Condition.User === userId)
);
});
if (!applicableDiscounts.length) return null;
let maxValueDiscount: Discount = applicableDiscounts[0];
for (const discount of applicableDiscounts) {
if (discount.Condition.User !== "" && discount.Condition.User === userId) {
maxValueDiscount = discount;
break;
}
if (Number(discount.Condition.PriceFrom) > Number(maxValueDiscount.Condition.PriceFrom)) {
maxValueDiscount = discount;
}
}
return maxValueDiscount;
}
export function findCartDiscount(
cartPurchasesAmount: number,
discounts: Discount[],
): Discount | null {
const applicableDiscounts = discounts.filter(discount => {
return (
discount.Layer === 3
&& cartPurchasesAmount >= Number(discount.Condition.CartPurchasesAmount)
);
});
if (!applicableDiscounts.length) return null;
const maxValueDiscount = applicableDiscounts.reduce((prev, current) => {
return Number(current.Condition.CartPurchasesAmount) > Number(prev.Condition.CartPurchasesAmount) ? current : prev;
});
return maxValueDiscount;
}
export function findLoyaltyDiscount(
purchasesAmount: number,
discounts: Discount[],
): Discount | null {
const applicableDiscounts = discounts.filter(discount => {
return (
discount.Layer === 4
&& discount.Condition.UserType !== "nko"
&& purchasesAmount >= Number(discount.Condition.PurchasesAmount)
);
});
if (!applicableDiscounts.length) return null;
const maxValueDiscount = applicableDiscounts.reduce((prev, current) => {
return Number(current.Condition.PurchasesAmount) > Number(prev.Condition.PurchasesAmount) ? current : prev;
});
return maxValueDiscount;
}

@ -1,6 +1,6 @@
{
"name": "@frontend/kitui",
"version": "1.0.71",
"version": "1.0.73",
"description": "test",
"main": "./dist/index.js",
"module": "./dist/index.js",
@ -22,6 +22,7 @@
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"test:cart": "vitest ./lib/utils/cart",
"prepublishOnly": "npm run build"
},
"publishConfig": {
@ -54,6 +55,7 @@
"typescript": "^5.0.2",
"vite": "^4.4.5",
"vite-plugin-dts": "^3.5.2",
"vitest": "^1.4.0",
"zustand": "^4.3.8"
},
"peerDependencies": {

5691
yarn.lock

File diff suppressed because it is too large Load Diff