@fiado/type-kit 3.483.0 → 3.484.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/_test_/unit/retailPromotions/salePromotionDiscountLevers.test.ts +49 -0
- package/bin/retailPromotions/dtos/SalePromotionLevers.d.ts +10 -3
- package/bin/retailPromotions/dtos/requests/SalePromotionLeversInput.d.ts +13 -2
- package/bin/retailPromotions/dtos/requests/SalePromotionLeversInput.js +53 -3
- package/package.json +1 -1
- package/src/retailPromotions/dtos/SalePromotionLevers.ts +11 -3
- package/src/retailPromotions/dtos/requests/SalePromotionLeversInput.ts +48 -3
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { plainToInstance } from 'class-transformer';
|
|
3
|
+
import { validate } from 'class-validator';
|
|
4
|
+
import { SalePromotionLeversInput } from '../../../src/retailPromotions/index';
|
|
5
|
+
|
|
6
|
+
/** Rutas de propiedad con error dentro de las palancas (`deviceDiscount.maxAmountCents`). */
|
|
7
|
+
const errorPaths = async (levers: Record<string, unknown>): Promise<string[]> => {
|
|
8
|
+
const errors = await validate(plainToInstance(SalePromotionLeversInput, levers) as object);
|
|
9
|
+
const walk = (list: typeof errors, prefix: string): string[] =>
|
|
10
|
+
list.flatMap((e) => {
|
|
11
|
+
const path = prefix ? `${prefix}.${e.property}` : e.property;
|
|
12
|
+
return e.children && e.children.length > 0 ? walk(e.children, path) : [path];
|
|
13
|
+
});
|
|
14
|
+
return walk(errors, '');
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
describe('deviceDiscount', () => {
|
|
18
|
+
it('acepta % o $ con tope opcional', async () => {
|
|
19
|
+
expect(await errorPaths({ deviceDiscount: { type: 'PERCENTAGE', percentBps: 1500, maxAmountCents: 200000 } })).toHaveLength(0);
|
|
20
|
+
expect(await errorPaths({ deviceDiscount: { type: 'AMOUNT', amountCents: 50000 } })).toHaveLength(0);
|
|
21
|
+
expect(await errorPaths({ deviceDiscount: { type: 'AMOUNT', amountCents: 50000, maxAmountCents: null } })).toHaveLength(0);
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('rechaza porcentaje fuera de 1..10000, monto no positivo y tope no positivo', async () => {
|
|
25
|
+
expect(await errorPaths({ deviceDiscount: { type: 'PERCENTAGE', percentBps: 0 } })).toContain('deviceDiscount.percentBps');
|
|
26
|
+
expect(await errorPaths({ deviceDiscount: { type: 'PERCENTAGE', percentBps: 10001 } })).toContain('deviceDiscount.percentBps');
|
|
27
|
+
expect(await errorPaths({ deviceDiscount: { type: 'AMOUNT', amountCents: 0 } })).toContain('deviceDiscount.amountCents');
|
|
28
|
+
expect(await errorPaths({ deviceDiscount: { type: 'AMOUNT', amountCents: 100, maxAmountCents: 0 } })).toContain('deviceDiscount.maxAmountCents');
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
describe('accessoryDiscount', () => {
|
|
33
|
+
it('sin type se asume porcentaje, como las promos existentes', async () => {
|
|
34
|
+
expect(await errorPaths({ accessoryDiscount: { percentBps: 2000, maxAmountCents: 30000 } })).toHaveLength(0);
|
|
35
|
+
expect(await errorPaths({ accessoryDiscount: { maxAmountCents: 30000 } })).toContain('accessoryDiscount.percentBps');
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('acepta monto fijo con type AMOUNT y no exige percentBps', async () => {
|
|
39
|
+
expect(await errorPaths({ accessoryDiscount: { type: 'AMOUNT', amountCents: 10000 } })).toHaveLength(0);
|
|
40
|
+
expect(await errorPaths({ accessoryDiscount: { type: 'AMOUNT', percentBps: 1000 } })).toContain('accessoryDiscount.amountCents');
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('rechaza tipo desconocido, porcentaje fuera de rango, monto y tope no positivos', async () => {
|
|
44
|
+
expect(await errorPaths({ accessoryDiscount: { type: 'FREE', percentBps: 1000 } })).toContain('accessoryDiscount.type');
|
|
45
|
+
expect(await errorPaths({ accessoryDiscount: { type: 'PERCENTAGE', percentBps: 10001 } })).toContain('accessoryDiscount.percentBps');
|
|
46
|
+
expect(await errorPaths({ accessoryDiscount: { type: 'AMOUNT', amountCents: -5 } })).toContain('accessoryDiscount.amountCents');
|
|
47
|
+
expect(await errorPaths({ accessoryDiscount: { percentBps: 1000, maxAmountCents: 0 } })).toContain('accessoryDiscount.maxAmountCents');
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -2,11 +2,18 @@ import { AccessorySubcategoryEnum } from '../../retailCatalog/enums/AccessorySub
|
|
|
2
2
|
import { ProductCategoryEnum } from '../../retailCatalog/enums/ProductCategoryEnum';
|
|
3
3
|
import { ProductTierEnum } from '../../retailCatalog/enums/ProductTierEnum';
|
|
4
4
|
import { CouponScopeEnum } from '../enums/CouponScopeEnum';
|
|
5
|
+
import { DiscountTypeEnum } from '../enums/DiscountTypeEnum';
|
|
5
6
|
import { GiftModeEnum } from '../enums/GiftModeEnum';
|
|
6
7
|
import { DiscountValue } from './DiscountValue';
|
|
7
|
-
/** Descuento en
|
|
8
|
+
/** Descuento del equipo en % o $, con tope opcional en centavos. */
|
|
9
|
+
export interface DeviceDiscountLever extends DiscountValue {
|
|
10
|
+
maxAmountCents?: number | null;
|
|
11
|
+
}
|
|
12
|
+
/** Descuento en accesorios en % o $, con tope opcional en centavos; sin `type` es `PERCENTAGE`. */
|
|
8
13
|
export interface AccessoryDiscountLever {
|
|
9
|
-
|
|
14
|
+
type?: DiscountTypeEnum | null;
|
|
15
|
+
amountCents?: number | null;
|
|
16
|
+
percentBps: number | null;
|
|
10
17
|
maxAmountCents: number | null;
|
|
11
18
|
}
|
|
12
19
|
/** Regalo por lista (`skus`) o por gama (`accessorySubcategory` + `maxPriceCents`); el cliente elige `chooseCount`. */
|
|
@@ -37,7 +44,7 @@ export interface WalletBonusLever {
|
|
|
37
44
|
}
|
|
38
45
|
/** Las 7 palancas; una palanca ausente o `null` no se usa. */
|
|
39
46
|
export interface SalePromotionLevers {
|
|
40
|
-
deviceDiscount:
|
|
47
|
+
deviceDiscount: DeviceDiscountLever | null;
|
|
41
48
|
accessoryDiscount: AccessoryDiscountLever | null;
|
|
42
49
|
gift: GiftLever | null;
|
|
43
50
|
coupon: CouponLever | null;
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { AccessorySubcategoryEnum } from '../../../retailCatalog/enums/AccessorySubcategoryEnum';
|
|
2
2
|
import { CouponScopeEnum } from '../../enums/CouponScopeEnum';
|
|
3
|
+
import { DiscountTypeEnum } from '../../enums/DiscountTypeEnum';
|
|
3
4
|
import { GiftModeEnum } from '../../enums/GiftModeEnum';
|
|
4
5
|
import { DiscountValueInput } from './DiscountValueInput';
|
|
6
|
+
/** Descuento del equipo: % (`percentBps` 1..10000) o $ (`amountCents` > 0), con tope opcional en centavos. */
|
|
7
|
+
export declare class DeviceDiscountLeverInput {
|
|
8
|
+
type: DiscountTypeEnum;
|
|
9
|
+
amountCents?: number | null;
|
|
10
|
+
percentBps?: number | null;
|
|
11
|
+
maxAmountCents?: number | null;
|
|
12
|
+
}
|
|
13
|
+
/** Descuento en accesorios: igual que el del equipo, pero sin `type` se asume `PERCENTAGE`. */
|
|
5
14
|
export declare class AccessoryDiscountLeverInput {
|
|
6
|
-
|
|
15
|
+
type?: DiscountTypeEnum | null;
|
|
16
|
+
amountCents?: number | null;
|
|
17
|
+
percentBps?: number | null;
|
|
7
18
|
maxAmountCents?: number | null;
|
|
8
19
|
}
|
|
9
20
|
/** Regalo por lista exige `skus`; por gama exige `accessorySubcategory` y `maxPriceCents`. */
|
|
@@ -31,7 +42,7 @@ export declare class WalletBonusLeverInput {
|
|
|
31
42
|
}
|
|
32
43
|
/** Las 7 palancas en el body; que venga al menos una lo valida el lambda (422). */
|
|
33
44
|
export declare class SalePromotionLeversInput {
|
|
34
|
-
deviceDiscount?:
|
|
45
|
+
deviceDiscount?: DeviceDiscountLeverInput | null;
|
|
35
46
|
accessoryDiscount?: AccessoryDiscountLeverInput | null;
|
|
36
47
|
gift?: GiftLeverInput | null;
|
|
37
48
|
coupon?: CouponLeverInput | null;
|
|
@@ -9,25 +9,75 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.SalePromotionLeversInput = exports.WalletBonusLeverInput = exports.ExtendedWarrantyLeverInput = exports.AirtimeLeverInput = exports.CouponLeverInput = exports.GiftLeverInput = exports.AccessoryDiscountLeverInput = void 0;
|
|
12
|
+
exports.SalePromotionLeversInput = exports.WalletBonusLeverInput = exports.ExtendedWarrantyLeverInput = exports.AirtimeLeverInput = exports.CouponLeverInput = exports.GiftLeverInput = exports.AccessoryDiscountLeverInput = exports.DeviceDiscountLeverInput = void 0;
|
|
13
13
|
const class_transformer_1 = require("class-transformer");
|
|
14
14
|
const class_validator_1 = require("class-validator");
|
|
15
15
|
const AccessorySubcategoryEnum_1 = require("../../../retailCatalog/enums/AccessorySubcategoryEnum");
|
|
16
16
|
const CouponScopeEnum_1 = require("../../enums/CouponScopeEnum");
|
|
17
|
+
const DiscountTypeEnum_1 = require("../../enums/DiscountTypeEnum");
|
|
17
18
|
const GiftModeEnum_1 = require("../../enums/GiftModeEnum");
|
|
18
19
|
const DiscountValueInput_1 = require("./DiscountValueInput");
|
|
20
|
+
/** Descuento del equipo: % (`percentBps` 1..10000) o $ (`amountCents` > 0), con tope opcional en centavos. */
|
|
21
|
+
class DeviceDiscountLeverInput {
|
|
22
|
+
}
|
|
23
|
+
exports.DeviceDiscountLeverInput = DeviceDiscountLeverInput;
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, class_transformer_1.Expose)(),
|
|
26
|
+
(0, class_validator_1.IsEnum)(DiscountTypeEnum_1.DiscountTypeEnum),
|
|
27
|
+
__metadata("design:type", String)
|
|
28
|
+
], DeviceDiscountLeverInput.prototype, "type", void 0);
|
|
29
|
+
__decorate([
|
|
30
|
+
(0, class_transformer_1.Expose)(),
|
|
31
|
+
(0, class_validator_1.ValidateIf)((o) => o.type === DiscountTypeEnum_1.DiscountTypeEnum.AMOUNT),
|
|
32
|
+
(0, class_validator_1.IsInt)(),
|
|
33
|
+
(0, class_validator_1.Min)(1),
|
|
34
|
+
__metadata("design:type", Number)
|
|
35
|
+
], DeviceDiscountLeverInput.prototype, "amountCents", void 0);
|
|
36
|
+
__decorate([
|
|
37
|
+
(0, class_transformer_1.Expose)(),
|
|
38
|
+
(0, class_validator_1.ValidateIf)((o) => o.type === DiscountTypeEnum_1.DiscountTypeEnum.PERCENTAGE),
|
|
39
|
+
(0, class_validator_1.IsInt)(),
|
|
40
|
+
(0, class_validator_1.Min)(1),
|
|
41
|
+
(0, class_validator_1.Max)(10000),
|
|
42
|
+
__metadata("design:type", Number)
|
|
43
|
+
], DeviceDiscountLeverInput.prototype, "percentBps", void 0);
|
|
44
|
+
__decorate([
|
|
45
|
+
(0, class_transformer_1.Expose)(),
|
|
46
|
+
(0, class_validator_1.IsOptional)(),
|
|
47
|
+
(0, class_validator_1.IsInt)(),
|
|
48
|
+
(0, class_validator_1.Min)(1),
|
|
49
|
+
__metadata("design:type", Number)
|
|
50
|
+
], DeviceDiscountLeverInput.prototype, "maxAmountCents", void 0);
|
|
51
|
+
/** Descuento en accesorios: igual que el del equipo, pero sin `type` se asume `PERCENTAGE`. */
|
|
19
52
|
class AccessoryDiscountLeverInput {
|
|
20
53
|
}
|
|
21
54
|
exports.AccessoryDiscountLeverInput = AccessoryDiscountLeverInput;
|
|
22
55
|
__decorate([
|
|
23
56
|
(0, class_transformer_1.Expose)(),
|
|
57
|
+
(0, class_validator_1.IsOptional)(),
|
|
58
|
+
(0, class_validator_1.IsEnum)(DiscountTypeEnum_1.DiscountTypeEnum),
|
|
59
|
+
__metadata("design:type", String)
|
|
60
|
+
], AccessoryDiscountLeverInput.prototype, "type", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, class_transformer_1.Expose)(),
|
|
63
|
+
(0, class_validator_1.ValidateIf)((o) => o.type === DiscountTypeEnum_1.DiscountTypeEnum.AMOUNT),
|
|
64
|
+
(0, class_validator_1.IsInt)(),
|
|
65
|
+
(0, class_validator_1.Min)(1),
|
|
66
|
+
__metadata("design:type", Number)
|
|
67
|
+
], AccessoryDiscountLeverInput.prototype, "amountCents", void 0);
|
|
68
|
+
__decorate([
|
|
69
|
+
(0, class_transformer_1.Expose)(),
|
|
70
|
+
(0, class_validator_1.ValidateIf)((o) => o.type !== DiscountTypeEnum_1.DiscountTypeEnum.AMOUNT),
|
|
24
71
|
(0, class_validator_1.IsInt)(),
|
|
72
|
+
(0, class_validator_1.Min)(1),
|
|
73
|
+
(0, class_validator_1.Max)(10000),
|
|
25
74
|
__metadata("design:type", Number)
|
|
26
75
|
], AccessoryDiscountLeverInput.prototype, "percentBps", void 0);
|
|
27
76
|
__decorate([
|
|
28
77
|
(0, class_transformer_1.Expose)(),
|
|
29
78
|
(0, class_validator_1.IsOptional)(),
|
|
30
79
|
(0, class_validator_1.IsInt)(),
|
|
80
|
+
(0, class_validator_1.Min)(1),
|
|
31
81
|
__metadata("design:type", Number)
|
|
32
82
|
], AccessoryDiscountLeverInput.prototype, "maxAmountCents", void 0);
|
|
33
83
|
/** Regalo por lista exige `skus`; por gama exige `accessorySubcategory` y `maxPriceCents`. */
|
|
@@ -119,8 +169,8 @@ __decorate([
|
|
|
119
169
|
(0, class_transformer_1.Expose)(),
|
|
120
170
|
(0, class_validator_1.IsOptional)(),
|
|
121
171
|
(0, class_validator_1.ValidateNested)(),
|
|
122
|
-
(0, class_transformer_1.Type)(() =>
|
|
123
|
-
__metadata("design:type",
|
|
172
|
+
(0, class_transformer_1.Type)(() => DeviceDiscountLeverInput),
|
|
173
|
+
__metadata("design:type", DeviceDiscountLeverInput)
|
|
124
174
|
], SalePromotionLeversInput.prototype, "deviceDiscount", void 0);
|
|
125
175
|
__decorate([
|
|
126
176
|
(0, class_transformer_1.Expose)(),
|
package/package.json
CHANGED
|
@@ -2,12 +2,20 @@ import { AccessorySubcategoryEnum } from '../../retailCatalog/enums/AccessorySub
|
|
|
2
2
|
import { ProductCategoryEnum } from '../../retailCatalog/enums/ProductCategoryEnum';
|
|
3
3
|
import { ProductTierEnum } from '../../retailCatalog/enums/ProductTierEnum';
|
|
4
4
|
import { CouponScopeEnum } from '../enums/CouponScopeEnum';
|
|
5
|
+
import { DiscountTypeEnum } from '../enums/DiscountTypeEnum';
|
|
5
6
|
import { GiftModeEnum } from '../enums/GiftModeEnum';
|
|
6
7
|
import { DiscountValue } from './DiscountValue';
|
|
7
8
|
|
|
8
|
-
/** Descuento en
|
|
9
|
+
/** Descuento del equipo en % o $, con tope opcional en centavos. */
|
|
10
|
+
export interface DeviceDiscountLever extends DiscountValue {
|
|
11
|
+
maxAmountCents?: number | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Descuento en accesorios en % o $, con tope opcional en centavos; sin `type` es `PERCENTAGE`. */
|
|
9
15
|
export interface AccessoryDiscountLever {
|
|
10
|
-
|
|
16
|
+
type?: DiscountTypeEnum | null;
|
|
17
|
+
amountCents?: number | null;
|
|
18
|
+
percentBps: number | null;
|
|
11
19
|
maxAmountCents: number | null;
|
|
12
20
|
}
|
|
13
21
|
|
|
@@ -44,7 +52,7 @@ export interface WalletBonusLever {
|
|
|
44
52
|
|
|
45
53
|
/** Las 7 palancas; una palanca ausente o `null` no se usa. */
|
|
46
54
|
export interface SalePromotionLevers {
|
|
47
|
-
deviceDiscount:
|
|
55
|
+
deviceDiscount: DeviceDiscountLever | null;
|
|
48
56
|
accessoryDiscount: AccessoryDiscountLever | null;
|
|
49
57
|
gift: GiftLever | null;
|
|
50
58
|
coupon: CouponLever | null;
|
|
@@ -5,23 +5,68 @@ import {
|
|
|
5
5
|
IsEnum,
|
|
6
6
|
IsInt,
|
|
7
7
|
IsOptional,
|
|
8
|
+
Max,
|
|
9
|
+
Min,
|
|
8
10
|
IsString,
|
|
9
11
|
ValidateIf,
|
|
10
12
|
ValidateNested,
|
|
11
13
|
} from 'class-validator';
|
|
12
14
|
import { AccessorySubcategoryEnum } from '../../../retailCatalog/enums/AccessorySubcategoryEnum';
|
|
13
15
|
import { CouponScopeEnum } from '../../enums/CouponScopeEnum';
|
|
16
|
+
import { DiscountTypeEnum } from '../../enums/DiscountTypeEnum';
|
|
14
17
|
import { GiftModeEnum } from '../../enums/GiftModeEnum';
|
|
15
18
|
import { DiscountValueInput } from './DiscountValueInput';
|
|
16
19
|
|
|
20
|
+
/** Descuento del equipo: % (`percentBps` 1..10000) o $ (`amountCents` > 0), con tope opcional en centavos. */
|
|
21
|
+
export class DeviceDiscountLeverInput {
|
|
22
|
+
@Expose()
|
|
23
|
+
@IsEnum(DiscountTypeEnum)
|
|
24
|
+
type!: DiscountTypeEnum;
|
|
25
|
+
|
|
26
|
+
@Expose()
|
|
27
|
+
@ValidateIf((o: DeviceDiscountLeverInput) => o.type === DiscountTypeEnum.AMOUNT)
|
|
28
|
+
@IsInt()
|
|
29
|
+
@Min(1)
|
|
30
|
+
amountCents?: number | null;
|
|
31
|
+
|
|
32
|
+
@Expose()
|
|
33
|
+
@ValidateIf((o: DeviceDiscountLeverInput) => o.type === DiscountTypeEnum.PERCENTAGE)
|
|
34
|
+
@IsInt()
|
|
35
|
+
@Min(1)
|
|
36
|
+
@Max(10000)
|
|
37
|
+
percentBps?: number | null;
|
|
38
|
+
|
|
39
|
+
@Expose()
|
|
40
|
+
@IsOptional()
|
|
41
|
+
@IsInt()
|
|
42
|
+
@Min(1)
|
|
43
|
+
maxAmountCents?: number | null;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Descuento en accesorios: igual que el del equipo, pero sin `type` se asume `PERCENTAGE`. */
|
|
17
47
|
export class AccessoryDiscountLeverInput {
|
|
18
48
|
@Expose()
|
|
49
|
+
@IsOptional()
|
|
50
|
+
@IsEnum(DiscountTypeEnum)
|
|
51
|
+
type?: DiscountTypeEnum | null;
|
|
52
|
+
|
|
53
|
+
@Expose()
|
|
54
|
+
@ValidateIf((o: AccessoryDiscountLeverInput) => o.type === DiscountTypeEnum.AMOUNT)
|
|
55
|
+
@IsInt()
|
|
56
|
+
@Min(1)
|
|
57
|
+
amountCents?: number | null;
|
|
58
|
+
|
|
59
|
+
@Expose()
|
|
60
|
+
@ValidateIf((o: AccessoryDiscountLeverInput) => o.type !== DiscountTypeEnum.AMOUNT)
|
|
19
61
|
@IsInt()
|
|
20
|
-
|
|
62
|
+
@Min(1)
|
|
63
|
+
@Max(10000)
|
|
64
|
+
percentBps?: number | null;
|
|
21
65
|
|
|
22
66
|
@Expose()
|
|
23
67
|
@IsOptional()
|
|
24
68
|
@IsInt()
|
|
69
|
+
@Min(1)
|
|
25
70
|
maxAmountCents?: number | null;
|
|
26
71
|
}
|
|
27
72
|
|
|
@@ -94,8 +139,8 @@ export class SalePromotionLeversInput {
|
|
|
94
139
|
@Expose()
|
|
95
140
|
@IsOptional()
|
|
96
141
|
@ValidateNested()
|
|
97
|
-
@Type(() =>
|
|
98
|
-
deviceDiscount?:
|
|
142
|
+
@Type(() => DeviceDiscountLeverInput)
|
|
143
|
+
deviceDiscount?: DeviceDiscountLeverInput | null;
|
|
99
144
|
|
|
100
145
|
@Expose()
|
|
101
146
|
@IsOptional()
|