@asumano/worklip-typeorm-db 1.1.3 → 1.1.4

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.
@@ -0,0 +1,9 @@
1
+ import { DataSource, EntityTarget, ObjectLiteral, Repository } from "typeorm";
2
+ import { IBasicFilter } from "./types";
3
+ export declare class CustomRepository<T extends ObjectLiteral> extends Repository<T> {
4
+ constructor(target: EntityTarget<T>, dataSource: DataSource);
5
+ getAssociatesForTheTableWrapper(params: IBasicFilter): Promise<{
6
+ data: any[];
7
+ totalRecords: number;
8
+ }>;
9
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CustomRepository = void 0;
4
+ const typeorm_1 = require("typeorm");
5
+ const entities_views_routes_1 = require("./entities.views.routes");
6
+ class CustomRepository extends typeorm_1.Repository {
7
+ constructor(target, dataSource) {
8
+ super(target, dataSource.manager);
9
+ }
10
+ async getAssociatesForTheTableWrapper(params) {
11
+ return await (0, entities_views_routes_1.getAssociatesForTheTable)(this, params);
12
+ }
13
+ }
14
+ exports.CustomRepository = CustomRepository;
@@ -23,3 +23,4 @@ export { AssociatePlatform } from "./entities/AssociatePlatform";
23
23
  export { AssociateRole } from "./entities/AssociateRole";
24
24
  export { AssociatePermission } from "./entities/AssociatePermission";
25
25
  export { AssociateSection } from "./entities/AssociateSection";
26
+ export { Associates } from "./views/Associates";
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AssociateSection = exports.AssociatePermission = exports.AssociateRole = exports.AssociatePlatform = exports.Reminder = exports.ServiceOrderHistory = exports.ServiceOrder = exports.TemplateSectionItem = exports.TemplateSection = exports.Template = exports.Workshop = exports.GlobalTemplateSectionItem = exports.GlobalTemplateSection = exports.GlobalTemplate = exports.AssociateSession = exports.MasterSession = exports.Associate = exports.Client = exports.Master = exports.Vehicle = exports.Brand = exports.Company = exports.City = exports.Region = exports.Country = void 0;
3
+ exports.Associates = exports.AssociateSection = exports.AssociatePermission = exports.AssociateRole = exports.AssociatePlatform = exports.Reminder = exports.ServiceOrderHistory = exports.ServiceOrder = exports.TemplateSectionItem = exports.TemplateSection = exports.Template = exports.Workshop = exports.GlobalTemplateSectionItem = exports.GlobalTemplateSection = exports.GlobalTemplate = exports.AssociateSession = exports.MasterSession = exports.Associate = exports.Client = exports.Master = exports.Vehicle = exports.Brand = exports.Company = exports.City = exports.Region = exports.Country = void 0;
4
4
  var Country_1 = require("./entities/Country");
5
5
  Object.defineProperty(exports, "Country", { enumerable: true, get: function () { return Country_1.Country; } });
6
6
  var Region_1 = require("./entities/Region");
@@ -51,3 +51,5 @@ var AssociatePermission_1 = require("./entities/AssociatePermission");
51
51
  Object.defineProperty(exports, "AssociatePermission", { enumerable: true, get: function () { return AssociatePermission_1.AssociatePermission; } });
52
52
  var AssociateSection_1 = require("./entities/AssociateSection");
53
53
  Object.defineProperty(exports, "AssociateSection", { enumerable: true, get: function () { return AssociateSection_1.AssociateSection; } });
54
+ var Associates_1 = require("./views/Associates");
55
+ Object.defineProperty(exports, "Associates", { enumerable: true, get: function () { return Associates_1.Associates; } });
@@ -1 +1,3 @@
1
1
  export * from "./entities.index";
2
+ export { getAssociatesForTheTable } from "./filters/AssociatesForTheTable";
3
+ export { CustomRepository } from "./CustomRepository";
@@ -14,4 +14,9 @@ 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
18
  __exportStar(require("./entities.index"), exports);
19
+ var AssociatesForTheTable_1 = require("./filters/AssociatesForTheTable");
20
+ Object.defineProperty(exports, "getAssociatesForTheTable", { enumerable: true, get: function () { return AssociatesForTheTable_1.getAssociatesForTheTable; } });
21
+ var CustomRepository_1 = require("./CustomRepository");
22
+ Object.defineProperty(exports, "CustomRepository", { enumerable: true, get: function () { return CustomRepository_1.CustomRepository; } });
@@ -0,0 +1,6 @@
1
+ import { Repository } from "typeorm";
2
+ import { IBasicFilter } from "../types";
3
+ export declare function getAssociatesForTheTable(repository: Repository<any>, { company, status, visible, lazyEvent }: IBasicFilter): Promise<{
4
+ data: any[];
5
+ totalRecords: number;
6
+ }>;
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getAssociatesForTheTable = getAssociatesForTheTable;
4
+ async function getAssociatesForTheTable(repository, { company, status, visible, lazyEvent }) {
5
+ try {
6
+ const queryBuilder = repository
7
+ .createQueryBuilder("associates")
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(associates.code) LIKE :globalValue OR LOWER(associates.name) LIKE :globalValue OR LOWER(associates.surname) LIKE :globalValue OR LOWER(associates.full_name) LIKE :globalValue OR LOWER(associates.email) LIKE :globalValue OR LOWER(associates.document) LIKE :globalValue OR LOWER(associates.phone) LIKE :globalValue OR LOWER(associates.address) LIKE :globalValue OR LOWER(associates.city_name) LIKE :globalValue)", { globalValue });
14
+ }
15
+ // DOC: Filtro por estado FILTRO POR DEFECTO.
16
+ if (status !== null && status >= 0) {
17
+ queryBuilder.andWhere("associates.status = :status", {
18
+ status,
19
+ });
20
+ }
21
+ // DOC: Filtro por company FILTRO POR DEFECTO.
22
+ if (company !== null && company >= 0) {
23
+ queryBuilder.andWhere("associates.company = :company", {
24
+ company,
25
+ });
26
+ }
27
+ // DOC: Filtro por visible FILTRO POR DEFECTO.
28
+ if (visible !== null) {
29
+ queryBuilder.andWhere("associates.visible = :visible", {
30
+ visible,
31
+ });
32
+ }
33
+ // DOC: Ordenamiento de los resultados.
34
+ if (lazyEvent.sortField) {
35
+ const sortOrder = lazyEvent.sortOrder === 1 ? "ASC" : "DESC";
36
+ queryBuilder.addOrderBy(`associates.${lazyEvent.sortField}`, sortOrder);
37
+ }
38
+ // DOC: Ejecutamos la consulta y obtenemos los resultados.
39
+ const [data, totalRecords] = await queryBuilder.getManyAndCount();
40
+ // DOC: Si quieres ver la consulta generada, puedes descomentar las siguientes líneas:
41
+ // console.log("Query:", queryBuilder.getQuery());
42
+ // console.log("Query:", queryBuilder.getQueryAndParameters());
43
+ return {
44
+ data,
45
+ totalRecords,
46
+ };
47
+ }
48
+ catch (_error) {
49
+ return {
50
+ data: [],
51
+ totalRecords: 0,
52
+ };
53
+ }
54
+ }
package/dist/index.d.ts CHANGED
@@ -1,7 +1,14 @@
1
1
  import { DataSource, EntityTarget, ObjectLiteral, Repository } from "typeorm";
