adminFront/src/model/discount.ts

120 lines
2.5 KiB
TypeScript
Raw Normal View History

import { ServiceType } from "./tariff";
2023-06-13 20:22:14 +00:00
export type Discount = {
ID: string;
Name: string;
Layer: number;
Description: string;
Condition: {
Period?: {
From: string;
To: string;
};
User?: string;
UserType?: string;
Coupon?: string;
PurchasesAmount?: number;
CartPurchasesAmount?: number;
Product?: string;
Term?: string;
Usage?: string;
PriceFrom?: number;
Group?: string;
};
Target: {
Products?: {
ID: string;
Factor: number;
Overhelm: boolean;
}[];
Factor?: number;
TargetScope?: string;
TargetGroup?: string;
Overhelm?: boolean;
};
Audit: {
UpdatedAt: string;
CreatedAt: string;
DeletedAt: string;
Deleted: boolean;
};
Deprecated: boolean;
2023-06-13 20:22:14 +00:00
};
export type GetDiscountResponse = {
Discounts: Discount[];
2023-06-13 20:22:14 +00:00
};
export const discountTypes = {
"purchasesAmount": "Лояльность",
"cartPurchasesAmount": "Корзина",
"service": "Сервис",
"privilege": "Товар",
} as const;
export type DiscountType = keyof typeof discountTypes;
export type CreateDiscountBodyBase = {
Name: string;
Description: string;
Condition: {
Period: {
From: string;
To: string;
};
User: string;
UserType: string;
Coupon: string;
Usage: string;
};
Target: {
Factor: number;
TargetScope: "Sum" | "Group" | "Each";
Overhelm: boolean;
};
};
export type CreateLoyaltyDiscountBody = CreateDiscountBodyBase & {
Layer: 4;
Condition: {
PurchasesAmount: number;
};
};
export type CreateCartDiscountBody = CreateDiscountBodyBase & {
Layer: 3;
Condition: {
CartPurchasesAmount: number;
};
};
export type CreateProductDiscountBody = CreateDiscountBodyBase & {
Layer: 1;
Condition: {
Product: string;
Term: string;
};
Products: [{
ID: string;
Factor: number;
Overhelm: false;
}];
};
export type CreateServiceDiscountBody = CreateDiscountBodyBase & {
Layer: 2;
Condition: {
PriceFrom: number;
Group: ServiceType;
};
Target: {
TargetGroup: ServiceType;
};
};
export type CreateAnyDiscountBody =
| CreateLoyaltyDiscountBody
| CreateCartDiscountBody
| CreateProductDiscountBody
| CreateServiceDiscountBody;