@asumano/worklip-typeorm-db 1.1.28 → 1.1.29
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/CustomRepository.d.ts +13 -1
- package/dist/CustomRepository.js +9 -0
- package/dist/entities/Client.d.ts +1 -0
- package/dist/entities/Client.js +9 -0
- package/dist/entities/Vehicle.d.ts +1 -0
- package/dist/entities/Vehicle.js +9 -0
- package/dist/entities.views.routes.d.ts +3 -0
- package/dist/entities.views.routes.js +7 -1
- package/dist/filters/ClientsForTheTable.d.ts +6 -0
- package/dist/filters/ClientsForTheTable.js +48 -0
- package/dist/filters/ServicesOrderForTheTable.d.ts +6 -1
- package/dist/filters/ServicesOrderForTheTable.js +181 -0
- package/dist/filters/VehiclesForTheTable.d.ts +6 -0
- package/dist/filters/VehiclesForTheTable.js +48 -0
- package/dist/types.d.ts +4 -0
- package/dist/views/Clients.d.ts +18 -0
- package/dist/views/Clients.js +83 -0
- package/dist/views/Vehicles.d.ts +20 -0
- package/dist/views/Vehicles.js +91 -0
- package/package.json +1 -1
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import { DataSource, EntityTarget, ObjectLiteral, Repository } from "typeorm";
|
|
2
|
-
import { IBasicFilter } from "./types";
|
|
2
|
+
import { IBasicFilter, IPropsFilterTableClientOrVehicle } from "./types";
|
|
3
3
|
export declare class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
|
|
4
4
|
constructor(target: EntityTarget<T>, dataSource: DataSource);
|
|
5
5
|
getAssociatesForTheTableWrapper(params: IBasicFilter): Promise<{
|
|
6
6
|
data: any[];
|
|
7
7
|
totalRecords: number;
|
|
8
8
|
}>;
|
|
9
|
+
getServicesOrderForTheTableWrapper(params: IBasicFilter): Promise<{
|
|
10
|
+
data: any[];
|
|
11
|
+
totalRecords: number;
|
|
12
|
+
}>;
|
|
13
|
+
getClientsForTheTableWrapper(params: IPropsFilterTableClientOrVehicle): Promise<{
|
|
14
|
+
data: any[];
|
|
15
|
+
totalRecords: number;
|
|
16
|
+
}>;
|
|
17
|
+
getVehiclesForTheTableWrapper(params: IPropsFilterTableClientOrVehicle): Promise<{
|
|
18
|
+
data: any[];
|
|
19
|
+
totalRecords: number;
|
|
20
|
+
}>;
|
|
9
21
|
}
|
package/dist/CustomRepository.js
CHANGED
|
@@ -10,5 +10,14 @@ class CustomRepository extends typeorm_1.Repository {
|
|
|
10
10
|
async getAssociatesForTheTableWrapper(params) {
|
|
11
11
|
return await (0, entities_views_routes_1.getAssociatesForTheTable)(this, params);
|
|
12
12
|
}
|
|
13
|
+
async getServicesOrderForTheTableWrapper(params) {
|
|
14
|
+
return await (0, entities_views_routes_1.getServicesOrderForTheTable)(this, params);
|
|
15
|
+
}
|
|
16
|
+
async getClientsForTheTableWrapper(params) {
|
|
17
|
+
return await (0, entities_views_routes_1.getClientsForTheTable)(this, params);
|
|
18
|
+
}
|
|
19
|
+
async getVehiclesForTheTableWrapper(params) {
|
|
20
|
+
return await (0, entities_views_routes_1.getVehiclesForTheTable)(this, params);
|
|
21
|
+
}
|
|
13
22
|
}
|
|
14
23
|
exports.CustomRepository = CustomRepository;
|
package/dist/entities/Client.js
CHANGED
|
@@ -86,6 +86,15 @@ __decorate([
|
|
|
86
86
|
}),
|
|
87
87
|
__metadata("design:type", Object)
|
|
88
88
|
], Client.prototype, "details", void 0);
|
|
89
|
+
__decorate([
|
|
90
|
+
(0, typeorm_1.Column)({
|
|
91
|
+
default: 1,
|
|
92
|
+
type: "int",
|
|
93
|
+
width: 1,
|
|
94
|
+
comment: "Estado en el que se encuentra el cliente, estos clientes no se pueden eliminar ya que la mayoría tienen relación con la tabla service_order.\r\n1: Activo: Visible en la plataforma.\r\n0: Inactivo: No estará visible en la plataforma para crear o enviar información ya sea por correo electrónico o al celular.",
|
|
95
|
+
}),
|
|
96
|
+
__metadata("design:type", Number)
|
|
97
|
+
], Client.prototype, "status", void 0);
|
|
89
98
|
__decorate([
|
|
90
99
|
(0, typeorm_1.OneToMany)(() => ServiceOrder_1.ServiceOrder, (serviceOrder) => serviceOrder.client),
|
|
91
100
|
__metadata("design:type", Array)
|
package/dist/entities/Vehicle.js
CHANGED
|
@@ -85,6 +85,15 @@ __decorate([
|
|
|
85
85
|
}),
|
|
86
86
|
__metadata("design:type", Object)
|
|
87
87
|
], Vehicle.prototype, "details", void 0);
|
|
88
|
+
__decorate([
|
|
89
|
+
(0, typeorm_1.Column)({
|
|
90
|
+
default: 1,
|
|
91
|
+
type: "int",
|
|
92
|
+
width: 1,
|
|
93
|
+
comment: "Estado en el que se encuentra el vehículo, estos vehículos no se pueden eliminar ya que la mayoría tienen relación con la tabla service_order.\r\n1: Activo: Visible en la plataforma.\r\n0: Inactivo: No estará visible en la plataforma para crear nuevos registros.",
|
|
94
|
+
}),
|
|
95
|
+
__metadata("design:type", Number)
|
|
96
|
+
], Vehicle.prototype, "status", void 0);
|
|
88
97
|
__decorate([
|
|
89
98
|
(0, typeorm_1.OneToMany)(() => ServiceOrder_1.ServiceOrder, (serviceOrder) => serviceOrder.vehicle),
|
|
90
99
|
__metadata("design:type", Array)
|
|
@@ -1,3 +1,6 @@
|
|
|
1
1
|
export * from "./entities.index";
|
|
2
2
|
export { getAssociatesForTheTable } from "./filters/AssociatesForTheTable";
|
|
3
|
+
export { getServicesOrderForTheTable } from "./filters/ServicesOrderForTheTable";
|
|
4
|
+
export { getClientsForTheTable } from "./filters/ClientsForTheTable";
|
|
5
|
+
export { getVehiclesForTheTable } from "./filters/VehiclesForTheTable";
|
|
3
6
|
export { CustomRepository } from "./CustomRepository";
|
|
@@ -14,9 +14,15 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.CustomRepository = exports.getAssociatesForTheTable = void 0;
|
|
17
|
+
exports.CustomRepository = exports.getVehiclesForTheTable = exports.getClientsForTheTable = exports.getServicesOrderForTheTable = exports.getAssociatesForTheTable = void 0;
|
|
18
18
|
__exportStar(require("./entities.index"), exports);
|
|
19
19
|
var AssociatesForTheTable_1 = require("./filters/AssociatesForTheTable");
|
|
20
20
|
Object.defineProperty(exports, "getAssociatesForTheTable", { enumerable: true, get: function () { return AssociatesForTheTable_1.getAssociatesForTheTable; } });
|
|
21
|
+
var ServicesOrderForTheTable_1 = require("./filters/ServicesOrderForTheTable");
|
|
22
|
+
Object.defineProperty(exports, "getServicesOrderForTheTable", { enumerable: true, get: function () { return ServicesOrderForTheTable_1.getServicesOrderForTheTable; } });
|
|
23
|
+
var ClientsForTheTable_1 = require("./filters/ClientsForTheTable");
|
|
24
|
+
Object.defineProperty(exports, "getClientsForTheTable", { enumerable: true, get: function () { return ClientsForTheTable_1.getClientsForTheTable; } });
|
|
25
|
+
var VehiclesForTheTable_1 = require("./filters/VehiclesForTheTable");
|
|
26
|
+
Object.defineProperty(exports, "getVehiclesForTheTable", { enumerable: true, get: function () { return VehiclesForTheTable_1.getVehiclesForTheTable; } });
|
|
21
27
|
var CustomRepository_1 = require("./CustomRepository");
|
|
22
28
|
Object.defineProperty(exports, "CustomRepository", { enumerable: true, get: function () { return CustomRepository_1.CustomRepository; } });
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Repository } from "typeorm";
|
|
2
|
+
import { IPropsFilterTableClientOrVehicle } from "../types";
|
|
3
|
+
export declare function getClientsForTheTable(repository: Repository<any>, { company, status, lazyEvent }: IPropsFilterTableClientOrVehicle): Promise<{
|
|
4
|
+
data: any[];
|
|
5
|
+
totalRecords: number;
|
|
6
|
+
}>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getClientsForTheTable = getClientsForTheTable;
|
|
4
|
+
async function getClientsForTheTable(repository, { company, status, lazyEvent }) {
|
|
5
|
+
try {
|
|
6
|
+
const queryBuilder = repository
|
|
7
|
+
.createQueryBuilder()
|
|
8
|
+
.skip(lazyEvent.first)
|
|
9
|
+
.take(lazyEvent.rows);
|
|
10
|
+
// DOC: Filtro global
|
|
11
|
+
if (lazyEvent.filters["global"] && lazyEvent.filters["global"].value) {
|
|
12
|
+
const globalValue = `%${lazyEvent.filters["global"].value.toLowerCase()}%`;
|
|
13
|
+
queryBuilder.andWhere("(document LIKE :globalValue OR LOWER(name) LIKE :globalValue OR LOWER(surname) LIKE :globalValue OR LOWER(full_name) LIKE :globalValue OR LOWER(email) LIKE :globalValue OR phone LIKE :globalValue OR LOWER(city_name) LIKE :globalValue)", { globalValue });
|
|
14
|
+
}
|
|
15
|
+
// DOC: Filtro por estado FILTRO POR DEFECTO.
|
|
16
|
+
if (status !== null && status >= 0) {
|
|
17
|
+
queryBuilder.andWhere("status = :status", {
|
|
18
|
+
status,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
// DOC: Filtro por company FILTRO POR DEFECTO.
|
|
22
|
+
if (company !== null && company >= 0) {
|
|
23
|
+
queryBuilder.andWhere("company = :company", {
|
|
24
|
+
company,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
// DOC: Ordenamiento de los resultados.
|
|
28
|
+
if (lazyEvent.sortField) {
|
|
29
|
+
const sortOrder = lazyEvent.sortOrder === 1 ? "ASC" : "DESC";
|
|
30
|
+
queryBuilder.addOrderBy(`${lazyEvent.sortField}`, sortOrder);
|
|
31
|
+
}
|
|
32
|
+
// DOC: Ejecutamos la consulta y obtenemos los resultados.
|
|
33
|
+
const [data, totalRecords] = await queryBuilder.getManyAndCount();
|
|
34
|
+
// DOC: Si quieres ver la consulta generada, puedes descomentar las siguientes líneas:
|
|
35
|
+
// console.log("Query:", queryBuilder.getQuery());
|
|
36
|
+
// console.log("Query:", queryBuilder.getQueryAndParameters());
|
|
37
|
+
return {
|
|
38
|
+
data,
|
|
39
|
+
totalRecords,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
catch (_error) {
|
|
43
|
+
return {
|
|
44
|
+
data: [],
|
|
45
|
+
totalRecords: 0,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -1 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
import { Repository } from "typeorm";
|
|
2
|
+
import { IBasicFilter } from "../types";
|
|
3
|
+
export declare function getServicesOrderForTheTable(repository: Repository<any>, { company, workshop, status, visible, lazyEvent }: IBasicFilter): Promise<{
|
|
4
|
+
data: any[];
|
|
5
|
+
totalRecords: number;
|
|
6
|
+
}>;
|
|
@@ -1,2 +1,183 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getServicesOrderForTheTable = getServicesOrderForTheTable;
|
|
4
|
+
async function getServicesOrderForTheTable(repository, { company, workshop, status, visible, lazyEvent }) {
|
|
5
|
+
try {
|
|
6
|
+
const queryBuilder = repository
|
|
7
|
+
.createQueryBuilder()
|
|
8
|
+
.skip(lazyEvent.first)
|
|
9
|
+
.take(lazyEvent.rows);
|
|
10
|
+
// DOC: Filtro global
|
|
11
|
+
if (lazyEvent.filters["global"] && lazyEvent.filters["global"].value) {
|
|
12
|
+
const globalValue = `%${lazyEvent.filters["global"].value.toLowerCase()}%`;
|
|
13
|
+
queryBuilder.andWhere("(LOWER(code) LIKE :globalValue OR LOWER(title) LIKE :globalValue OR client_document LIKE :globalValue OR LOWER(client_name) LIKE :globalValue OR LOWER(client_surname) LIKE :globalValue OR LOWER(client_full_name) LIKE :globalValue OR LOWER(workshop_name) LIKE :globalValue OR LOWER(vehicle_plate) LIKE :globalValue OR LOWER(template_code) LIKE :globalValue OR LOWER(template_name) LIKE :globalValue)", { globalValue });
|
|
14
|
+
}
|
|
15
|
+
// DOC: Filtro por estado FILTRO POR DEFECTO.
|
|
16
|
+
if (status !== null && status >= 0) {
|
|
17
|
+
queryBuilder.andWhere("status = :status", {
|
|
18
|
+
status,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
// DOC: Filtro por company FILTRO POR DEFECTO.
|
|
22
|
+
if (company !== null && company >= 0) {
|
|
23
|
+
queryBuilder.andWhere("workshop_company = :company", {
|
|
24
|
+
company,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
// DOC: Filtro por workshop.
|
|
28
|
+
if (workshop !== null && workshop >= 0) {
|
|
29
|
+
queryBuilder.andWhere("workshop = :workshop", {
|
|
30
|
+
workshop,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// DOC: Acá vienen los otros filtros, por las columnas de la tabla.
|
|
34
|
+
const filters = lazyEvent.filters;
|
|
35
|
+
Object.keys(filters).forEach((key) => {
|
|
36
|
+
let value = filters[key].value; // DOC: Obtenemos el valor del filtro.
|
|
37
|
+
if ((Array.isArray(value) && value.length > 0) ||
|
|
38
|
+
(!Array.isArray(value) && value && key !== "global")) {
|
|
39
|
+
// DOC: Verificamos si el filtro tiene valor, si no es un filtro global y no es un array vacío.
|
|
40
|
+
const matchMode = filters[key].matchMode; // DOC: Obtenemos el modo de coincidencia del filtro.
|
|
41
|
+
if (!Array.isArray(value) && value) {
|
|
42
|
+
// DOC: Si el valor no es un array y tiene valor, lo convertimos a minúsculas.
|
|
43
|
+
value = filters[key].value.toLowerCase();
|
|
44
|
+
}
|
|
45
|
+
const accessKey = key.split(".").length > 1 ? `${key}` : `${key}`; // DOC: Verificamos si el filtro es un campo anidado o no.
|
|
46
|
+
switch (matchMode // DOC: Verificamos el modo de coincidencia del filtro.
|
|
47
|
+
) {
|
|
48
|
+
case "custom":
|
|
49
|
+
if (key === "created" || key === "updated") {
|
|
50
|
+
if (Array.isArray(value) && value.length === 2) {
|
|
51
|
+
const [from, to] = value;
|
|
52
|
+
if (from !== null && to === null) {
|
|
53
|
+
queryBuilder.andWhere(`${accessKey} >= :from`, {
|
|
54
|
+
from: new Date(from),
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
else if (from === null && to !== null) {
|
|
58
|
+
queryBuilder.andWhere(`${accessKey} <= :to`, {
|
|
59
|
+
to: new Date(to),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
else if (from !== null && to !== null) {
|
|
63
|
+
queryBuilder.andWhere(`${accessKey} BETWEEN :from AND :to`, {
|
|
64
|
+
from: new Date(from),
|
|
65
|
+
to: new Date(to),
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (key === "workshop" ||
|
|
71
|
+
key === "vehicle" ||
|
|
72
|
+
key === "client" ||
|
|
73
|
+
key === "template") {
|
|
74
|
+
if (Array.isArray(value) && value.length > 0) {
|
|
75
|
+
queryBuilder.andWhere(`${accessKey} IN (:...${key})`, {
|
|
76
|
+
[key]: value,
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (key === "history_count") {
|
|
81
|
+
if (Array.isArray(value) && value.length === 2) {
|
|
82
|
+
const [from, to] = value;
|
|
83
|
+
if (from !== null && to === null) {
|
|
84
|
+
queryBuilder.andWhere(`${accessKey} >= :from`, { from });
|
|
85
|
+
}
|
|
86
|
+
else if (from === null && to !== null) {
|
|
87
|
+
queryBuilder.andWhere(`${accessKey} <= :to`, { to });
|
|
88
|
+
}
|
|
89
|
+
else if (from !== null && to !== null) {
|
|
90
|
+
queryBuilder.andWhere(`${accessKey} BETWEEN :from AND :to`, {
|
|
91
|
+
from,
|
|
92
|
+
to,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
break;
|
|
98
|
+
case "contains": // DOC: Si el modo de coincidencia es "contains".
|
|
99
|
+
queryBuilder.andWhere(`LOWER(${accessKey}) LIKE :${key}`, {
|
|
100
|
+
[key]: `%${value}%`,
|
|
101
|
+
});
|
|
102
|
+
break;
|
|
103
|
+
case "notContains": // DOC: Si el modo de coincidencia es "notContains".
|
|
104
|
+
queryBuilder.andWhere(`LOWER(${accessKey}) NOT LIKE :${key}`, {
|
|
105
|
+
[key]: `%${value}%`,
|
|
106
|
+
});
|
|
107
|
+
break;
|
|
108
|
+
case "equals": // DOC: Si el modo de coincidencia es "equals".
|
|
109
|
+
queryBuilder.andWhere(`${accessKey} = :${key}`, { [key]: value });
|
|
110
|
+
break;
|
|
111
|
+
case "notEquals": // DOC: Si el modo de coincidencia es "notEquals".
|
|
112
|
+
queryBuilder.andWhere(`${accessKey} != :${key}`, { [key]: value });
|
|
113
|
+
break;
|
|
114
|
+
case "startsWith": // DOC: Si el modo de coincidencia es "startsWith".
|
|
115
|
+
queryBuilder.andWhere(`LOWER(${accessKey}) LIKE :${key}`, {
|
|
116
|
+
[key]: `${value}%`,
|
|
117
|
+
});
|
|
118
|
+
break;
|
|
119
|
+
case "endsWith": // DOC: Si el modo de coincidencia es "endsWith".
|
|
120
|
+
queryBuilder.andWhere(`LOWER(${accessKey}) LIKE :${key}`, {
|
|
121
|
+
[key]: `%${value}`,
|
|
122
|
+
});
|
|
123
|
+
break;
|
|
124
|
+
case "in": // DOC: Si el modo de coincidencia es "in".
|
|
125
|
+
if (Array.isArray(value)) {
|
|
126
|
+
queryBuilder.andWhere(`${accessKey} IN (:...${key})`, {
|
|
127
|
+
[key]: value,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
break;
|
|
131
|
+
case "notIn": // DOC: Si el modo de coincidencia es "notIn
|
|
132
|
+
if (Array.isArray(value)) {
|
|
133
|
+
queryBuilder.andWhere(`${accessKey} NOT IN (:...${key})`, {
|
|
134
|
+
[key]: value,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
break;
|
|
138
|
+
case "lt": // DOC: Si el modo de coincidencia es "lt" (less than).
|
|
139
|
+
queryBuilder.andWhere(`${accessKey} < :${key}`, { [key]: value });
|
|
140
|
+
break;
|
|
141
|
+
case "lte": // DOC: Si el modo de coincidencia es "lte" (less than or equal).
|
|
142
|
+
queryBuilder.andWhere(`${accessKey} <= :${key}`, { [key]: value });
|
|
143
|
+
break;
|
|
144
|
+
case "gt": // DOC: Si el modo de coincidencia es "gt" (greater than).
|
|
145
|
+
queryBuilder.andWhere(`${accessKey} > :${key}`, { [key]: value });
|
|
146
|
+
break;
|
|
147
|
+
case "gte": // DOC: Si el modo de coincidencia es "gte" (greater than or equal).
|
|
148
|
+
queryBuilder.andWhere(`${accessKey} >= :${key}`, { [key]: value });
|
|
149
|
+
break;
|
|
150
|
+
case "between": // DOC: Si el modo de coincidencia es "between".
|
|
151
|
+
if (Array.isArray(value) && value.length === 2) {
|
|
152
|
+
const [from, to] = value;
|
|
153
|
+
queryBuilder.andWhere(`${accessKey} BETWEEN :from AND :to`, {
|
|
154
|
+
from,
|
|
155
|
+
to,
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
// DOC: Ordenamiento de los resultados.
|
|
163
|
+
if (lazyEvent.sortField) {
|
|
164
|
+
const sortOrder = lazyEvent.sortOrder === 1 ? "ASC" : "DESC";
|
|
165
|
+
queryBuilder.addOrderBy(`${lazyEvent.sortField}`, sortOrder);
|
|
166
|
+
}
|
|
167
|
+
// DOC: Ejecutamos la consulta y obtenemos los resultados.
|
|
168
|
+
const [data, totalRecords] = await queryBuilder.getManyAndCount();
|
|
169
|
+
// DOC: Si quieres ver la consulta generada, puedes descomentar las siguientes líneas:
|
|
170
|
+
// console.log("Query:", queryBuilder.getQuery());
|
|
171
|
+
// console.log("Query:", queryBuilder.getQueryAndParameters());
|
|
172
|
+
return {
|
|
173
|
+
data,
|
|
174
|
+
totalRecords,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
catch (_error) {
|
|
178
|
+
return {
|
|
179
|
+
data: [],
|
|
180
|
+
totalRecords: 0,
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Repository } from "typeorm";
|
|
2
|
+
import { IPropsFilterTableClientOrVehicle } from "../types";
|
|
3
|
+
export declare function getVehiclesForTheTable(repository: Repository<any>, { company, status, lazyEvent }: IPropsFilterTableClientOrVehicle): Promise<{
|
|
4
|
+
data: any[];
|
|
5
|
+
totalRecords: number;
|
|
6
|
+
}>;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getVehiclesForTheTable = getVehiclesForTheTable;
|
|
4
|
+
async function getVehiclesForTheTable(repository, { company, status, lazyEvent }) {
|
|
5
|
+
try {
|
|
6
|
+
const queryBuilder = repository
|
|
7
|
+
.createQueryBuilder()
|
|
8
|
+
.skip(lazyEvent.first)
|
|
9
|
+
.take(lazyEvent.rows);
|
|
10
|
+
// DOC: Filtro global
|
|
11
|
+
if (lazyEvent.filters["global"] && lazyEvent.filters["global"].value) {
|
|
12
|
+
const globalValue = `%${lazyEvent.filters["global"].value.toLowerCase()}%`;
|
|
13
|
+
queryBuilder.andWhere("(LOWER(plate) LIKE :globalValue OR mileage LIKE :globalValue OR model LIKE :globalValue OR LOWER(version) LIKE :globalValue OR LOWER(vehicle_type_name) LIKE :globalValue OR LOWER(brand_name) LIKE :globalValue)", { globalValue });
|
|
14
|
+
}
|
|
15
|
+
// DOC: Filtro por estado FILTRO POR DEFECTO.
|
|
16
|
+
if (status !== null && status >= 0) {
|
|
17
|
+
queryBuilder.andWhere("status = :status", {
|
|
18
|
+
status,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
// DOC: Filtro por company FILTRO POR DEFECTO.
|
|
22
|
+
if (company !== null && company >= 0) {
|
|
23
|
+
queryBuilder.andWhere("company = :company", {
|
|
24
|
+
company,
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
// DOC: Ordenamiento de los resultados.
|
|
28
|
+
if (lazyEvent.sortField) {
|
|
29
|
+
const sortOrder = lazyEvent.sortOrder === 1 ? "ASC" : "DESC";
|
|
30
|
+
queryBuilder.addOrderBy(`${lazyEvent.sortField}`, sortOrder);
|
|
31
|
+
}
|
|
32
|
+
// DOC: Ejecutamos la consulta y obtenemos los resultados.
|
|
33
|
+
const [data, totalRecords] = await queryBuilder.getManyAndCount();
|
|
34
|
+
// DOC: Si quieres ver la consulta generada, puedes descomentar las siguientes líneas:
|
|
35
|
+
// console.log("Query:", queryBuilder.getQuery());
|
|
36
|
+
// console.log("Query:", queryBuilder.getQueryAndParameters());
|
|
37
|
+
return {
|
|
38
|
+
data,
|
|
39
|
+
totalRecords,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
catch (_error) {
|
|
43
|
+
return {
|
|
44
|
+
data: [],
|
|
45
|
+
totalRecords: 0,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
package/dist/types.d.ts
CHANGED
|
@@ -14,4 +14,8 @@ export interface IBasicFilter extends IBasicLazyEvent {
|
|
|
14
14
|
workshop: number | null;
|
|
15
15
|
visible: number | null;
|
|
16
16
|
}
|
|
17
|
+
export interface IPropsFilterTableClientOrVehicle extends IBasicLazyEvent {
|
|
18
|
+
company: number | null;
|
|
19
|
+
status: number | null;
|
|
20
|
+
}
|
|
17
21
|
export type IType = "mysql" | "mariadb";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare class Clients {
|
|
2
|
+
id: number;
|
|
3
|
+
document: string | null;
|
|
4
|
+
company: number;
|
|
5
|
+
name: string;
|
|
6
|
+
surname: string;
|
|
7
|
+
full_name: string;
|
|
8
|
+
email: string;
|
|
9
|
+
phone: string | null;
|
|
10
|
+
city: number;
|
|
11
|
+
details: any | null;
|
|
12
|
+
status: number;
|
|
13
|
+
city_id: number;
|
|
14
|
+
city_name: string;
|
|
15
|
+
city_region: number;
|
|
16
|
+
city_status: number;
|
|
17
|
+
total_service_orders: number;
|
|
18
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
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.Clients = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
let Clients = class Clients {
|
|
15
|
+
};
|
|
16
|
+
exports.Clients = Clients;
|
|
17
|
+
__decorate([
|
|
18
|
+
(0, typeorm_1.ViewColumn)(),
|
|
19
|
+
__metadata("design:type", Number)
|
|
20
|
+
], Clients.prototype, "id", void 0);
|
|
21
|
+
__decorate([
|
|
22
|
+
(0, typeorm_1.ViewColumn)(),
|
|
23
|
+
__metadata("design:type", Object)
|
|
24
|
+
], Clients.prototype, "document", void 0);
|
|
25
|
+
__decorate([
|
|
26
|
+
(0, typeorm_1.ViewColumn)(),
|
|
27
|
+
__metadata("design:type", Number)
|
|
28
|
+
], Clients.prototype, "company", void 0);
|
|
29
|
+
__decorate([
|
|
30
|
+
(0, typeorm_1.ViewColumn)(),
|
|
31
|
+
__metadata("design:type", String)
|
|
32
|
+
], Clients.prototype, "name", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, typeorm_1.ViewColumn)(),
|
|
35
|
+
__metadata("design:type", String)
|
|
36
|
+
], Clients.prototype, "surname", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, typeorm_1.ViewColumn)(),
|
|
39
|
+
__metadata("design:type", String)
|
|
40
|
+
], Clients.prototype, "full_name", void 0);
|
|
41
|
+
__decorate([
|
|
42
|
+
(0, typeorm_1.ViewColumn)(),
|
|
43
|
+
__metadata("design:type", String)
|
|
44
|
+
], Clients.prototype, "email", void 0);
|
|
45
|
+
__decorate([
|
|
46
|
+
(0, typeorm_1.ViewColumn)(),
|
|
47
|
+
__metadata("design:type", Object)
|
|
48
|
+
], Clients.prototype, "phone", void 0);
|
|
49
|
+
__decorate([
|
|
50
|
+
(0, typeorm_1.ViewColumn)(),
|
|
51
|
+
__metadata("design:type", Number)
|
|
52
|
+
], Clients.prototype, "city", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
(0, typeorm_1.ViewColumn)(),
|
|
55
|
+
__metadata("design:type", Object)
|
|
56
|
+
], Clients.prototype, "details", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
(0, typeorm_1.ViewColumn)(),
|
|
59
|
+
__metadata("design:type", Number)
|
|
60
|
+
], Clients.prototype, "status", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, typeorm_1.ViewColumn)(),
|
|
63
|
+
__metadata("design:type", Number)
|
|
64
|
+
], Clients.prototype, "city_id", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
(0, typeorm_1.ViewColumn)(),
|
|
67
|
+
__metadata("design:type", String)
|
|
68
|
+
], Clients.prototype, "city_name", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
(0, typeorm_1.ViewColumn)(),
|
|
71
|
+
__metadata("design:type", Number)
|
|
72
|
+
], Clients.prototype, "city_region", void 0);
|
|
73
|
+
__decorate([
|
|
74
|
+
(0, typeorm_1.ViewColumn)(),
|
|
75
|
+
__metadata("design:type", Number)
|
|
76
|
+
], Clients.prototype, "city_status", void 0);
|
|
77
|
+
__decorate([
|
|
78
|
+
(0, typeorm_1.ViewColumn)(),
|
|
79
|
+
__metadata("design:type", Number)
|
|
80
|
+
], Clients.prototype, "total_service_orders", void 0);
|
|
81
|
+
exports.Clients = Clients = __decorate([
|
|
82
|
+
(0, typeorm_1.ViewEntity)()
|
|
83
|
+
], Clients);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare class Vehicles {
|
|
2
|
+
id: number;
|
|
3
|
+
company: number;
|
|
4
|
+
vehicle_type: number;
|
|
5
|
+
plate: string;
|
|
6
|
+
brand: number;
|
|
7
|
+
mileage: number;
|
|
8
|
+
model: number;
|
|
9
|
+
version: string;
|
|
10
|
+
details: any | null;
|
|
11
|
+
status: number;
|
|
12
|
+
vehicle_type_id: number;
|
|
13
|
+
vehicle_type_name: string;
|
|
14
|
+
vehicle_type_details: any | null;
|
|
15
|
+
vehicle_type_status: number;
|
|
16
|
+
brand_id: number;
|
|
17
|
+
brand_name: string;
|
|
18
|
+
brand_details: any | null;
|
|
19
|
+
total_service_orders: number;
|
|
20
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
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.Vehicles = void 0;
|
|
13
|
+
const typeorm_1 = require("typeorm");
|
|
14
|
+
let Vehicles = class Vehicles {
|
|
15
|
+
};
|
|
16
|
+
exports.Vehicles = Vehicles;
|
|
17
|
+
__decorate([
|
|
18
|
+
(0, typeorm_1.ViewColumn)(),
|
|
19
|
+
__metadata("design:type", Number)
|
|
20
|
+
], Vehicles.prototype, "id", void 0);
|
|
21
|
+
__decorate([
|
|
22
|
+
(0, typeorm_1.ViewColumn)(),
|
|
23
|
+
__metadata("design:type", Number)
|
|
24
|
+
], Vehicles.prototype, "company", void 0);
|
|
25
|
+
__decorate([
|
|
26
|
+
(0, typeorm_1.ViewColumn)(),
|
|
27
|
+
__metadata("design:type", Number)
|
|
28
|
+
], Vehicles.prototype, "vehicle_type", void 0);
|
|
29
|
+
__decorate([
|
|
30
|
+
(0, typeorm_1.ViewColumn)(),
|
|
31
|
+
__metadata("design:type", String)
|
|
32
|
+
], Vehicles.prototype, "plate", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, typeorm_1.ViewColumn)(),
|
|
35
|
+
__metadata("design:type", Number)
|
|
36
|
+
], Vehicles.prototype, "brand", void 0);
|
|
37
|
+
__decorate([
|
|
38
|
+
(0, typeorm_1.ViewColumn)(),
|
|
39
|
+
__metadata("design:type", Number)
|
|
40
|
+
], Vehicles.prototype, "mileage", void 0);
|
|
41
|
+
__decorate([
|
|
42
|
+
(0, typeorm_1.ViewColumn)(),
|
|
43
|
+
__metadata("design:type", Number)
|
|
44
|
+
], Vehicles.prototype, "model", void 0);
|
|
45
|
+
__decorate([
|
|
46
|
+
(0, typeorm_1.ViewColumn)(),
|
|
47
|
+
__metadata("design:type", String)
|
|
48
|
+
], Vehicles.prototype, "version", void 0);
|
|
49
|
+
__decorate([
|
|
50
|
+
(0, typeorm_1.ViewColumn)(),
|
|
51
|
+
__metadata("design:type", Object)
|
|
52
|
+
], Vehicles.prototype, "details", void 0);
|
|
53
|
+
__decorate([
|
|
54
|
+
(0, typeorm_1.ViewColumn)(),
|
|
55
|
+
__metadata("design:type", Number)
|
|
56
|
+
], Vehicles.prototype, "status", void 0);
|
|
57
|
+
__decorate([
|
|
58
|
+
(0, typeorm_1.ViewColumn)(),
|
|
59
|
+
__metadata("design:type", Number)
|
|
60
|
+
], Vehicles.prototype, "vehicle_type_id", void 0);
|
|
61
|
+
__decorate([
|
|
62
|
+
(0, typeorm_1.ViewColumn)(),
|
|
63
|
+
__metadata("design:type", String)
|
|
64
|
+
], Vehicles.prototype, "vehicle_type_name", void 0);
|
|
65
|
+
__decorate([
|
|
66
|
+
(0, typeorm_1.ViewColumn)(),
|
|
67
|
+
__metadata("design:type", Object)
|
|
68
|
+
], Vehicles.prototype, "vehicle_type_details", void 0);
|
|
69
|
+
__decorate([
|
|
70
|
+
(0, typeorm_1.ViewColumn)(),
|
|
71
|
+
__metadata("design:type", Number)
|
|
72
|
+
], Vehicles.prototype, "vehicle_type_status", void 0);
|
|
73
|
+
__decorate([
|
|
74
|
+
(0, typeorm_1.ViewColumn)(),
|
|
75
|
+
__metadata("design:type", Number)
|
|
76
|
+
], Vehicles.prototype, "brand_id", void 0);
|
|
77
|
+
__decorate([
|
|
78
|
+
(0, typeorm_1.ViewColumn)(),
|
|
79
|
+
__metadata("design:type", String)
|
|
80
|
+
], Vehicles.prototype, "brand_name", void 0);
|
|
81
|
+
__decorate([
|
|
82
|
+
(0, typeorm_1.ViewColumn)(),
|
|
83
|
+
__metadata("design:type", Object)
|
|
84
|
+
], Vehicles.prototype, "brand_details", void 0);
|
|
85
|
+
__decorate([
|
|
86
|
+
(0, typeorm_1.ViewColumn)(),
|
|
87
|
+
__metadata("design:type", Number)
|
|
88
|
+
], Vehicles.prototype, "total_service_orders", void 0);
|
|
89
|
+
exports.Vehicles = Vehicles = __decorate([
|
|
90
|
+
(0, typeorm_1.ViewEntity)()
|
|
91
|
+
], Vehicles);
|