@asumano/worklip-typeorm-db 1.1.78 → 1.1.80
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/dist/discount.rules.d.ts +80 -0
- package/dist/discount.rules.js +131 -0
- package/dist/entities/AssociatePermission.d.ts +2 -1
- package/dist/entities/AssociatePermission.js +9 -0
- package/dist/entities/AssociateSection.d.ts +2 -1
- package/dist/entities/AssociateSection.js +9 -0
- package/dist/entities/BillingInvoice.d.ts +1 -0
- package/dist/entities/BillingInvoice.js +10 -0
- package/dist/entities/CompanyDiscount.d.ts +25 -0
- package/dist/entities/CompanyDiscount.js +147 -0
- package/dist/entities/CompanyFeature.d.ts +15 -0
- package/dist/entities/CompanyFeature.js +131 -0
- package/dist/entities/CompanySubscription.d.ts +2 -0
- package/dist/entities/CompanySubscription.js +5 -0
- package/dist/entities/DiscountCode.d.ts +41 -0
- package/dist/entities/DiscountCode.js +203 -0
- package/dist/entities/Feature.d.ts +17 -0
- package/dist/entities/Feature.js +132 -0
- package/dist/entities/GlobalSection.d.ts +17 -0
- package/dist/entities/GlobalSection.js +122 -0
- package/dist/entities/GlobalSectionItem.d.ts +16 -0
- package/dist/entities/{GlobalTemplateSectionItem.js → GlobalSectionItem.js} +47 -28
- package/dist/entities/GlobalTemplate.d.ts +3 -0
- package/dist/entities/GlobalTemplate.js +18 -0
- package/dist/entities/GlobalTemplateSection.d.ts +5 -5
- package/dist/entities/GlobalTemplateSection.js +35 -35
- package/dist/entities/Section.d.ts +19 -0
- package/dist/entities/Section.js +138 -0
- package/dist/entities/SectionItem.d.ts +16 -0
- package/dist/entities/{TemplateSectionItem.js → SectionItem.js} +48 -28
- package/dist/entities/SubscriptionPlan.d.ts +2 -0
- package/dist/entities/SubscriptionPlan.js +16 -0
- package/dist/entities/Template.d.ts +3 -0
- package/dist/entities/Template.js +18 -0
- package/dist/entities/TemplateSection.d.ts +5 -5
- package/dist/entities/TemplateSection.js +48 -34
- package/dist/entities/WhatsappLog.d.ts +3 -1
- package/dist/entities/WhatsappLog.js +23 -2
- package/dist/entities/Workshop.d.ts +2 -0
- package/dist/entities/Workshop.js +5 -0
- package/dist/entities.index.d.ts +12 -6
- package/dist/entities.index.js +30 -14
- package/dist/feature.scope.d.ts +28 -0
- package/dist/feature.scope.js +51 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -0
- package/dist/views/{GlobalTemplateSectionItems.d.ts → GlobalSectionItems.d.ts} +6 -3
- package/dist/views/{TemplateSections.js → GlobalSectionItems.js} +31 -21
- package/dist/views/GlobalSections.d.ts +16 -0
- package/dist/views/{TemplateSectionItems.js → GlobalSections.js} +30 -24
- package/dist/views/GlobalTemplates.d.ts +5 -1
- package/dist/views/GlobalTemplates.js +17 -1
- package/dist/views/{TemplateSectionItems.d.ts → SectionItems.d.ts} +5 -2
- package/dist/views/{GlobalTemplateSectionItems.js → SectionItems.js} +42 -19
- package/dist/views/Sections.d.ts +19 -0
- package/dist/views/{GlobalTemplateSections.js → Sections.js} +48 -17
- package/dist/views/Templates.d.ts +5 -1
- package/dist/views/Templates.js +17 -1
- package/package.json +2 -1
- package/dist/entities/GlobalTemplateSectionItem.d.ts +0 -13
- package/dist/entities/TemplateSectionItem.d.ts +0 -13
- package/dist/views/GlobalTemplateSections.d.ts +0 -12
- package/dist/views/TemplateSections.d.ts +0 -14
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export declare const DISCOUNT_TYPE: {
|
|
2
|
+
readonly PERCENTAGE: 1;
|
|
3
|
+
readonly FIXED: 2;
|
|
4
|
+
};
|
|
5
|
+
export type TDiscountType = (typeof DISCOUNT_TYPE)[keyof typeof DISCOUNT_TYPE];
|
|
6
|
+
export declare const DISCOUNT_DURATION: {
|
|
7
|
+
readonly ONCE: 1;
|
|
8
|
+
readonly CYCLES: 2;
|
|
9
|
+
readonly FOREVER: 3;
|
|
10
|
+
};
|
|
11
|
+
export type TDiscountDuration = (typeof DISCOUNT_DURATION)[keyof typeof DISCOUNT_DURATION];
|
|
12
|
+
export type TDiscountRejection = "NOT_FOUND" | "INACTIVE" | "NOT_STARTED" | "EXPIRED" | "EXHAUSTED" | "ALREADY_REDEEMED" | "NOT_FOR_THIS_COMPANY";
|
|
13
|
+
export interface IDiscountCodeRules {
|
|
14
|
+
status: number;
|
|
15
|
+
valid_from?: Date | string | null;
|
|
16
|
+
valid_until?: Date | string | null;
|
|
17
|
+
max_redemptions?: number | null;
|
|
18
|
+
redemptions_count?: number | null;
|
|
19
|
+
}
|
|
20
|
+
export interface IRedeemContext {
|
|
21
|
+
alreadyRedeemed: boolean;
|
|
22
|
+
allowedCompanies: number[] | null;
|
|
23
|
+
company: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* DOC: ¿Se puede canjear este código, y si no, por qué?
|
|
27
|
+
*
|
|
28
|
+
* Devuelve `null` cuando SÍ se puede. El orden de las comprobaciones importa para el mensaje:
|
|
29
|
+
* primero lo que es del código (apagado, fuera de fecha, agotado) y de últimas lo que es de
|
|
30
|
+
* esta empresa, para no decirle "ya lo usaste" de un código que además está vencido.
|
|
31
|
+
*
|
|
32
|
+
* ⚠️ Esto NO reemplaza la comprobación al canjear. Entre que se valida y se canjea, otro
|
|
33
|
+
* puede llevarse el último cupo: el descuento del contador tiene que ser atómico. Ver el
|
|
34
|
+
* comentario de `redemptions_count` en la entidad.
|
|
35
|
+
*/
|
|
36
|
+
export declare const getDiscountRejection: (code: IDiscountCodeRules | null | undefined, context: IRedeemContext, at?: Date) => TDiscountRejection | null;
|
|
37
|
+
export interface IDiscountableBase {
|
|
38
|
+
plan: number;
|
|
39
|
+
addons: number;
|
|
40
|
+
features: number;
|
|
41
|
+
}
|
|
42
|
+
export interface IDiscountApplication {
|
|
43
|
+
applies_to_plan: number;
|
|
44
|
+
applies_to_addons: number;
|
|
45
|
+
applies_to_features: number;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* DOC: Sobre cuánto se calcula el descuento. Un código de "20% en el plan" no toca los
|
|
49
|
+
* complementos, así que la base no es el total de la factura sino la suma de las partes que
|
|
50
|
+
* el código cubre.
|
|
51
|
+
*/
|
|
52
|
+
export declare const getDiscountableBase: (base: IDiscountableBase, application: IDiscountApplication) => number;
|
|
53
|
+
/**
|
|
54
|
+
* DOC: Cuánto se descuenta, en plata.
|
|
55
|
+
*
|
|
56
|
+
* Dos garantías que no se pueden perder:
|
|
57
|
+
* - NUNCA devuelve más que la base. Un fijo de $50.000 sobre una factura de $30.000
|
|
58
|
+
* descuenta $30.000, no deja la factura en -$20.000 (y Wompi no sabe cobrar negativos).
|
|
59
|
+
* - NUNCA devuelve negativo, aunque el código venga con un valor absurdo.
|
|
60
|
+
*
|
|
61
|
+
* Se redondea a peso entero porque la moneda no tiene centavos y Wompi cobra en centavos de
|
|
62
|
+
* peso: dejar decimales acá hace que el total de la factura y el monto cobrado difieran en 1.
|
|
63
|
+
*/
|
|
64
|
+
export declare const computeDiscountAmount: (discount: {
|
|
65
|
+
type: number;
|
|
66
|
+
value: number;
|
|
67
|
+
}, discountableBase: number) => number;
|
|
68
|
+
/**
|
|
69
|
+
* DOC: ¿Este canje sigue vivo en una fecha dada?
|
|
70
|
+
*
|
|
71
|
+
* Misma convención que las funcionalidades y los complementos: `end_date` nula = sin fin.
|
|
72
|
+
* Para la duración por CICLOS manda el contador, no la fecha: el ciclo puede correrse (un
|
|
73
|
+
* cobro reintentado, un cambio de día de facturación) y contar por fecha regalaría —o
|
|
74
|
+
* quitaría— un mes.
|
|
75
|
+
*/
|
|
76
|
+
export declare const isDiscountRedemptionAliveAt: (redemption: {
|
|
77
|
+
status: number;
|
|
78
|
+
end_date?: Date | string | null;
|
|
79
|
+
cycles_remaining?: number | null;
|
|
80
|
+
}, at?: Date) => boolean;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// DOC: Reglas de los códigos de descuento. Vive acá y no en cada repo porque el número que
|
|
3
|
+
// sale de esto es PLATA, y lo tienen que calcular igual los tres: el panel al simular el
|
|
4
|
+
// código que está creando, el portal al mostrarle al dueño cómo le quedaría la factura, y el
|
|
5
|
+
// API al cobrar de verdad. Si se separaran, la pantalla prometería un precio y el cobro haría
|
|
6
|
+
// otro.
|
|
7
|
+
//
|
|
8
|
+
// Es un módulo PURO: no toca TypeORM ni la base.
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.isDiscountRedemptionAliveAt = exports.computeDiscountAmount = exports.getDiscountableBase = exports.getDiscountRejection = exports.DISCOUNT_DURATION = exports.DISCOUNT_TYPE = void 0;
|
|
11
|
+
// DOC: Qué clase de descuento es. Los números son parte del contrato con la base: no se
|
|
12
|
+
// reordenan ni se reciclan.
|
|
13
|
+
exports.DISCOUNT_TYPE = {
|
|
14
|
+
// DOC: Un porcentaje sobre la base descontable (ej: 20 = 20%).
|
|
15
|
+
PERCENTAGE: 1,
|
|
16
|
+
// DOC: Un monto fijo en la moneda de la empresa (ej: 50000 = $50.000 COP).
|
|
17
|
+
FIXED: 2,
|
|
18
|
+
};
|
|
19
|
+
// DOC: Cuánto dura el descuento DESPUÉS de canjearlo. Es distinto de la vigencia del código
|
|
20
|
+
// (`valid_until`), que dice hasta cuándo se puede CANJEAR: un código que vence en diciembre
|
|
21
|
+
// puede regalar 3 meses de descuento a quien lo canjeó en noviembre.
|
|
22
|
+
exports.DISCOUNT_DURATION = {
|
|
23
|
+
// DOC: Solo la primera factura.
|
|
24
|
+
ONCE: 1,
|
|
25
|
+
// DOC: Un número fijo de ciclos (`duration_cycles`).
|
|
26
|
+
CYCLES: 2,
|
|
27
|
+
// DOC: Mientras la empresa siga suscrita. Es el más caro y el que más se olvida: no tiene
|
|
28
|
+
// fin, así que el descuento sigue aplicándose años después de la campaña.
|
|
29
|
+
FOREVER: 3,
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* DOC: ¿Se puede canjear este código, y si no, por qué?
|
|
33
|
+
*
|
|
34
|
+
* Devuelve `null` cuando SÍ se puede. El orden de las comprobaciones importa para el mensaje:
|
|
35
|
+
* primero lo que es del código (apagado, fuera de fecha, agotado) y de últimas lo que es de
|
|
36
|
+
* esta empresa, para no decirle "ya lo usaste" de un código que además está vencido.
|
|
37
|
+
*
|
|
38
|
+
* ⚠️ Esto NO reemplaza la comprobación al canjear. Entre que se valida y se canjea, otro
|
|
39
|
+
* puede llevarse el último cupo: el descuento del contador tiene que ser atómico. Ver el
|
|
40
|
+
* comentario de `redemptions_count` en la entidad.
|
|
41
|
+
*/
|
|
42
|
+
const getDiscountRejection = (code, context, at = new Date()) => {
|
|
43
|
+
if (!code)
|
|
44
|
+
return "NOT_FOUND";
|
|
45
|
+
if (Number(code.status) !== 1)
|
|
46
|
+
return "INACTIVE";
|
|
47
|
+
if (code.valid_from && new Date(code.valid_from) > at)
|
|
48
|
+
return "NOT_STARTED";
|
|
49
|
+
// DOC: `valid_until` nula = NO vence. Es lo que pidió el negocio: un código sin fecha se
|
|
50
|
+
// canjea indefinidamente hasta que se apague o se agote.
|
|
51
|
+
if (code.valid_until && new Date(code.valid_until) < at)
|
|
52
|
+
return "EXPIRED";
|
|
53
|
+
// DOC: `max_redemptions` nula = canjes ilimitados.
|
|
54
|
+
const max = code.max_redemptions;
|
|
55
|
+
if (max !== null && max !== undefined) {
|
|
56
|
+
if (Number(code.redemptions_count || 0) >= Number(max))
|
|
57
|
+
return "EXHAUSTED";
|
|
58
|
+
}
|
|
59
|
+
if (context.allowedCompanies !== null &&
|
|
60
|
+
!context.allowedCompanies.includes(Number(context.company))) {
|
|
61
|
+
return "NOT_FOR_THIS_COMPANY";
|
|
62
|
+
}
|
|
63
|
+
if (context.alreadyRedeemed)
|
|
64
|
+
return "ALREADY_REDEEMED";
|
|
65
|
+
return null;
|
|
66
|
+
};
|
|
67
|
+
exports.getDiscountRejection = getDiscountRejection;
|
|
68
|
+
/**
|
|
69
|
+
* DOC: Sobre cuánto se calcula el descuento. Un código de "20% en el plan" no toca los
|
|
70
|
+
* complementos, así que la base no es el total de la factura sino la suma de las partes que
|
|
71
|
+
* el código cubre.
|
|
72
|
+
*/
|
|
73
|
+
const getDiscountableBase = (base, application) => {
|
|
74
|
+
let total = 0;
|
|
75
|
+
if (Number(application.applies_to_plan) === 1)
|
|
76
|
+
total += Number(base.plan) || 0;
|
|
77
|
+
if (Number(application.applies_to_addons) === 1)
|
|
78
|
+
total += Number(base.addons) || 0;
|
|
79
|
+
if (Number(application.applies_to_features) === 1) {
|
|
80
|
+
total += Number(base.features) || 0;
|
|
81
|
+
}
|
|
82
|
+
return total > 0 ? total : 0;
|
|
83
|
+
};
|
|
84
|
+
exports.getDiscountableBase = getDiscountableBase;
|
|
85
|
+
/**
|
|
86
|
+
* DOC: Cuánto se descuenta, en plata.
|
|
87
|
+
*
|
|
88
|
+
* Dos garantías que no se pueden perder:
|
|
89
|
+
* - NUNCA devuelve más que la base. Un fijo de $50.000 sobre una factura de $30.000
|
|
90
|
+
* descuenta $30.000, no deja la factura en -$20.000 (y Wompi no sabe cobrar negativos).
|
|
91
|
+
* - NUNCA devuelve negativo, aunque el código venga con un valor absurdo.
|
|
92
|
+
*
|
|
93
|
+
* Se redondea a peso entero porque la moneda no tiene centavos y Wompi cobra en centavos de
|
|
94
|
+
* peso: dejar decimales acá hace que el total de la factura y el monto cobrado difieran en 1.
|
|
95
|
+
*/
|
|
96
|
+
const computeDiscountAmount = (discount, discountableBase) => {
|
|
97
|
+
const base = Number(discountableBase) || 0;
|
|
98
|
+
if (base <= 0)
|
|
99
|
+
return 0;
|
|
100
|
+
const value = Number(discount?.value) || 0;
|
|
101
|
+
if (value <= 0)
|
|
102
|
+
return 0;
|
|
103
|
+
const raw = Number(discount?.type) === exports.DISCOUNT_TYPE.PERCENTAGE
|
|
104
|
+
? (base * Math.min(value, 100)) / 100
|
|
105
|
+
: value;
|
|
106
|
+
const amount = Math.round(raw);
|
|
107
|
+
if (amount <= 0)
|
|
108
|
+
return 0;
|
|
109
|
+
return Math.min(amount, Math.round(base));
|
|
110
|
+
};
|
|
111
|
+
exports.computeDiscountAmount = computeDiscountAmount;
|
|
112
|
+
/**
|
|
113
|
+
* DOC: ¿Este canje sigue vivo en una fecha dada?
|
|
114
|
+
*
|
|
115
|
+
* Misma convención que las funcionalidades y los complementos: `end_date` nula = sin fin.
|
|
116
|
+
* Para la duración por CICLOS manda el contador, no la fecha: el ciclo puede correrse (un
|
|
117
|
+
* cobro reintentado, un cambio de día de facturación) y contar por fecha regalaría —o
|
|
118
|
+
* quitaría— un mes.
|
|
119
|
+
*/
|
|
120
|
+
const isDiscountRedemptionAliveAt = (redemption, at = new Date()) => {
|
|
121
|
+
if (Number(redemption.status) !== 1)
|
|
122
|
+
return false;
|
|
123
|
+
if (redemption.end_date && new Date(redemption.end_date) <= at)
|
|
124
|
+
return false;
|
|
125
|
+
const remaining = redemption.cycles_remaining;
|
|
126
|
+
if (remaining !== null && remaining !== undefined && Number(remaining) <= 0) {
|
|
127
|
+
return false;
|
|
128
|
+
}
|
|
129
|
+
return true;
|
|
130
|
+
};
|
|
131
|
+
exports.isDiscountRedemptionAliveAt = isDiscountRedemptionAliveAt;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Associate, AssociateRole, AssociateSection } from "../entities.views.routes";
|
|
1
|
+
import { Associate, AssociateRole, AssociateSection, Feature } from "../entities.views.routes";
|
|
2
2
|
export declare class AssociatePermission {
|
|
3
3
|
id: number;
|
|
4
4
|
section: AssociateSection;
|
|
@@ -8,5 +8,6 @@ export declare class AssociatePermission {
|
|
|
8
8
|
icon: string;
|
|
9
9
|
status: number;
|
|
10
10
|
roles: AssociateRole[];
|
|
11
|
+
feature: Feature | null;
|
|
11
12
|
associates: Associate[];
|
|
12
13
|
}
|
|
@@ -85,6 +85,15 @@ __decorate([
|
|
|
85
85
|
,
|
|
86
86
|
__metadata("design:type", Array)
|
|
87
87
|
], AssociatePermission.prototype, "roles", void 0);
|
|
88
|
+
__decorate([
|
|
89
|
+
(0, typeorm_1.ManyToOne)(() => entities_views_routes_1.Feature, (feature) => feature.permissions, {
|
|
90
|
+
onDelete: "SET NULL",
|
|
91
|
+
onUpdate: "NO ACTION",
|
|
92
|
+
nullable: true,
|
|
93
|
+
}),
|
|
94
|
+
(0, typeorm_1.JoinColumn)({ name: "feature" }),
|
|
95
|
+
__metadata("design:type", Object)
|
|
96
|
+
], AssociatePermission.prototype, "feature", void 0);
|
|
88
97
|
__decorate([
|
|
89
98
|
(0, typeorm_1.ManyToMany)(() => entities_views_routes_1.Associate, (associate) => associate.permissions),
|
|
90
99
|
__metadata("design:type", Array)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AssociatePermission, AssociatePlatform } from "../entities.views.routes";
|
|
1
|
+
import { AssociatePermission, AssociatePlatform, Feature } from "../entities.views.routes";
|
|
2
2
|
export declare class AssociateSection {
|
|
3
3
|
id: number;
|
|
4
4
|
name: string;
|
|
@@ -6,5 +6,6 @@ export declare class AssociateSection {
|
|
|
6
6
|
icon: string;
|
|
7
7
|
status: number;
|
|
8
8
|
platforms: AssociatePlatform[];
|
|
9
|
+
feature: Feature | null;
|
|
9
10
|
permissions: AssociatePermission[];
|
|
10
11
|
}
|
|
@@ -58,6 +58,15 @@ __decorate([
|
|
|
58
58
|
}),
|
|
59
59
|
__metadata("design:type", Array)
|
|
60
60
|
], AssociateSection.prototype, "platforms", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, typeorm_1.ManyToOne)(() => entities_views_routes_1.Feature, (feature) => feature.sections, {
|
|
63
|
+
onDelete: "SET NULL",
|
|
64
|
+
onUpdate: "NO ACTION",
|
|
65
|
+
nullable: true,
|
|
66
|
+
}),
|
|
67
|
+
(0, typeorm_1.JoinColumn)({ name: "feature" }),
|
|
68
|
+
__metadata("design:type", Object)
|
|
69
|
+
], AssociateSection.prototype, "feature", void 0);
|
|
61
70
|
__decorate([
|
|
62
71
|
(0, typeorm_1.OneToMany)(() => entities_views_routes_1.AssociatePermission, (permission) => permission.section),
|
|
63
72
|
__metadata("design:type", Array)
|
|
@@ -85,6 +85,16 @@ __decorate([
|
|
|
85
85
|
}),
|
|
86
86
|
__metadata("design:type", Number)
|
|
87
87
|
], BillingInvoice.prototype, "subtotal", void 0);
|
|
88
|
+
__decorate([
|
|
89
|
+
(0, typeorm_1.Column)({
|
|
90
|
+
type: "decimal",
|
|
91
|
+
precision: 14,
|
|
92
|
+
scale: 2,
|
|
93
|
+
default: 0,
|
|
94
|
+
comment: "Descuento aplicado sobre el subtotal.",
|
|
95
|
+
}),
|
|
96
|
+
__metadata("design:type", Number)
|
|
97
|
+
], BillingInvoice.prototype, "discount", void 0);
|
|
88
98
|
__decorate([
|
|
89
99
|
(0, typeorm_1.Column)({
|
|
90
100
|
type: "decimal",
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Company, DiscountCode } from "../entities.views.routes";
|
|
2
|
+
export declare class CompanyDiscount {
|
|
3
|
+
id: number;
|
|
4
|
+
discount_code: DiscountCode;
|
|
5
|
+
company: Company;
|
|
6
|
+
type: number;
|
|
7
|
+
value: number;
|
|
8
|
+
applies_to_plan: number;
|
|
9
|
+
applies_to_addons: number;
|
|
10
|
+
applies_to_features: number;
|
|
11
|
+
start_date: string;
|
|
12
|
+
end_date: string | null;
|
|
13
|
+
/**
|
|
14
|
+
* DOC: Ciclos que le quedan al descuento. NULL = no se cuenta por ciclos (duración "solo
|
|
15
|
+
* la primera factura" —que se resuelve poniendo 1— o "mientras siga suscrita").
|
|
16
|
+
*
|
|
17
|
+
* Manda el CONTADOR y no la fecha: el ciclo se puede correr (un cobro reintentado, un
|
|
18
|
+
* cambio del día de facturación) y contar por fecha regalaría o quitaría un mes. El job
|
|
19
|
+
* mensual lo baja en uno cada vez que emite una factura con el descuento aplicado.
|
|
20
|
+
*/
|
|
21
|
+
cycles_remaining: number | null;
|
|
22
|
+
status: number;
|
|
23
|
+
created: Date;
|
|
24
|
+
updated: Date | null;
|
|
25
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
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.CompanyDiscount = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
const entities_views_routes_1 = require("../entities.views.routes");
|
|
15
|
+
// DOC: Canje de un código por parte de una empresa. Una fila = "esta empresa usó este
|
|
16
|
+
// código", y es la que el cobro mensual consulta para saber cuánto descontar.
|
|
17
|
+
//
|
|
18
|
+
// El UNIQUE (código, empresa) es lo que impide reusarlo: una empresa no lo puede canjear dos
|
|
19
|
+
// veces, ni siquiera después de que se le acabe. Acá SÍ funciona como cerrojo —a diferencia
|
|
20
|
+
// de `company_feature`— porque ninguna de las dos columnas es anulable.
|
|
21
|
+
let CompanyDiscount = class CompanyDiscount {
|
|
22
|
+
};
|
|
23
|
+
exports.CompanyDiscount = CompanyDiscount;
|
|
24
|
+
__decorate([
|
|
25
|
+
(0, typeorm_1.PrimaryGeneratedColumn)({
|
|
26
|
+
type: "int",
|
|
27
|
+
comment: "Número de identificación (ID) único de cada registro.",
|
|
28
|
+
}),
|
|
29
|
+
__metadata("design:type", Number)
|
|
30
|
+
], CompanyDiscount.prototype, "id", void 0);
|
|
31
|
+
__decorate([
|
|
32
|
+
(0, typeorm_1.ManyToOne)(() => entities_views_routes_1.DiscountCode, (discountCode) => discountCode.redemptions, {
|
|
33
|
+
onDelete: "RESTRICT",
|
|
34
|
+
onUpdate: "NO ACTION",
|
|
35
|
+
}),
|
|
36
|
+
(0, typeorm_1.JoinColumn)({ name: "discount_code" }),
|
|
37
|
+
__metadata("design:type", entities_views_routes_1.DiscountCode)
|
|
38
|
+
], CompanyDiscount.prototype, "discount_code", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, typeorm_1.ManyToOne)(() => entities_views_routes_1.Company, { onDelete: "CASCADE", onUpdate: "NO ACTION" }),
|
|
41
|
+
(0, typeorm_1.JoinColumn)({ name: "company" }),
|
|
42
|
+
__metadata("design:type", entities_views_routes_1.Company)
|
|
43
|
+
], CompanyDiscount.prototype, "company", void 0);
|
|
44
|
+
__decorate([
|
|
45
|
+
(0, typeorm_1.Column)({
|
|
46
|
+
type: "int",
|
|
47
|
+
comment: "Tipo de descuento congelado al canjear:\r\n1. Porcentaje.\r\n2. Monto fijo.",
|
|
48
|
+
}),
|
|
49
|
+
__metadata("design:type", Number)
|
|
50
|
+
], CompanyDiscount.prototype, "type", void 0);
|
|
51
|
+
__decorate([
|
|
52
|
+
(0, typeorm_1.Column)({
|
|
53
|
+
type: "decimal",
|
|
54
|
+
precision: 14,
|
|
55
|
+
scale: 2,
|
|
56
|
+
comment: "Valor del descuento congelado al canjear.",
|
|
57
|
+
}),
|
|
58
|
+
__metadata("design:type", Number)
|
|
59
|
+
], CompanyDiscount.prototype, "value", void 0);
|
|
60
|
+
__decorate([
|
|
61
|
+
(0, typeorm_1.Column)({
|
|
62
|
+
default: 1,
|
|
63
|
+
type: "int",
|
|
64
|
+
width: 1,
|
|
65
|
+
comment: "¿Aplica al precio del plan?\r\n1: Sí.\r\n0: No.",
|
|
66
|
+
}),
|
|
67
|
+
__metadata("design:type", Number)
|
|
68
|
+
], CompanyDiscount.prototype, "applies_to_plan", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
(0, typeorm_1.Column)({
|
|
71
|
+
default: 0,
|
|
72
|
+
type: "int",
|
|
73
|
+
width: 1,
|
|
74
|
+
comment: "¿Aplica a los complementos?\r\n1: Sí.\r\n0: No.",
|
|
75
|
+
}),
|
|
76
|
+
__metadata("design:type", Number)
|
|
77
|
+
], CompanyDiscount.prototype, "applies_to_addons", void 0);
|
|
78
|
+
__decorate([
|
|
79
|
+
(0, typeorm_1.Column)({
|
|
80
|
+
default: 0,
|
|
81
|
+
type: "int",
|
|
82
|
+
width: 1,
|
|
83
|
+
comment: "¿Aplica a las funcionalidades?\r\n1: Sí.\r\n0: No.",
|
|
84
|
+
}),
|
|
85
|
+
__metadata("design:type", Number)
|
|
86
|
+
], CompanyDiscount.prototype, "applies_to_features", void 0);
|
|
87
|
+
__decorate([
|
|
88
|
+
(0, typeorm_1.Column)({
|
|
89
|
+
type: "date",
|
|
90
|
+
comment: "Fecha en que se canjeó y desde la que aplica.",
|
|
91
|
+
}),
|
|
92
|
+
__metadata("design:type", String)
|
|
93
|
+
], CompanyDiscount.prototype, "start_date", void 0);
|
|
94
|
+
__decorate([
|
|
95
|
+
(0, typeorm_1.Column)({
|
|
96
|
+
type: "date",
|
|
97
|
+
nullable: true,
|
|
98
|
+
default: null,
|
|
99
|
+
comment: "Fecha en que deja de aplicar el descuento. NULL significa que no termina.",
|
|
100
|
+
}),
|
|
101
|
+
__metadata("design:type", Object)
|
|
102
|
+
], CompanyDiscount.prototype, "end_date", void 0);
|
|
103
|
+
__decorate([
|
|
104
|
+
(0, typeorm_1.Column)({
|
|
105
|
+
type: "int",
|
|
106
|
+
nullable: true,
|
|
107
|
+
default: null,
|
|
108
|
+
comment: "Ciclos que le quedan al descuento. NULL significa que no se cuenta por ciclos.",
|
|
109
|
+
}),
|
|
110
|
+
__metadata("design:type", Object)
|
|
111
|
+
], CompanyDiscount.prototype, "cycles_remaining", void 0);
|
|
112
|
+
__decorate([
|
|
113
|
+
(0, typeorm_1.Column)({
|
|
114
|
+
default: 1,
|
|
115
|
+
type: "int",
|
|
116
|
+
width: 1,
|
|
117
|
+
comment: "Estado del canje.\r\n1: Activo.\r\n0: Terminado o anulado.",
|
|
118
|
+
}),
|
|
119
|
+
__metadata("design:type", Number)
|
|
120
|
+
], CompanyDiscount.prototype, "status", void 0);
|
|
121
|
+
__decorate([
|
|
122
|
+
(0, typeorm_1.Column)({
|
|
123
|
+
type: "datetime",
|
|
124
|
+
comment: "Fecha de creación del registro.",
|
|
125
|
+
default: () => "CURRENT_TIMESTAMP",
|
|
126
|
+
}),
|
|
127
|
+
__metadata("design:type", Date)
|
|
128
|
+
], CompanyDiscount.prototype, "created", void 0);
|
|
129
|
+
__decorate([
|
|
130
|
+
(0, typeorm_1.Column)({
|
|
131
|
+
type: "datetime",
|
|
132
|
+
default: null,
|
|
133
|
+
nullable: true,
|
|
134
|
+
comment: "Fecha de actualización del registro.",
|
|
135
|
+
onUpdate: "CURRENT_TIMESTAMP",
|
|
136
|
+
}),
|
|
137
|
+
__metadata("design:type", Object)
|
|
138
|
+
], CompanyDiscount.prototype, "updated", void 0);
|
|
139
|
+
exports.CompanyDiscount = CompanyDiscount = __decorate([
|
|
140
|
+
(0, typeorm_1.Index)("UQ_company_discount_once", ["discount_code", "company"], {
|
|
141
|
+
unique: true,
|
|
142
|
+
}),
|
|
143
|
+
(0, typeorm_1.Entity)({
|
|
144
|
+
comment: "Códigos de descuento canjeados por las empresas.",
|
|
145
|
+
name: "company_discount",
|
|
146
|
+
})
|
|
147
|
+
], CompanyDiscount);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { CompanySubscription, Feature, Workshop } from "../entities.views.routes";
|
|
2
|
+
export declare class CompanyFeature {
|
|
3
|
+
id: number;
|
|
4
|
+
company_subscription: CompanySubscription;
|
|
5
|
+
feature: Feature;
|
|
6
|
+
workshop: Workshop | null;
|
|
7
|
+
settings: Record<string, any> | null;
|
|
8
|
+
origin: number;
|
|
9
|
+
monthly_price: number;
|
|
10
|
+
start_date: string;
|
|
11
|
+
end_date: string | null;
|
|
12
|
+
status: number;
|
|
13
|
+
created: Date;
|
|
14
|
+
updated: Date | null;
|
|
15
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
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.CompanyFeature = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
const entities_views_routes_1 = require("../entities.views.routes");
|
|
15
|
+
// DOC: Funcionalidades que una empresa tiene CONTRATADAS. Cuelga de `company_subscription`
|
|
16
|
+
// igual que `subscription_addon`, para que el cobro mensual las encuentre por el mismo lado.
|
|
17
|
+
//
|
|
18
|
+
// ⚠️ NO lleva UNIQUE sobre (suscripción, funcionalidad, taller) y no es un olvido: MySQL
|
|
19
|
+
// permite varios NULL en un índice único, así que no frenaría las concesiones de empresa
|
|
20
|
+
// duplicadas —justo el caso que habría que frenar—, y además las filas vencidas se
|
|
21
|
+
// conservan para el historial de facturación, así que el trío se repite a propósito. La
|
|
22
|
+
// comprobación de "ya tiene una viva" va en el modelo, como `findAssociateConflictModel`.
|
|
23
|
+
let CompanyFeature = class CompanyFeature {
|
|
24
|
+
};
|
|
25
|
+
exports.CompanyFeature = CompanyFeature;
|
|
26
|
+
__decorate([
|
|
27
|
+
(0, typeorm_1.PrimaryGeneratedColumn)({
|
|
28
|
+
type: "int",
|
|
29
|
+
comment: "Número de identificación (ID) único de cada registro.",
|
|
30
|
+
}),
|
|
31
|
+
__metadata("design:type", Number)
|
|
32
|
+
], CompanyFeature.prototype, "id", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, typeorm_1.ManyToOne)(() => entities_views_routes_1.CompanySubscription, (companySubscription) => companySubscription.company_features, { onDelete: "CASCADE", onUpdate: "NO ACTION" }),
|
|
35
|
+
(0, typeorm_1.JoinColumn)({ name: "company_subscription" }),
|
|
36
|
+
__metadata("design:type", entities_views_routes_1.CompanySubscription)
|
|
37
|
+
], CompanyFeature.prototype, "company_subscription", void 0);
|
|
38
|
+
__decorate([
|
|
39
|
+
(0, typeorm_1.ManyToOne)(() => entities_views_routes_1.Feature, (feature) => feature.company_features, {
|
|
40
|
+
onDelete: "RESTRICT",
|
|
41
|
+
onUpdate: "NO ACTION",
|
|
42
|
+
}),
|
|
43
|
+
(0, typeorm_1.JoinColumn)({ name: "feature" }),
|
|
44
|
+
__metadata("design:type", entities_views_routes_1.Feature)
|
|
45
|
+
], CompanyFeature.prototype, "feature", void 0);
|
|
46
|
+
__decorate([
|
|
47
|
+
(0, typeorm_1.ManyToOne)(() => entities_views_routes_1.Workshop, {
|
|
48
|
+
onDelete: "CASCADE",
|
|
49
|
+
onUpdate: "NO ACTION",
|
|
50
|
+
nullable: true,
|
|
51
|
+
}),
|
|
52
|
+
(0, typeorm_1.JoinColumn)({ name: "workshop" }),
|
|
53
|
+
__metadata("design:type", Object)
|
|
54
|
+
], CompanyFeature.prototype, "workshop", void 0);
|
|
55
|
+
__decorate([
|
|
56
|
+
(0, typeorm_1.Column)({
|
|
57
|
+
type: "json",
|
|
58
|
+
nullable: true,
|
|
59
|
+
default: null,
|
|
60
|
+
comment: "Campo de tipo JSON con la configuración propia de esta funcionalidad contratada.",
|
|
61
|
+
}),
|
|
62
|
+
__metadata("design:type", Object)
|
|
63
|
+
], CompanyFeature.prototype, "settings", void 0);
|
|
64
|
+
__decorate([
|
|
65
|
+
(0, typeorm_1.Column)({
|
|
66
|
+
default: 1,
|
|
67
|
+
type: "int",
|
|
68
|
+
width: 1,
|
|
69
|
+
comment: "Origen de la concesión:\r\n1: Comprada (se factura).\r\n2: Cortesía o prueba (no se factura).",
|
|
70
|
+
}),
|
|
71
|
+
__metadata("design:type", Number)
|
|
72
|
+
], CompanyFeature.prototype, "origin", void 0);
|
|
73
|
+
__decorate([
|
|
74
|
+
(0, typeorm_1.Column)({
|
|
75
|
+
type: "decimal",
|
|
76
|
+
precision: 14,
|
|
77
|
+
scale: 2,
|
|
78
|
+
comment: "Valor mensual que se cobra por esta funcionalidad.",
|
|
79
|
+
}),
|
|
80
|
+
__metadata("design:type", Number)
|
|
81
|
+
], CompanyFeature.prototype, "monthly_price", void 0);
|
|
82
|
+
__decorate([
|
|
83
|
+
(0, typeorm_1.Column)({
|
|
84
|
+
type: "date",
|
|
85
|
+
comment: "Fecha desde la que se empieza a cobrar la funcionalidad.",
|
|
86
|
+
}),
|
|
87
|
+
__metadata("design:type", String)
|
|
88
|
+
], CompanyFeature.prototype, "start_date", void 0);
|
|
89
|
+
__decorate([
|
|
90
|
+
(0, typeorm_1.Column)({
|
|
91
|
+
type: "date",
|
|
92
|
+
nullable: true,
|
|
93
|
+
default: null,
|
|
94
|
+
comment: "Fecha en que deja de cobrarse la funcionalidad. NULL significa que sigue activa.",
|
|
95
|
+
}),
|
|
96
|
+
__metadata("design:type", Object)
|
|
97
|
+
], CompanyFeature.prototype, "end_date", void 0);
|
|
98
|
+
__decorate([
|
|
99
|
+
(0, typeorm_1.Column)({
|
|
100
|
+
default: 2,
|
|
101
|
+
type: "int",
|
|
102
|
+
width: 1,
|
|
103
|
+
comment: "Estado de la concesión:\r\n1: Activa.\r\n2: Pendiente de pago.\r\n0: Anulada.",
|
|
104
|
+
}),
|
|
105
|
+
__metadata("design:type", Number)
|
|
106
|
+
], CompanyFeature.prototype, "status", void 0);
|
|
107
|
+
__decorate([
|
|
108
|
+
(0, typeorm_1.Column)({
|
|
109
|
+
type: "datetime",
|
|
110
|
+
comment: "Fecha de creación del registro.",
|
|
111
|
+
default: () => "CURRENT_TIMESTAMP",
|
|
112
|
+
}),
|
|
113
|
+
__metadata("design:type", Date)
|
|
114
|
+
], CompanyFeature.prototype, "created", void 0);
|
|
115
|
+
__decorate([
|
|
116
|
+
(0, typeorm_1.Column)({
|
|
117
|
+
type: "datetime",
|
|
118
|
+
default: null,
|
|
119
|
+
nullable: true,
|
|
120
|
+
comment: "Fecha de actualización del registro.",
|
|
121
|
+
onUpdate: "CURRENT_TIMESTAMP",
|
|
122
|
+
}),
|
|
123
|
+
__metadata("design:type", Object)
|
|
124
|
+
], CompanyFeature.prototype, "updated", void 0);
|
|
125
|
+
exports.CompanyFeature = CompanyFeature = __decorate([
|
|
126
|
+
(0, typeorm_1.Index)("IDX_company_feature_lookup", ["company_subscription", "feature"]),
|
|
127
|
+
(0, typeorm_1.Entity)({
|
|
128
|
+
comment: "Funcionalidades contratadas por la empresa.",
|
|
129
|
+
name: "company_feature",
|
|
130
|
+
})
|
|
131
|
+
], CompanyFeature);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Company } from "./Company";
|
|
2
2
|
import { SubscriptionPlan } from "./SubscriptionPlan";
|
|
3
3
|
import { SubscriptionAddon } from "./SubscriptionAddon";
|
|
4
|
+
import { CompanyFeature } from "./CompanyFeature";
|
|
4
5
|
import { BillingInvoice } from "./BillingInvoice";
|
|
5
6
|
export declare class CompanySubscription {
|
|
6
7
|
id: number;
|
|
@@ -17,4 +18,5 @@ export declare class CompanySubscription {
|
|
|
17
18
|
updated: Date | null;
|
|
18
19
|
subscription_addons: SubscriptionAddon[];
|
|
19
20
|
billing_invoices: BillingInvoice[];
|
|
21
|
+
company_features: CompanyFeature[];
|
|
20
22
|
}
|
|
@@ -14,6 +14,7 @@ const typeorm_1 = require("typeorm");
|
|
|
14
14
|
const Company_1 = require("./Company");
|
|
15
15
|
const SubscriptionPlan_1 = require("./SubscriptionPlan");
|
|
16
16
|
const SubscriptionAddon_1 = require("./SubscriptionAddon");
|
|
17
|
+
const CompanyFeature_1 = require("./CompanyFeature");
|
|
17
18
|
const BillingInvoice_1 = require("./BillingInvoice");
|
|
18
19
|
let CompanySubscription = class CompanySubscription {
|
|
19
20
|
};
|
|
@@ -129,6 +130,10 @@ __decorate([
|
|
|
129
130
|
(0, typeorm_1.OneToMany)(() => BillingInvoice_1.BillingInvoice, (billingInvoice) => billingInvoice.company_subscription),
|
|
130
131
|
__metadata("design:type", Array)
|
|
131
132
|
], CompanySubscription.prototype, "billing_invoices", void 0);
|
|
133
|
+
__decorate([
|
|
134
|
+
(0, typeorm_1.OneToMany)(() => CompanyFeature_1.CompanyFeature, (companyFeature) => companyFeature.company_subscription),
|
|
135
|
+
__metadata("design:type", Array)
|
|
136
|
+
], CompanySubscription.prototype, "company_features", void 0);
|
|
132
137
|
exports.CompanySubscription = CompanySubscription = __decorate([
|
|
133
138
|
(0, typeorm_1.Entity)({ comment: "Plan de la empresa.", name: "company_subscription" }),
|
|
134
139
|
(0, typeorm_1.Index)("IDX_company_subscription_company", ["company"])
|