2
+ import { IBasicFilter } from "./types";
2
3
  export * from "./entities.views.routes";
3
4
  export declare function createDataBaseSource(): DataSource;
4
5
  export declare function showEntityName<T extends ObjectLiteral>(entity: EntityTarget<T>): Promise<Repository<T>>;
5
6
  export declare function callStoredProcedureName(storedProcedure: any, elements: any): Promise<any>;
6
7
  export declare function getDataSource(): Promise<DataSource>;
7
8
  export declare function executeQuery(query: string, params?: any[]): Promise<any>;
9
+ export declare const getRepositoryByEntity: <T extends ObjectLiteral>(entity: EntityTarget<T>) => Promise<Repository<T> & {
10
+ getAssociatesForTheTableWrapper(params: IBasicFilter): Promise<{
11
+ data: any[];
12
+ totalRecords: number;
13
+ }>;
14
+ }>;
package/dist/index.js CHANGED
@@ -36,6 +36,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
36
36
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.getRepositoryByEntity = void 0;
39
40
  exports.createDataBaseSource = createDataBaseSource;
40
41
  exports.showEntityName = showEntityName;
41
42
  exports.callStoredProcedureName = callStoredProcedureName;
@@ -45,6 +46,7 @@ const dotenv_1 = require("dotenv");
45
46
  const path_1 = require("path");
46
47
  const typeorm_1 = require("typeorm");
47
48
  const EntitiesViewsRoutes = __importStar(require("./entities.index"));
49
+ const entities_views_routes_1 = require("./entities.views.routes");
48
50
  __exportStar(require("./entities.views.routes"), exports);
49
51
  let connection = null;
50
52
  // DOC: Función para crear la conexión de la base de datos.
@@ -114,3 +116,15 @@ async function executeQuery(query, params = []) {
114
116
  const ds = await getDataSource();
115
117
  return ds.query(query, params);
116
118
  }
119
+ const getRepositoryByEntity = async (entity) => {
120
+ if (!connection || !connection.isInitialized) {
121
+ connection = createDataBaseSource();
122
+ await connection.initialize();
123
+ }
124
+ return connection.getRepository(entity).extend({
125
+ async getAssociatesForTheTableWrapper(params) {
126
+ return (0, entities_views_routes_1.getAssociatesForTheTable)(this, params);
127
+ },
128
+ });
129
+ };
130
+ exports.getRepositoryByEntity = getRepositoryByEntity;
package/dist/types.d.ts CHANGED
@@ -1 +1,16 @@
1
+ export interface IBasicLazyEvent {
2
+ lazyEvent: {
3
+ first: number;
4
+ rows: number;
5
+ page: number;
6
+ sortField: any;
7
+ sortOrder: any;
8
+ filters: any;
9
+ };
10
+ }
11
+ export interface IBasicFilter extends IBasicLazyEvent {
12
+ status: number | null;
13
+ company: number | null;
14
+ visible: number | null;
15
+ }
1
16
  export type IType = "mysql" | "mariadb";
