@fiado/type-kit 3.596.0 → 3.597.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/constants.test.ts +1 -2
- package/_test_/unit/rules/segmentRelation.test.ts +62 -0
- package/bin/retailPromotions/constants/retailPromotionsErrorHttpStatus.js +0 -1
- package/bin/retailPromotions/enums/RetailPromotionsErrorCodeEnum.d.ts +0 -2
- package/bin/retailPromotions/enums/RetailPromotionsErrorCodeEnum.js +0 -2
- package/bin/rules/dtos/population/SegmentGroup.d.ts +2 -1
- package/bin/rules/dtos/population/SegmentGroup.js +2 -0
- package/bin/rules/dtos/population/SegmentRelationCondition.d.ts +18 -0
- package/bin/rules/dtos/population/SegmentRelationCondition.js +69 -0
- package/bin/rules/enums/SegmentConditionKindEnum.d.ts +2 -1
- package/bin/rules/enums/SegmentConditionKindEnum.js +1 -0
- package/bin/rules/enums/SegmentRelationQuantifierKindEnum.d.ts +5 -0
- package/bin/rules/enums/SegmentRelationQuantifierKindEnum.js +9 -0
- package/bin/rules/index.d.ts +2 -0
- package/bin/rules/index.js +2 -0
- package/package.json +1 -1
- package/src/retailPromotions/constants/retailPromotionsErrorHttpStatus.ts +0 -1
- package/src/retailPromotions/enums/RetailPromotionsErrorCodeEnum.ts +0 -2
- package/src/rules/dtos/population/SegmentGroup.ts +3 -1
- package/src/rules/dtos/population/SegmentRelationCondition.ts +25 -0
- package/src/rules/enums/SegmentConditionKindEnum.ts +1 -0
- package/src/rules/enums/SegmentRelationQuantifierKindEnum.ts +5 -0
- package/src/rules/index.ts +2 -0
|
@@ -43,8 +43,7 @@ describe('catálogo de errores', () => {
|
|
|
43
43
|
expect(RETAIL_PROMOTIONS_ERROR_HTTP_STATUS.CODE_NOT_FOUND).toBe(404);
|
|
44
44
|
expect(RETAIL_PROMOTIONS_ERROR_HTTP_STATUS.DISCOUNT_AFTER_QUOTE).toBe(409);
|
|
45
45
|
expect(RETAIL_PROMOTIONS_ERROR_HTTP_STATUS.CODE_NOT_OWNED).toBe(422);
|
|
46
|
-
expect(Object.keys(RetailPromotionsErrorCodeEnum)).toHaveLength(
|
|
47
|
-
expect(RETAIL_PROMOTIONS_ERROR_HTTP_STATUS.SPLIT_FINANCING_DISABLED).toBe(409);
|
|
46
|
+
expect(Object.keys(RetailPromotionsErrorCodeEnum)).toHaveLength(35);
|
|
48
47
|
});
|
|
49
48
|
|
|
50
49
|
it('la forma de pago que la promo no acepta es 422', () => {
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import 'reflect-metadata';
|
|
2
|
+
import { plainToInstance } from 'class-transformer';
|
|
3
|
+
import { validate } from 'class-validator';
|
|
4
|
+
import * as Rules from '../../../src/rules';
|
|
5
|
+
|
|
6
|
+
const filter = { kind: 'COLUMN', table: 'directory', column: 'status', op: 'EQUALS', value: 'ACTIVE' };
|
|
7
|
+
const relation = (over: object = {}): object => ({
|
|
8
|
+
kind: 'RELATION', relation: 'referidos',
|
|
9
|
+
quantifier: { kind: 'COUNT', op: 'GTE', value: 1 },
|
|
10
|
+
filters: [filter], ...over,
|
|
11
|
+
});
|
|
12
|
+
const group = (conditions: object[]): object => ({ match: 'ALL', conditions });
|
|
13
|
+
|
|
14
|
+
const errorsOf = async (plain: object): Promise<number> =>
|
|
15
|
+
(await validate(plainToInstance(Rules.SegmentGroup, plain, { excludeExtraneousValues: true }))).length;
|
|
16
|
+
|
|
17
|
+
describe('SegmentRelationCondition', () => {
|
|
18
|
+
it('enum RELATION y quantifier kinds', () => {
|
|
19
|
+
expect(Rules.SegmentConditionKindEnum.RELATION).toBe('RELATION');
|
|
20
|
+
expect(Object.values(Rules.SegmentRelationQuantifierKindEnum)).toEqual(['ANY', 'ALL', 'COUNT']);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('instancia SegmentRelationCondition por discriminador', () => {
|
|
24
|
+
const g = plainToInstance(Rules.SegmentGroup, group([relation()]), { excludeExtraneousValues: true });
|
|
25
|
+
expect(g.conditions[0]).toBeInstanceOf(Rules.SegmentRelationCondition);
|
|
26
|
+
expect((g.conditions[0] as Rules.SegmentRelationCondition).quantifier).toBeInstanceOf(Rules.SegmentRelationQuantifier);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('COUNT con filtros -> valido', async () => {
|
|
30
|
+
expect(await errorsOf(group([relation()]))).toBe(0);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('ANY / ALL sin op ni value -> valido; ONE sin quantifier -> valido', async () => {
|
|
34
|
+
expect(await errorsOf(group([relation({ quantifier: { kind: 'ANY' } })]))).toBe(0);
|
|
35
|
+
expect(await errorsOf(group([relation({ quantifier: { kind: 'ALL' } })]))).toBe(0);
|
|
36
|
+
expect(await errorsOf(group([relation({ relation: 'referidor', quantifier: undefined })]))).toBe(0);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('COUNT sin op o sin value -> error', async () => {
|
|
40
|
+
expect(await errorsOf(group([relation({ quantifier: { kind: 'COUNT', value: 1 } })]))).toBeGreaterThan(0);
|
|
41
|
+
expect(await errorsOf(group([relation({ quantifier: { kind: 'COUNT', op: 'GTE' } })]))).toBeGreaterThan(0);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('relation con mayusculas o espacios -> error', async () => {
|
|
45
|
+
expect(await errorsOf(group([relation({ relation: 'Referidos' })]))).toBeGreaterThan(0);
|
|
46
|
+
expect(await errorsOf(group([relation({ relation: 'ref idos' })]))).toBeGreaterThan(0);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('quantifier kind desconocido -> error', async () => {
|
|
50
|
+
expect(await errorsOf(group([relation({ quantifier: { kind: 'SOME' } })]))).toBeGreaterThan(0);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('mas de 10 filters -> error; filters ausente -> error', async () => {
|
|
54
|
+
expect(await errorsOf(group([relation({ filters: Array(11).fill(filter) })]))).toBeGreaterThan(0);
|
|
55
|
+
expect(await errorsOf(group([relation({ filters: undefined })]))).toBeGreaterThan(0);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it('kind desconocido sigue rechazado; COLUMN y AGGREGATE siguen', async () => {
|
|
59
|
+
expect(await errorsOf(group([{ kind: 'OTHER' }]))).toBeGreaterThan(0);
|
|
60
|
+
expect(await errorsOf(group([filter]))).toBe(0);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -33,7 +33,6 @@ exports.RETAIL_PROMOTIONS_ERROR_HTTP_STATUS = {
|
|
|
33
33
|
[RetailPromotionsErrorCodeEnum_1.RetailPromotionsErrorCodeEnum.SALE_PROMOTION_HOLD_CONFLICT]: 409,
|
|
34
34
|
[RetailPromotionsErrorCodeEnum_1.RetailPromotionsErrorCodeEnum.INVALID_NEXT_TOKEN]: 400,
|
|
35
35
|
[RetailPromotionsErrorCodeEnum_1.RetailPromotionsErrorCodeEnum.CATALOG_SKU_NOT_FOUND]: 404,
|
|
36
|
-
[RetailPromotionsErrorCodeEnum_1.RetailPromotionsErrorCodeEnum.SPLIT_FINANCING_DISABLED]: 409,
|
|
37
36
|
[RetailPromotionsErrorCodeEnum_1.RetailPromotionsErrorCodeEnum.PROMOTION_NOT_STACKABLE]: 422,
|
|
38
37
|
[RetailPromotionsErrorCodeEnum_1.RetailPromotionsErrorCodeEnum.PROMOTION_PAYMENT_NOT_ELIGIBLE]: 422,
|
|
39
38
|
[RetailPromotionsErrorCodeEnum_1.RetailPromotionsErrorCodeEnum.SYSTEM_PROMOTION_TRANSITION_NOT_ALLOWED]: 422,
|
|
@@ -43,8 +43,6 @@ export declare enum RetailPromotionsErrorCodeEnum {
|
|
|
43
43
|
INVALID_NEXT_TOKEN = "INVALID_NEXT_TOKEN",
|
|
44
44
|
/** El SKU no existe en el catálogo. */
|
|
45
45
|
CATALOG_SKU_NOT_FOUND = "CATALOG_SKU_NOT_FOUND",
|
|
46
|
-
/** Con el reparto apagado no se aplican palancas de precio ni código; los regalos sí. */
|
|
47
|
-
SPLIT_FINANCING_DISABLED = "SPLIT_FINANCING_DISABLED",
|
|
48
46
|
/** La promo no acumulable choca con otra en la misma línea. */
|
|
49
47
|
PROMOTION_NOT_STACKABLE = "PROMOTION_NOT_STACKABLE",
|
|
50
48
|
/** La promo no acepta la forma de pago o el medio de cobro de la venta. */
|
|
@@ -47,8 +47,6 @@ var RetailPromotionsErrorCodeEnum;
|
|
|
47
47
|
RetailPromotionsErrorCodeEnum["INVALID_NEXT_TOKEN"] = "INVALID_NEXT_TOKEN";
|
|
48
48
|
/** El SKU no existe en el catálogo. */
|
|
49
49
|
RetailPromotionsErrorCodeEnum["CATALOG_SKU_NOT_FOUND"] = "CATALOG_SKU_NOT_FOUND";
|
|
50
|
-
/** Con el reparto apagado no se aplican palancas de precio ni código; los regalos sí. */
|
|
51
|
-
RetailPromotionsErrorCodeEnum["SPLIT_FINANCING_DISABLED"] = "SPLIT_FINANCING_DISABLED";
|
|
52
50
|
/** La promo no acumulable choca con otra en la misma línea. */
|
|
53
51
|
RetailPromotionsErrorCodeEnum["PROMOTION_NOT_STACKABLE"] = "PROMOTION_NOT_STACKABLE";
|
|
54
52
|
/** La promo no acepta la forma de pago o el medio de cobro de la venta. */
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { SegmentMatchEnum } from '../../enums/SegmentMatchEnum';
|
|
2
2
|
import { SegmentAggregateCondition } from './SegmentAggregateCondition';
|
|
3
3
|
import { SegmentColumnCondition } from './SegmentColumnCondition';
|
|
4
|
-
|
|
4
|
+
import { SegmentRelationCondition } from './SegmentRelationCondition';
|
|
5
|
+
export type SegmentCondition = SegmentColumnCondition | SegmentAggregateCondition | SegmentRelationCondition;
|
|
5
6
|
export declare class SegmentGroup {
|
|
6
7
|
match: SegmentMatchEnum;
|
|
7
8
|
/** `kind` decide la clase; un `kind` desconocido NO se instancia y la validacion lo rechaza (el objeto queda sin `@Equals` valido). */
|
|
@@ -16,6 +16,7 @@ const SegmentConditionKindEnum_1 = require("../../enums/SegmentConditionKindEnum
|
|
|
16
16
|
const SegmentMatchEnum_1 = require("../../enums/SegmentMatchEnum");
|
|
17
17
|
const SegmentAggregateCondition_1 = require("./SegmentAggregateCondition");
|
|
18
18
|
const SegmentColumnCondition_1 = require("./SegmentColumnCondition");
|
|
19
|
+
const SegmentRelationCondition_1 = require("./SegmentRelationCondition");
|
|
19
20
|
class SegmentGroup {
|
|
20
21
|
}
|
|
21
22
|
exports.SegmentGroup = SegmentGroup;
|
|
@@ -37,6 +38,7 @@ __decorate([
|
|
|
37
38
|
subTypes: [
|
|
38
39
|
{ value: SegmentColumnCondition_1.SegmentColumnCondition, name: SegmentConditionKindEnum_1.SegmentConditionKindEnum.COLUMN },
|
|
39
40
|
{ value: SegmentAggregateCondition_1.SegmentAggregateCondition, name: SegmentConditionKindEnum_1.SegmentConditionKindEnum.AGGREGATE },
|
|
41
|
+
{ value: SegmentRelationCondition_1.SegmentRelationCondition, name: SegmentConditionKindEnum_1.SegmentConditionKindEnum.RELATION },
|
|
40
42
|
],
|
|
41
43
|
},
|
|
42
44
|
}),
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { SegmentConditionKindEnum } from '../../enums/SegmentConditionKindEnum';
|
|
2
|
+
import { SegmentOperatorEnum } from '../../enums/SegmentOperatorEnum';
|
|
3
|
+
import { SegmentRelationQuantifierKindEnum } from '../../enums/SegmentRelationQuantifierKindEnum';
|
|
4
|
+
import { SegmentColumnCondition } from './SegmentColumnCondition';
|
|
5
|
+
/** Cuantificador de una relacion 1:N. COUNT exige `op` y `value`; ANY/ALL no los llevan. */
|
|
6
|
+
export declare class SegmentRelationQuantifier {
|
|
7
|
+
kind: SegmentRelationQuantifierKindEnum;
|
|
8
|
+
op?: SegmentOperatorEnum;
|
|
9
|
+
value?: number;
|
|
10
|
+
}
|
|
11
|
+
/** (c) Condicion sobre los relacionados de la persona (referidor / referidos). `filters` se aplica a cada relacionado. */
|
|
12
|
+
export declare class SegmentRelationCondition {
|
|
13
|
+
kind: SegmentConditionKindEnum.RELATION;
|
|
14
|
+
relation: string;
|
|
15
|
+
/** MANY: obligatorio; ONE: ausente (lo valida el compilador, no el DTO). */
|
|
16
|
+
quantifier?: SegmentRelationQuantifier;
|
|
17
|
+
filters: SegmentColumnCondition[];
|
|
18
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.SegmentRelationCondition = exports.SegmentRelationQuantifier = void 0;
|
|
13
|
+
const class_transformer_1 = require("class-transformer");
|
|
14
|
+
const class_validator_1 = require("class-validator");
|
|
15
|
+
const RulesRelationLimits_1 = require("../../constants/RulesRelationLimits");
|
|
16
|
+
const SegmentConditionKindEnum_1 = require("../../enums/SegmentConditionKindEnum");
|
|
17
|
+
const SegmentOperatorEnum_1 = require("../../enums/SegmentOperatorEnum");
|
|
18
|
+
const SegmentRelationQuantifierKindEnum_1 = require("../../enums/SegmentRelationQuantifierKindEnum");
|
|
19
|
+
const SegmentColumnCondition_1 = require("./SegmentColumnCondition");
|
|
20
|
+
/** Cuantificador de una relacion 1:N. COUNT exige `op` y `value`; ANY/ALL no los llevan. */
|
|
21
|
+
class SegmentRelationQuantifier {
|
|
22
|
+
}
|
|
23
|
+
exports.SegmentRelationQuantifier = SegmentRelationQuantifier;
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, class_transformer_1.Expose)(),
|
|
26
|
+
(0, class_validator_1.IsEnum)(SegmentRelationQuantifierKindEnum_1.SegmentRelationQuantifierKindEnum),
|
|
27
|
+
__metadata("design:type", String)
|
|
28
|
+
], SegmentRelationQuantifier.prototype, "kind", void 0);
|
|
29
|
+
__decorate([
|
|
30
|
+
(0, class_transformer_1.Expose)(),
|
|
31
|
+
(0, class_validator_1.ValidateIf)((q) => q.kind === SegmentRelationQuantifierKindEnum_1.SegmentRelationQuantifierKindEnum.COUNT || q.op !== undefined),
|
|
32
|
+
(0, class_validator_1.IsEnum)(SegmentOperatorEnum_1.SegmentOperatorEnum),
|
|
33
|
+
__metadata("design:type", String)
|
|
34
|
+
], SegmentRelationQuantifier.prototype, "op", void 0);
|
|
35
|
+
__decorate([
|
|
36
|
+
(0, class_transformer_1.Expose)(),
|
|
37
|
+
(0, class_validator_1.ValidateIf)((q) => q.kind === SegmentRelationQuantifierKindEnum_1.SegmentRelationQuantifierKindEnum.COUNT || q.value !== undefined),
|
|
38
|
+
(0, class_validator_1.IsNumber)(),
|
|
39
|
+
__metadata("design:type", Number)
|
|
40
|
+
], SegmentRelationQuantifier.prototype, "value", void 0);
|
|
41
|
+
/** (c) Condicion sobre los relacionados de la persona (referidor / referidos). `filters` se aplica a cada relacionado. */
|
|
42
|
+
class SegmentRelationCondition {
|
|
43
|
+
}
|
|
44
|
+
exports.SegmentRelationCondition = SegmentRelationCondition;
|
|
45
|
+
__decorate([
|
|
46
|
+
(0, class_transformer_1.Expose)(),
|
|
47
|
+
(0, class_validator_1.Equals)(SegmentConditionKindEnum_1.SegmentConditionKindEnum.RELATION),
|
|
48
|
+
__metadata("design:type", String)
|
|
49
|
+
], SegmentRelationCondition.prototype, "kind", void 0);
|
|
50
|
+
__decorate([
|
|
51
|
+
(0, class_transformer_1.Expose)(),
|
|
52
|
+
(0, class_validator_1.Matches)(RulesRelationLimits_1.RULES_RELATION_NAME_PATTERN),
|
|
53
|
+
__metadata("design:type", String)
|
|
54
|
+
], SegmentRelationCondition.prototype, "relation", void 0);
|
|
55
|
+
__decorate([
|
|
56
|
+
(0, class_transformer_1.Expose)(),
|
|
57
|
+
(0, class_validator_1.IsOptional)(),
|
|
58
|
+
(0, class_validator_1.ValidateNested)(),
|
|
59
|
+
(0, class_transformer_1.Type)(() => SegmentRelationQuantifier),
|
|
60
|
+
__metadata("design:type", SegmentRelationQuantifier)
|
|
61
|
+
], SegmentRelationCondition.prototype, "quantifier", void 0);
|
|
62
|
+
__decorate([
|
|
63
|
+
(0, class_transformer_1.Expose)(),
|
|
64
|
+
(0, class_validator_1.IsArray)(),
|
|
65
|
+
(0, class_validator_1.ArrayMaxSize)(10),
|
|
66
|
+
(0, class_validator_1.ValidateNested)({ each: true }),
|
|
67
|
+
(0, class_transformer_1.Type)(() => SegmentColumnCondition_1.SegmentColumnCondition),
|
|
68
|
+
__metadata("design:type", Array)
|
|
69
|
+
], SegmentRelationCondition.prototype, "filters", void 0);
|
|
@@ -5,4 +5,5 @@ var SegmentConditionKindEnum;
|
|
|
5
5
|
(function (SegmentConditionKindEnum) {
|
|
6
6
|
SegmentConditionKindEnum["COLUMN"] = "COLUMN";
|
|
7
7
|
SegmentConditionKindEnum["AGGREGATE"] = "AGGREGATE";
|
|
8
|
+
SegmentConditionKindEnum["RELATION"] = "RELATION";
|
|
8
9
|
})(SegmentConditionKindEnum || (exports.SegmentConditionKindEnum = SegmentConditionKindEnum = {}));
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SegmentRelationQuantifierKindEnum = void 0;
|
|
4
|
+
var SegmentRelationQuantifierKindEnum;
|
|
5
|
+
(function (SegmentRelationQuantifierKindEnum) {
|
|
6
|
+
SegmentRelationQuantifierKindEnum["ANY"] = "ANY";
|
|
7
|
+
SegmentRelationQuantifierKindEnum["ALL"] = "ALL";
|
|
8
|
+
SegmentRelationQuantifierKindEnum["COUNT"] = "COUNT";
|
|
9
|
+
})(SegmentRelationQuantifierKindEnum || (exports.SegmentRelationQuantifierKindEnum = SegmentRelationQuantifierKindEnum = {}));
|
package/bin/rules/index.d.ts
CHANGED
|
@@ -20,6 +20,7 @@ export * from './dtos/EvaluateRulesResponse';
|
|
|
20
20
|
export * from './enums/SegmentMatchEnum';
|
|
21
21
|
export * from './enums/SegmentOutputEnum';
|
|
22
22
|
export * from './enums/SegmentConditionKindEnum';
|
|
23
|
+
export * from './enums/SegmentRelationQuantifierKindEnum';
|
|
23
24
|
export * from './enums/SegmentAggregateFnEnum';
|
|
24
25
|
export * from './enums/SegmentOperatorEnum';
|
|
25
26
|
export * from './enums/SegmentParamTypeEnum';
|
|
@@ -28,6 +29,7 @@ export * from './constants/SegmentLimits';
|
|
|
28
29
|
export * from './dtos/population/SegmentWindow';
|
|
29
30
|
export * from './dtos/population/SegmentColumnCondition';
|
|
30
31
|
export * from './dtos/population/SegmentAggregateCondition';
|
|
32
|
+
export * from './dtos/population/SegmentRelationCondition';
|
|
31
33
|
export * from './dtos/population/SegmentGroup';
|
|
32
34
|
export * from './dtos/population/PopulationSegmentDefinition';
|
|
33
35
|
export * from './dtos/population/SegmentParam';
|
package/bin/rules/index.js
CHANGED
|
@@ -40,6 +40,7 @@ __exportStar(require("./dtos/EvaluateRulesResponse"), exports);
|
|
|
40
40
|
__exportStar(require("./enums/SegmentMatchEnum"), exports);
|
|
41
41
|
__exportStar(require("./enums/SegmentOutputEnum"), exports);
|
|
42
42
|
__exportStar(require("./enums/SegmentConditionKindEnum"), exports);
|
|
43
|
+
__exportStar(require("./enums/SegmentRelationQuantifierKindEnum"), exports);
|
|
43
44
|
__exportStar(require("./enums/SegmentAggregateFnEnum"), exports);
|
|
44
45
|
__exportStar(require("./enums/SegmentOperatorEnum"), exports);
|
|
45
46
|
__exportStar(require("./enums/SegmentParamTypeEnum"), exports);
|
|
@@ -48,6 +49,7 @@ __exportStar(require("./constants/SegmentLimits"), exports);
|
|
|
48
49
|
__exportStar(require("./dtos/population/SegmentWindow"), exports);
|
|
49
50
|
__exportStar(require("./dtos/population/SegmentColumnCondition"), exports);
|
|
50
51
|
__exportStar(require("./dtos/population/SegmentAggregateCondition"), exports);
|
|
52
|
+
__exportStar(require("./dtos/population/SegmentRelationCondition"), exports);
|
|
51
53
|
__exportStar(require("./dtos/population/SegmentGroup"), exports);
|
|
52
54
|
__exportStar(require("./dtos/population/PopulationSegmentDefinition"), exports);
|
|
53
55
|
__exportStar(require("./dtos/population/SegmentParam"), exports);
|
package/package.json
CHANGED
|
@@ -31,7 +31,6 @@ export const RETAIL_PROMOTIONS_ERROR_HTTP_STATUS: Readonly<Record<C, 400 | 403 |
|
|
|
31
31
|
[C.SALE_PROMOTION_HOLD_CONFLICT]: 409,
|
|
32
32
|
[C.INVALID_NEXT_TOKEN]: 400,
|
|
33
33
|
[C.CATALOG_SKU_NOT_FOUND]: 404,
|
|
34
|
-
[C.SPLIT_FINANCING_DISABLED]: 409,
|
|
35
34
|
[C.PROMOTION_NOT_STACKABLE]: 422,
|
|
36
35
|
[C.PROMOTION_PAYMENT_NOT_ELIGIBLE]: 422,
|
|
37
36
|
[C.SYSTEM_PROMOTION_TRANSITION_NOT_ALLOWED]: 422,
|
|
@@ -43,8 +43,6 @@ export enum RetailPromotionsErrorCodeEnum {
|
|
|
43
43
|
INVALID_NEXT_TOKEN = 'INVALID_NEXT_TOKEN',
|
|
44
44
|
/** El SKU no existe en el catálogo. */
|
|
45
45
|
CATALOG_SKU_NOT_FOUND = 'CATALOG_SKU_NOT_FOUND',
|
|
46
|
-
/** Con el reparto apagado no se aplican palancas de precio ni código; los regalos sí. */
|
|
47
|
-
SPLIT_FINANCING_DISABLED = 'SPLIT_FINANCING_DISABLED',
|
|
48
46
|
/** La promo no acumulable choca con otra en la misma línea. */
|
|
49
47
|
PROMOTION_NOT_STACKABLE = 'PROMOTION_NOT_STACKABLE',
|
|
50
48
|
/** La promo no acepta la forma de pago o el medio de cobro de la venta. */
|
|
@@ -4,8 +4,9 @@ import { SegmentConditionKindEnum } from '../../enums/SegmentConditionKindEnum';
|
|
|
4
4
|
import { SegmentMatchEnum } from '../../enums/SegmentMatchEnum';
|
|
5
5
|
import { SegmentAggregateCondition } from './SegmentAggregateCondition';
|
|
6
6
|
import { SegmentColumnCondition } from './SegmentColumnCondition';
|
|
7
|
+
import { SegmentRelationCondition } from './SegmentRelationCondition';
|
|
7
8
|
|
|
8
|
-
export type SegmentCondition = SegmentColumnCondition | SegmentAggregateCondition;
|
|
9
|
+
export type SegmentCondition = SegmentColumnCondition | SegmentAggregateCondition | SegmentRelationCondition;
|
|
9
10
|
|
|
10
11
|
export class SegmentGroup {
|
|
11
12
|
@Expose() @IsEnum(SegmentMatchEnum) match: SegmentMatchEnum;
|
|
@@ -20,6 +21,7 @@ export class SegmentGroup {
|
|
|
20
21
|
subTypes: [
|
|
21
22
|
{ value: SegmentColumnCondition, name: SegmentConditionKindEnum.COLUMN },
|
|
22
23
|
{ value: SegmentAggregateCondition, name: SegmentConditionKindEnum.AGGREGATE },
|
|
24
|
+
{ value: SegmentRelationCondition, name: SegmentConditionKindEnum.RELATION },
|
|
23
25
|
],
|
|
24
26
|
},
|
|
25
27
|
})
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Expose, Type } from 'class-transformer';
|
|
2
|
+
import { ArrayMaxSize, Equals, IsArray, IsEnum, IsNumber, IsOptional, Matches, ValidateIf, ValidateNested } from 'class-validator';
|
|
3
|
+
import { RULES_RELATION_NAME_PATTERN } from '../../constants/RulesRelationLimits';
|
|
4
|
+
import { SegmentConditionKindEnum } from '../../enums/SegmentConditionKindEnum';
|
|
5
|
+
import { SegmentOperatorEnum } from '../../enums/SegmentOperatorEnum';
|
|
6
|
+
import { SegmentRelationQuantifierKindEnum } from '../../enums/SegmentRelationQuantifierKindEnum';
|
|
7
|
+
import { SegmentColumnCondition } from './SegmentColumnCondition';
|
|
8
|
+
|
|
9
|
+
/** Cuantificador de una relacion 1:N. COUNT exige `op` y `value`; ANY/ALL no los llevan. */
|
|
10
|
+
export class SegmentRelationQuantifier {
|
|
11
|
+
@Expose() @IsEnum(SegmentRelationQuantifierKindEnum) kind: SegmentRelationQuantifierKindEnum;
|
|
12
|
+
@Expose() @ValidateIf((q: SegmentRelationQuantifier) => q.kind === SegmentRelationQuantifierKindEnum.COUNT || q.op !== undefined)
|
|
13
|
+
@IsEnum(SegmentOperatorEnum) op?: SegmentOperatorEnum;
|
|
14
|
+
@Expose() @ValidateIf((q: SegmentRelationQuantifier) => q.kind === SegmentRelationQuantifierKindEnum.COUNT || q.value !== undefined)
|
|
15
|
+
@IsNumber() value?: number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** (c) Condicion sobre los relacionados de la persona (referidor / referidos). `filters` se aplica a cada relacionado. */
|
|
19
|
+
export class SegmentRelationCondition {
|
|
20
|
+
@Expose() @Equals(SegmentConditionKindEnum.RELATION) kind: SegmentConditionKindEnum.RELATION;
|
|
21
|
+
@Expose() @Matches(RULES_RELATION_NAME_PATTERN) relation: string;
|
|
22
|
+
/** MANY: obligatorio; ONE: ausente (lo valida el compilador, no el DTO). */
|
|
23
|
+
@Expose() @IsOptional() @ValidateNested() @Type(() => SegmentRelationQuantifier) quantifier?: SegmentRelationQuantifier;
|
|
24
|
+
@Expose() @IsArray() @ArrayMaxSize(10) @ValidateNested({ each: true }) @Type(() => SegmentColumnCondition) filters: SegmentColumnCondition[];
|
|
25
|
+
}
|
package/src/rules/index.ts
CHANGED
|
@@ -27,6 +27,7 @@ export * from './dtos/EvaluateRulesResponse';
|
|
|
27
27
|
export * from './enums/SegmentMatchEnum';
|
|
28
28
|
export * from './enums/SegmentOutputEnum';
|
|
29
29
|
export * from './enums/SegmentConditionKindEnum';
|
|
30
|
+
export * from './enums/SegmentRelationQuantifierKindEnum';
|
|
30
31
|
export * from './enums/SegmentAggregateFnEnum';
|
|
31
32
|
export * from './enums/SegmentOperatorEnum';
|
|
32
33
|
export * from './enums/SegmentParamTypeEnum';
|
|
@@ -35,6 +36,7 @@ export * from './constants/SegmentLimits';
|
|
|
35
36
|
export * from './dtos/population/SegmentWindow';
|
|
36
37
|
export * from './dtos/population/SegmentColumnCondition';
|
|
37
38
|
export * from './dtos/population/SegmentAggregateCondition';
|
|
39
|
+
export * from './dtos/population/SegmentRelationCondition';
|
|
38
40
|
export * from './dtos/population/SegmentGroup';
|
|
39
41
|
export * from './dtos/population/PopulationSegmentDefinition';
|
|
40
42
|
export * from './dtos/population/SegmentParam';
|