@fiado/type-kit 3.601.0 → 3.603.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/retailIntegration/retailSaleContracts.test.ts +162 -10
- package/_test_/unit/retailIntegration/retailSystemEnums.test.ts +3 -1
- package/bin/collection/dtos/AuthorizeCollectionMovementRequest.d.ts +7 -0
- package/bin/collection/dtos/AuthorizeCollectionMovementRequest.js +5 -0
- package/bin/retailIntegration/constants/retailIntegrationLimits.d.ts +15 -0
- package/bin/retailIntegration/constants/retailIntegrationLimits.js +16 -1
- package/bin/retailIntegration/dtos/CancelRetailSaleRequest.d.ts +7 -0
- package/bin/retailIntegration/dtos/CancelRetailSaleRequest.js +34 -1
- package/bin/retailIntegration/enums/RetailPaymentFrequencyEnum.d.ts +6 -0
- package/bin/retailIntegration/enums/RetailPaymentFrequencyEnum.js +10 -0
- package/bin/retailIntegration/enums/RetailPaymentMethodEnum.d.ts +3 -2
- package/bin/retailIntegration/enums/RetailPaymentMethodEnum.js +3 -2
- package/bin/retailIntegration/enums/index.d.ts +1 -0
- package/bin/retailIntegration/enums/index.js +1 -0
- package/bin/retailIntegration/index.d.ts +2 -0
- package/bin/retailIntegration/index.js +2 -0
- package/bin/retailIntegration/models/RetailSystemSale.d.ts +23 -2
- package/bin/retailIntegration/models/RetailSystemSale.js +89 -11
- package/bin/retailIntegration/validators/IsCalendarDate.d.ts +6 -0
- package/bin/retailIntegration/validators/IsCalendarDate.js +25 -0
- package/bin/retailIntegration/validators/IsIsoDateTimeWithZone.js +2 -6
- package/bin/retailIntegration/validators/calendarDate.d.ts +2 -0
- package/bin/retailIntegration/validators/calendarDate.js +8 -0
- package/bin/retailIntegration/validators/saleValidators.d.ts +26 -0
- package/bin/retailIntegration/validators/saleValidators.js +100 -0
- package/package.json +1 -1
- package/src/collection/dtos/AuthorizeCollectionMovementRequest.ts +9 -1
- package/src/retailIntegration/constants/retailIntegrationLimits.ts +22 -0
- package/src/retailIntegration/dtos/CancelRetailSaleRequest.ts +14 -2
- package/src/retailIntegration/enums/RetailPaymentFrequencyEnum.ts +6 -0
- package/src/retailIntegration/enums/RetailPaymentMethodEnum.ts +3 -2
- package/src/retailIntegration/enums/index.ts +1 -0
- package/src/retailIntegration/index.ts +2 -0
- package/src/retailIntegration/models/RetailSystemSale.ts +57 -10
- package/src/retailIntegration/validators/IsCalendarDate.ts +16 -0
- package/src/retailIntegration/validators/IsIsoDateTimeWithZone.ts +1 -6
- package/src/retailIntegration/validators/calendarDate.ts +5 -0
- package/src/retailIntegration/validators/saleValidators.ts +80 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { ValidationArguments, ValidatorConstraint, ValidatorConstraintInterface } from 'class-validator';
|
|
2
|
+
import { RETAIL_SALE_DECIMAL_PATTERN, RETAIL_SALE_ID_TEXT_PATTERN, RETAIL_SALE_POSITIVE_DECIMAL_PATTERN } from '../constants/retailIntegrationLimits';
|
|
3
|
+
import { RetailSaleFinancierEnum, RetailSaleLineRoleEnum, RetailSaleTypeEnum } from '../enums';
|
|
4
|
+
|
|
5
|
+
function decimalToCents(value: string): number {
|
|
6
|
+
return Number(value.replace('.', ''));
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Campo de un pago que solo aplica a un medio: con ese medio cumple el patrón; con los demás es `null`. */
|
|
10
|
+
@ValidatorConstraint({ name: 'matchesForPaymentMethod', async: false })
|
|
11
|
+
export class MatchesForPaymentMethod implements ValidatorConstraintInterface {
|
|
12
|
+
validate(value: unknown, args: ValidationArguments): boolean {
|
|
13
|
+
const [method, pattern, nullable] = args.constraints as [string, RegExp, boolean?];
|
|
14
|
+
if ((args.object as { method?: string }).method !== method) return value === null;
|
|
15
|
+
if (value === null) return nullable === true;
|
|
16
|
+
return typeof value === 'string' && pattern.test(value);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
defaultMessage(args: ValidationArguments): string {
|
|
20
|
+
return `${args.property} es obligatorio y válido en ${args.constraints[0]} y null en los demás medios`;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** La suma de `payments[].amount` es `amountPaid`; con `amountPaid` en `"0.00"` el arreglo va vacío. */
|
|
25
|
+
@ValidatorConstraint({ name: 'paymentsMatchAmountPaid', async: false })
|
|
26
|
+
export class PaymentsMatchAmountPaid implements ValidatorConstraintInterface {
|
|
27
|
+
validate(value: unknown, args: ValidationArguments): boolean {
|
|
28
|
+
const amountPaid = (args.object as { amountPaid?: unknown }).amountPaid;
|
|
29
|
+
if (!Array.isArray(value) || typeof amountPaid !== 'string' || !RETAIL_SALE_DECIMAL_PATTERN.test(amountPaid)) return true;
|
|
30
|
+
const amounts = value.map((p) => (p as { amount?: unknown })?.amount);
|
|
31
|
+
if (!amounts.every((a) => typeof a === 'string' && RETAIL_SALE_POSITIVE_DECIMAL_PATTERN.test(a))) return true;
|
|
32
|
+
const total = (amounts as string[]).reduce((sum, a) => sum + decimalToCents(a), 0);
|
|
33
|
+
return total === decimalToCents(amountPaid);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
defaultMessage(): string {
|
|
37
|
+
return 'la suma de payments[].amount debe ser amountPaid; [] solo si amountPaid es 0.00';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** `credit` y `creditId`: obligatorios con `SUREKEEP` y `null` en contado. */
|
|
42
|
+
@ValidatorConstraint({ name: 'creditMatchesFinancier', async: false })
|
|
43
|
+
export class CreditMatchesFinancier implements ValidatorConstraintInterface {
|
|
44
|
+
validate(value: unknown, args: ValidationArguments): boolean {
|
|
45
|
+
const { saleType, credit, creditId } = args.object as { saleType?: unknown; credit?: unknown; creditId?: unknown };
|
|
46
|
+
if (value === RetailSaleFinancierEnum.SUREKEEP) return credit !== null && creditId !== null;
|
|
47
|
+
if (value === RetailSaleFinancierEnum.NONE || saleType === RetailSaleTypeEnum.CASH) return credit == null && creditId == null;
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
defaultMessage(): string {
|
|
52
|
+
return 'credit y creditId son obligatorios con SUREKEEP y null en contado';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** `promotionId`: texto o `null`, nunca omitido; un regalo siempre lo trae. */
|
|
57
|
+
@ValidatorConstraint({ name: 'promotionIdMatchesRole', async: false })
|
|
58
|
+
export class PromotionIdMatchesRole implements ValidatorConstraintInterface {
|
|
59
|
+
validate(value: unknown, args: ValidationArguments): boolean {
|
|
60
|
+
if (value === null) return (args.object as { role?: unknown }).role !== RetailSaleLineRoleEnum.GIFT;
|
|
61
|
+
return typeof value === 'string' && RETAIL_SALE_ID_TEXT_PATTERN.test(value);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
defaultMessage(): string {
|
|
65
|
+
return 'promotionId es texto de 1 a 64 o null, y obligatorio con role GIFT';
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** Un dañado con `identifier` es una sola pieza: `qty` debe ser 1. */
|
|
70
|
+
@ValidatorConstraint({ name: 'qtyMatchesIdentifier', async: false })
|
|
71
|
+
export class QtyMatchesIdentifier implements ValidatorConstraintInterface {
|
|
72
|
+
validate(value: unknown, args: ValidationArguments): boolean {
|
|
73
|
+
const identifier = (args.object as { identifier?: unknown }).identifier;
|
|
74
|
+
return typeof identifier !== 'string' || value === 1;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
defaultMessage(): string {
|
|
78
|
+
return 'qty debe ser 1 cuando viene identifier';
|
|
79
|
+
}
|
|
80
|
+
}
|