@asumano/worklip-typeorm-db 1.1.64 → 1.1.66
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/index.js +57 -20
- package/dist/visit.summary.d.ts +30 -1
- package/dist/visit.summary.js +9 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -52,6 +52,31 @@ __exportStar(require("./entities.views.routes"), exports);
|
|
|
52
52
|
// (al guardar), y tiene que ser la MISMA implementación en los dos.
|
|
53
53
|
__exportStar(require("./visit.summary"), exports);
|
|
54
54
|
let connection = null;
|
|
55
|
+
// DOC: Inicialización en curso. Se memoriza la PROMESA y no el resultado porque el patrón
|
|
56
|
+
// "si no está inicializada, inicialízala" tiene una carrera en el arranque en frío: dos
|
|
57
|
+
// peticiones simultáneas entran las dos y llaman `initialize()` sobre la misma instancia,
|
|
58
|
+
// y la segunda revienta o deja el pool a medias. Guardando la promesa, la segunda espera a
|
|
59
|
+
// la primera.
|
|
60
|
+
let initializing = null;
|
|
61
|
+
const ensureInitialized = async () => {
|
|
62
|
+
if (connection?.isInitialized)
|
|
63
|
+
return connection;
|
|
64
|
+
if (!initializing) {
|
|
65
|
+
const ds = createDataBaseSource();
|
|
66
|
+
initializing = ds
|
|
67
|
+
.initialize()
|
|
68
|
+
.then((initialized) => {
|
|
69
|
+
connection = initialized;
|
|
70
|
+
return initialized;
|
|
71
|
+
})
|
|
72
|
+
.finally(() => {
|
|
73
|
+
// DOC: Se suelta al terminar (bien o mal). Si falló, el siguiente intento vuelve a
|
|
74
|
+
// probar en vez de quedarse pegado a una promesa rechazada para siempre.
|
|
75
|
+
initializing = null;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
return await initializing;
|
|
79
|
+
};
|
|
55
80
|
// DOC: Función para crear la conexión de la base de datos.
|
|
56
81
|
function createDataBaseSource() {
|
|
57
82
|
if (!connection) {
|
|
@@ -65,8 +90,22 @@ function createDataBaseSource() {
|
|
|
65
90
|
username: process.env.DB_USERNAME,
|
|
66
91
|
password: process.env.DB_PASSWORD ?? "",
|
|
67
92
|
database: process.env.DB_DATABASE,
|
|
68
|
-
|
|
93
|
+
// DOC: Deja que TypeORM ALTERE el esquema para que coincida con las entidades. Es
|
|
94
|
+
// útil en desarrollo y catastrófico en producción: puede borrar columnas y tablas que
|
|
95
|
+
// no estén declaradas. Se exige que la variable diga "true" Y que NO se esté en
|
|
96
|
+
// producción, para que un .env copiado por error no reescriba la base.
|
|
97
|
+
synchronize: process.env.DB_SYNCHRONIZE === "true" &&
|
|
98
|
+
process.env.NODE_ENV !== "production",
|
|
69
99
|
timezone: "Z", // Configura la zona horaria a UTC
|
|
100
|
+
// DOC: Tamaño del pool de mysql2. Sin declararlo son 10 conexiones, y de ese pool
|
|
101
|
+
// comen a la vez el API, el worker de videos y los jobs programados: en una hora
|
|
102
|
+
// cargada las peticiones empiezan a esperar turno sin que nada lo diga.
|
|
103
|
+
//
|
|
104
|
+
// Se configura por entorno porque el número correcto depende del `max_connections` del
|
|
105
|
+
// MySQL de cada despliegue, no del código.
|
|
106
|
+
extra: {
|
|
107
|
+
connectionLimit: Number(process.env.DB_POOL_SIZE || 10),
|
|
108
|
+
},
|
|
70
109
|
entities: Object.values(EntitiesViewsRoutes),
|
|
71
110
|
// entities: [
|
|
72
111
|
// __dirname +
|
|
@@ -89,19 +128,24 @@ function createDataBaseSource() {
|
|
|
89
128
|
return connection;
|
|
90
129
|
}
|
|
91
130
|
async function showEntityName(entity) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
await connection.initialize();
|
|
95
|
-
}
|
|
96
|
-
return connection.getRepository(entity);
|
|
131
|
+
const ds = await ensureInitialized();
|
|
132
|
+
return ds.getRepository(entity);
|
|
97
133
|
}
|
|
134
|
+
// DOC: El NOMBRE del procedimiento se interpola en el SQL (no existe `CALL ?`), así que es
|
|
135
|
+
// el único punto de esta función donde alguien podría escribir SQL. Hoy no la llama nadie
|
|
136
|
+
// —el único uso está comentado—, pero está exportada y espera a que alguien la use con algo
|
|
137
|
+
// que venga de una petición.
|
|
138
|
+
//
|
|
139
|
+
// Se limita a un identificador de MySQL: letras, números y guion bajo. Cualquier otra cosa
|
|
140
|
+
// se rechaza ANTES de armar la consulta.
|
|
141
|
+
const STORED_PROCEDURE_PATTERN = /^[A-Za-z0-9_]{1,64}$/;
|
|
98
142
|
async function callStoredProcedureName(storedProcedure, elements) {
|
|
99
143
|
try {
|
|
100
|
-
if (!
|
|
101
|
-
|
|
102
|
-
await connection.initialize();
|
|
144
|
+
if (!STORED_PROCEDURE_PATTERN.test(String(storedProcedure ?? ""))) {
|
|
145
|
+
throw new Error(`Nombre de procedimiento almacenado inválido: ${storedProcedure}`);
|
|
103
146
|
}
|
|
104
|
-
const
|
|
147
|
+
const ds = await ensureInitialized();
|
|
148
|
+
const result = await ds.query(`CALL ${storedProcedure}`, elements);
|
|
105
149
|
return result;
|
|
106
150
|
}
|
|
107
151
|
catch (error) {
|
|
@@ -109,22 +153,15 @@ async function callStoredProcedureName(storedProcedure, elements) {
|
|
|
109
153
|
}
|
|
110
154
|
}
|
|
111
155
|
async function getDataSource() {
|
|
112
|
-
|
|
113
|
-
connection = createDataBaseSource();
|
|
114
|
-
await connection.initialize();
|
|
115
|
-
}
|
|
116
|
-
return connection;
|
|
156
|
+
return await ensureInitialized();
|
|
117
157
|
}
|
|
118
158
|
async function executeQuery(query, params = []) {
|
|
119
159
|
const ds = await getDataSource();
|
|
120
160
|
return ds.query(query, params);
|
|
121
161
|
}
|
|
122
162
|
const getRepositoryByEntity = async (entity) => {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
await connection.initialize();
|
|
126
|
-
}
|
|
127
|
-
return connection.getRepository(entity).extend({
|
|
163
|
+
const ds = await ensureInitialized();
|
|
164
|
+
return ds.getRepository(entity).extend({
|
|
128
165
|
async getAssociatesForTheTableWrapper(params) {
|
|
129
166
|
return (0, entities_views_routes_1.getAssociatesForTheTable)(this, params);
|
|
130
167
|
},
|
package/dist/visit.summary.d.ts
CHANGED
|
@@ -18,6 +18,14 @@ export interface IVisitEvidence {
|
|
|
18
18
|
visible: boolean;
|
|
19
19
|
createdAt: number;
|
|
20
20
|
capturedAt?: number | null;
|
|
21
|
+
purged?: boolean;
|
|
22
|
+
purged_at?: string;
|
|
23
|
+
}
|
|
24
|
+
export type TReminderApproval = "PENDING" | "APPROVED" | "REJECTED";
|
|
25
|
+
export interface IVisitItemReminder {
|
|
26
|
+
approval: TReminderApproval;
|
|
27
|
+
responded_at?: number | null;
|
|
28
|
+
reminder_id?: number | null;
|
|
21
29
|
}
|
|
22
30
|
export interface IVisitItem {
|
|
23
31
|
id: string;
|
|
@@ -29,6 +37,7 @@ export interface IVisitItem {
|
|
|
29
37
|
status: TItemStatus;
|
|
30
38
|
comments: string;
|
|
31
39
|
appointment_reminder?: string | Date | null;
|
|
40
|
+
reminder?: IVisitItemReminder | null;
|
|
32
41
|
costs: IVisitCosts | null;
|
|
33
42
|
evidence: IVisitEvidence[];
|
|
34
43
|
order: number;
|
|
@@ -40,10 +49,30 @@ export interface IVisitSection {
|
|
|
40
49
|
items: IVisitItem[];
|
|
41
50
|
custom_section?: boolean;
|
|
42
51
|
}
|
|
52
|
+
export interface IVisitSignature {
|
|
53
|
+
image: string;
|
|
54
|
+
signed_at: string;
|
|
55
|
+
name: string;
|
|
56
|
+
document: string;
|
|
57
|
+
source?: "workshop" | "report";
|
|
58
|
+
}
|
|
59
|
+
export interface IVisitSignatures {
|
|
60
|
+
mechanic?: IVisitSignature | null;
|
|
61
|
+
client?: IVisitSignature | null;
|
|
62
|
+
}
|
|
63
|
+
export interface IVisitPdf {
|
|
64
|
+
key: string;
|
|
65
|
+
generated_at?: string;
|
|
66
|
+
size_bytes?: number;
|
|
67
|
+
images?: number;
|
|
68
|
+
archived_at?: string;
|
|
69
|
+
}
|
|
43
70
|
export interface IVisitData {
|
|
44
71
|
sections: IVisitSection[];
|
|
45
72
|
summary?: IVisitSummary;
|
|
46
73
|
service_tax_mode?: TTaxMode;
|
|
74
|
+
signatures?: IVisitSignatures;
|
|
75
|
+
pdf?: IVisitPdf;
|
|
47
76
|
}
|
|
48
77
|
export interface IVisitQuotationSummary {
|
|
49
78
|
servicePrice: number;
|
|
@@ -83,7 +112,7 @@ export interface IPropsBuildVisitSummary {
|
|
|
83
112
|
export declare const isItemAnsweredByClient: (costs: {
|
|
84
113
|
approval?: TCostApproval | null;
|
|
85
114
|
} | null | undefined) => boolean;
|
|
86
|
-
export declare const buildVisitSummary: (data: IVisitData | null | undefined, { servicePrice, taxPercentage, isTaxIncluded }: IPropsBuildVisitSummary) => IVisitSummary;
|
|
115
|
+
export declare const buildVisitSummary: (data: Pick<IVisitData, "sections" | "service_tax_mode"> | null | undefined, { servicePrice, taxPercentage, isTaxIncluded }: IPropsBuildVisitSummary) => IVisitSummary;
|
|
87
116
|
export declare const getTaxConfig: (companyDetails: any) => {
|
|
88
117
|
taxPercentage: number;
|
|
89
118
|
isTaxIncluded: boolean;
|
package/dist/visit.summary.js
CHANGED
|
@@ -40,7 +40,15 @@ const isItemAnsweredByClient = (costs) => {
|
|
|
40
40
|
return (costs.approval ?? "PENDING") !== "PENDING";
|
|
41
41
|
};
|
|
42
42
|
exports.isItemAnsweredByClient = isItemAnsweredByClient;
|
|
43
|
-
const buildVisitSummary = (
|
|
43
|
+
const buildVisitSummary = (
|
|
44
|
+
// DOC: Pide solo lo que USA, y no un `IVisitData` completo. Dos razones:
|
|
45
|
+
// · dice de qué depende de verdad el resumen: los ítems y el modo de impuesto del
|
|
46
|
+
// servicio. Nada más de la visita lo mueve;
|
|
47
|
+
// · el formulario del front no es un `IVisitData` exacto —una firma recién dibujada
|
|
48
|
+
// todavía no tiene fecha ni nombre, que los pone el servidor al guardar—, y exigirle
|
|
49
|
+
// el tipo entero obligaba a un `as any` en la pantalla, que es justo donde no se
|
|
50
|
+
// quiere apagar el compilador.
|
|
51
|
+
data, { servicePrice, taxPercentage, isTaxIncluded }) => {
|
|
44
52
|
const statusCounts = {
|
|
45
53
|
GOOD: 0,
|
|
46
54
|
REGULAR: 0,
|