@@ -0,0 +1,22 @@
1
+ export declare class Associates {
2
+ id: number;
3
+ code: string;
4
+ company: number;
5
+ document: string;
6
+ name: string;
7
+ surname: string;
8
+ full_name: string;
9
+ email: string;
10
+ phone: string;
11
+ address: string;
12
+ details: any;
13
+ created: Date;
14
+ updated: Date;
15
+ owner: number;
16
+ status: number;
17
+ visible: number;
18
+ city_id: number;
19
+ city_name: string;
20
+ city_region: number;
21
+ city_status: number;
22
+ }
@@ -0,0 +1,99 @@
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.Associates = void 0;
13
+ const typeorm_1 = require("typeorm");
14
+ let Associates = class Associates {
15
+ };
16
+ exports.Associates = Associates;
17
+ __decorate([
18
+ (0, typeorm_1.ViewColumn)(),
19
+ __metadata("design:type", Number)
20
+ ], Associates.prototype, "id", void 0);
21
+ __decorate([
22
+ (0, typeorm_1.ViewColumn)(),
23
+ __metadata("design:type", String)
24
+ ], Associates.prototype, "code", void 0);
25
+ __decorate([
26
+ (0, typeorm_1.ViewColumn)(),
27
+ __metadata("design:type", Number)
28
+ ], Associates.prototype, "company", void 0);
29
+ __decorate([
30
+ (0, typeorm_1.ViewColumn)(),
31
+ __metadata("design:type", String)
32
+ ], Associates.prototype, "document", void 0);
33
+ __decorate([
34
+ (0, typeorm_1.ViewColumn)(),
35
+ __metadata("design:type", String)
36
+ ], Associates.prototype, "name", void 0);
37
+ __decorate([
38
+ (0, typeorm_1.ViewColumn)(),
39
+ __metadata("design:type", String)
40
+ ], Associates.prototype, "surname", void 0);
41
+ __decorate([
42
+ (0, typeorm_1.ViewColumn)(),
43
+ __metadata("design:type", String)
44
+ ], Associates.prototype, "full_name", void 0);
45
+ __decorate([
46
+ (0, typeorm_1.ViewColumn)(),
47
+ __metadata("design:type", String)
48
+ ], Associates.prototype, "email", void 0);
49
+ __decorate([
50
+ (0, typeorm_1.ViewColumn)(),
51
+ __metadata("design:type", String)
52
+ ], Associates.prototype, "phone", void 0);
53
+ __decorate([
54
+ (0, typeorm_1.ViewColumn)(),
55
+ __metadata("design:type", String)
56
+ ], Associates.prototype, "address", void 0);
57
+ __decorate([
58
+ (0, typeorm_1.ViewColumn)(),
59
+ __metadata("design:type", Object)
60
+ ], Associates.prototype, "details", void 0);
61
+ __decorate([
62
+ (0, typeorm_1.ViewColumn)(),
63
+ __metadata("design:type", Date)
64
+ ], Associates.prototype, "created", void 0);
65
+ __decorate([
66
+ (0, typeorm_1.ViewColumn)(),
67
+ __metadata("design:type", Date)
68
+ ], Associates.prototype, "updated", void 0);
69
+ __decorate([
70
+ (0, typeorm_1.ViewColumn)(),
71
+ __metadata("design:type", Number)
72
+ ], Associates.prototype, "owner", void 0);
73
+ __decorate([
74
+ (0, typeorm_1.ViewColumn)(),
75
+ __metadata("design:type", Number)
76
+ ], Associates.prototype, "status", void 0);
77
+ __decorate([
78
+ (0, typeorm_1.ViewColumn)(),
79
+ __metadata("design:type", Number)
80
+ ], Associates.prototype, "visible", void 0);
81
+ __decorate([
82
+ (0, typeorm_1.ViewColumn)(),
83
+ __metadata("design:type", Number)
84
+ ], Associates.prototype, "city_id", void 0);
85
+ __decorate([
86
+ (0, typeorm_1.ViewColumn)(),
87
+ __metadata("design:type", String)
88
+ ], Associates.prototype, "city_name", void 0);
89
+ __decorate([
90
+ (0, typeorm_1.ViewColumn)(),
91
+ __metadata("design:type", Number)
92
+ ], Associates.prototype, "city_region", void 0);
93
+ __decorate([
94
+ (0, typeorm_1.ViewColumn)(),
95
+ __metadata("design:type", Number)
96
+ ], Associates.prototype, "city_status", void 0);
97
+ exports.Associates = Associates = __decorate([
98
+ (0, typeorm_1.ViewEntity)()
99
+ ], Associates);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asumano/worklip-typeorm-db",
3
- "version": "1.1.3",
3
+ "version": "1.1.4",
4
4
  "publishConfig": {
5
5
  "access": "restricted"
6
6
  },