@consolidador-com/tad-nest-module 0.1.2 → 0.1.3
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/tad.core.d.ts +27 -0
- package/dist/tad.core.d.ts.map +1 -0
- package/dist/tad.core.js +196 -0
- package/dist/tad.core.js.map +1 -0
- package/dist/tad.module.d.ts +2 -2
- package/dist/tad.service.d.ts +7 -24
- package/dist/tad.service.d.ts.map +1 -1
- package/dist/tad.service.js +10 -168
- package/dist/tad.service.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { FindOptionsWhere, ObjectLiteral, Repository } from "typeorm";
|
|
2
|
+
import { ResponseTad, tadBundleT, tadColumns, tadDataFilterObject, tadDataFilterT, tadMetadata } from "./types/tad.types";
|
|
3
|
+
import * as ExcelJS from "exceljs";
|
|
4
|
+
import { AxiosInstance } from "axios";
|
|
5
|
+
import { TadOptions } from "./interface";
|
|
6
|
+
import { TadSearchDTO } from "./dto/tad-search.dto";
|
|
7
|
+
type findSchema<T extends ObjectLiteral> = {
|
|
8
|
+
list: T[];
|
|
9
|
+
totalItems: number;
|
|
10
|
+
totalPages: number;
|
|
11
|
+
};
|
|
12
|
+
export declare class TadCore {
|
|
13
|
+
private readonly options;
|
|
14
|
+
constructor(options: TadOptions);
|
|
15
|
+
createTad<T extends ObjectLiteral>(repo: Repository<T>, filters: tadDataFilterT<T>[], columns: tadColumns<T>[], dataSearch: TadSearchDTO<T>, fileExport?: boolean): Promise<ResponseTad<T> | ExcelJS.Buffer>;
|
|
16
|
+
createTadByApi<T extends ObjectLiteral>(api: AxiosInstance, dataSearch: TadSearchDTO<T>, fileExport?: boolean): Promise<ResponseTad<T> | ExcelJS.Buffer>;
|
|
17
|
+
find<T extends ObjectLiteral>(repo: Repository<T>, where: FindOptionsWhere<T>, dataSearch: TadSearchDTO<T>, columns: tadColumns<T>[]): Promise<findSchema<T>>;
|
|
18
|
+
createBundleFunction(fileExport: boolean): (bundle: tadBundleT) => string;
|
|
19
|
+
createFileExport<T extends ObjectLiteral>(metadata: tadMetadata<T>, rows: T[]): Promise<ExcelJS.Buffer>;
|
|
20
|
+
filterToWhere<T extends ObjectLiteral>(filters: tadDataFilterT<T>[], dataSearch: TadSearchDTO<T>): {
|
|
21
|
+
where: FindOptionsWhere<T>;
|
|
22
|
+
filtersObject: tadDataFilterObject<T>;
|
|
23
|
+
};
|
|
24
|
+
formatColumns<T extends ObjectLiteral>(columns: tadColumns<T>[], list: T[]): void;
|
|
25
|
+
}
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=tad.core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tad.core.d.ts","sourceRoot":"","sources":["../src/tad.core.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,gBAAgB,EAKhB,aAAa,EACb,UAAU,EACX,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,WAAW,EACX,UAAU,EAEV,UAAU,EAEV,mBAAmB,EAEnB,cAAc,EACd,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAE3B,OAAO,KAAK,OAAO,MAAM,SAAS,CAAC;AACnC,OAAO,EAAE,aAAa,EAAiB,MAAM,OAAO,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAMpD,KAAK,UAAU,CAAC,CAAC,SAAS,aAAa,IAAI;IACzC,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAyDF,qBAAa,OAAO;IACN,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAAP,OAAO,EAAE,UAAU;IAC1C,SAAS,CAAC,CAAC,SAAS,aAAa,EACrC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,EACnB,OAAO,EAAE,cAAc,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TadCore = void 0;
|
|
4
|
+
const typeorm_1 = require("typeorm");
|
|
5
|
+
const tad_types_1 = require("./types/tad.types");
|
|
6
|
+
const moment = require("moment");
|
|
7
|
+
const ExcelJS = require("exceljs");
|
|
8
|
+
function getTadDataFiltersFunctions() {
|
|
9
|
+
const WhereDateTimeRange = (key, v) => {
|
|
10
|
+
const dates = v.split(",");
|
|
11
|
+
let dateFrom = false;
|
|
12
|
+
let dateTo = false;
|
|
13
|
+
if (dates[0])
|
|
14
|
+
dateFrom = moment(dates[0]).toDate() || false;
|
|
15
|
+
// if (dates[1]) dateTo = moment(dates[1]).add('1 day').toDate() || false usar na consulta de Dates
|
|
16
|
+
if (dates[1])
|
|
17
|
+
dateTo = moment(dates[1]).toDate() || false;
|
|
18
|
+
if (dateFrom && dateTo) {
|
|
19
|
+
return { [key]: (0, typeorm_1.Between)(dateFrom, dateTo) };
|
|
20
|
+
}
|
|
21
|
+
else if (dateFrom) {
|
|
22
|
+
return { [key]: (0, typeorm_1.MoreThanOrEqual)(dateFrom) };
|
|
23
|
+
}
|
|
24
|
+
else if (dateTo) {
|
|
25
|
+
return { [key]: (0, typeorm_1.LessThanOrEqual)(dateTo) };
|
|
26
|
+
}
|
|
27
|
+
return {};
|
|
28
|
+
};
|
|
29
|
+
return {
|
|
30
|
+
[tad_types_1.tadDataFiltersEnum.STRING]: (key, v) => ({ [key]: (0, typeorm_1.Like)(`%${v}%`) }),
|
|
31
|
+
[tad_types_1.tadDataFiltersEnum.SELECT_SINGLE]: (key, v) => ({ [key]: v }),
|
|
32
|
+
[tad_types_1.tadDataFiltersEnum.SELECT_MULTIPLE]: (key, v) => ({ [key]: (0, typeorm_1.In)(v.split(",")) }),
|
|
33
|
+
[tad_types_1.tadDataFiltersEnum.NUMBER]: (key, v) => ({ [key]: v }),
|
|
34
|
+
[tad_types_1.tadDataFiltersEnum.NUMBER_RANGE]: (key, v) => ({
|
|
35
|
+
[key]: (0, typeorm_1.Between)(v.split(",")[0], v.split(",")[1]),
|
|
36
|
+
}),
|
|
37
|
+
[tad_types_1.tadDataFiltersEnum.DATE]: (key, v) => ({
|
|
38
|
+
[key]: (0, typeorm_1.Between)(moment(v).toDate(), moment(v).add("1 day").toDate()),
|
|
39
|
+
}),
|
|
40
|
+
[tad_types_1.tadDataFiltersEnum.DATETIME]: (key, v) => ({
|
|
41
|
+
[key]: (0, typeorm_1.Between)(moment(v).toDate(), moment(v).add("1 day").toDate()),
|
|
42
|
+
}),
|
|
43
|
+
[tad_types_1.tadDataFiltersEnum.DATE_RANGE]: (key, v) => ({
|
|
44
|
+
[key]: (0, typeorm_1.Between)(moment(v.split(",")[0]).toDate(), moment(v.split(",")[1]).add("1 day").toDate()),
|
|
45
|
+
}),
|
|
46
|
+
[tad_types_1.tadDataFiltersEnum.DATETIME_RANGE]: WhereDateTimeRange,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
class TadCore {
|
|
50
|
+
constructor(options) {
|
|
51
|
+
this.options = options;
|
|
52
|
+
}
|
|
53
|
+
async createTad(repo, filters, columns, dataSearch, fileExport = false) {
|
|
54
|
+
if (fileExport) {
|
|
55
|
+
dataSearch.itemsPerPage = 999999;
|
|
56
|
+
dataSearch.page = 0;
|
|
57
|
+
columns = columns.filter((col) => col.fileExport !== false);
|
|
58
|
+
}
|
|
59
|
+
const { where, filtersObject } = this.filterToWhere(filters, dataSearch);
|
|
60
|
+
const { list, totalPages, totalItems } = await this.find(repo, where, dataSearch, columns);
|
|
61
|
+
this.formatColumns(columns, list);
|
|
62
|
+
const metadata = {
|
|
63
|
+
columns,
|
|
64
|
+
filters: filtersObject,
|
|
65
|
+
totalItems,
|
|
66
|
+
totalPages,
|
|
67
|
+
sort: dataSearch.sort,
|
|
68
|
+
page: dataSearch.page,
|
|
69
|
+
itemsPerPage: dataSearch.itemsPerPage,
|
|
70
|
+
filter: dataSearch.filter,
|
|
71
|
+
};
|
|
72
|
+
if (fileExport)
|
|
73
|
+
return await this.createFileExport(metadata, list); // returns Excel File
|
|
74
|
+
return { metadata, rows: list }; // returns responseTad
|
|
75
|
+
}
|
|
76
|
+
async createTadByApi(api, dataSearch, fileExport = false) {
|
|
77
|
+
if (fileExport) {
|
|
78
|
+
dataSearch.itemsPerPage = 10000;
|
|
79
|
+
dataSearch.page = 0;
|
|
80
|
+
}
|
|
81
|
+
const data = await api
|
|
82
|
+
.post("", dataSearch)
|
|
83
|
+
.then((response) => {
|
|
84
|
+
return response.data;
|
|
85
|
+
})
|
|
86
|
+
.catch((error) => {
|
|
87
|
+
throw new Error(" Falha no consumo da API de Integração.");
|
|
88
|
+
});
|
|
89
|
+
if (fileExport)
|
|
90
|
+
return await this.createFileExport(data.metadata, data.rows); // returns Excel File
|
|
91
|
+
return data; // returns responseTad
|
|
92
|
+
}
|
|
93
|
+
async find(repo, where, dataSearch, columns) {
|
|
94
|
+
const skip = dataSearch.page
|
|
95
|
+
? (dataSearch.page - 1) * dataSearch.itemsPerPage
|
|
96
|
+
: 0;
|
|
97
|
+
const select = columns.map((col) => col.key);
|
|
98
|
+
const list = await repo.find({
|
|
99
|
+
select,
|
|
100
|
+
skip,
|
|
101
|
+
take: dataSearch.itemsPerPage || undefined,
|
|
102
|
+
where,
|
|
103
|
+
order: dataSearch.sort,
|
|
104
|
+
});
|
|
105
|
+
const total = await repo.count({ where });
|
|
106
|
+
const totalPages = Math.ceil(total / dataSearch.itemsPerPage);
|
|
107
|
+
return {
|
|
108
|
+
list,
|
|
109
|
+
totalItems: total,
|
|
110
|
+
totalPages,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
createBundleFunction(fileExport) {
|
|
114
|
+
const bundleFunc = (bundle) => {
|
|
115
|
+
if (fileExport === true)
|
|
116
|
+
return bundle.text || "";
|
|
117
|
+
return JSON.stringify(bundle);
|
|
118
|
+
};
|
|
119
|
+
return bundleFunc;
|
|
120
|
+
}
|
|
121
|
+
async createFileExport(metadata, rows) {
|
|
122
|
+
// Criar workbook
|
|
123
|
+
const workbook = new ExcelJS.Workbook();
|
|
124
|
+
const worksheet = workbook.addWorksheet("Reports");
|
|
125
|
+
worksheet.columns = metadata.columns.map((col) => ({
|
|
126
|
+
header: col.label,
|
|
127
|
+
key: col.key,
|
|
128
|
+
width: 30,
|
|
129
|
+
}));
|
|
130
|
+
rows.forEach((report) => {
|
|
131
|
+
const row = {};
|
|
132
|
+
metadata.columns.forEach((col) => {
|
|
133
|
+
const value = report[col.key];
|
|
134
|
+
// Formatar data se necessário (type guard)
|
|
135
|
+
if (col.cellType === tad_types_1.tadCellType.DATE_TIME &&
|
|
136
|
+
value !== null &&
|
|
137
|
+
value !== undefined &&
|
|
138
|
+
Object.prototype.toString.call(value) === "[object Date]") {
|
|
139
|
+
row[col.key] = moment(value).format("DD/MM/YYYY HH:mm:ss");
|
|
140
|
+
}
|
|
141
|
+
else if (typeof value === "string" ||
|
|
142
|
+
typeof value === "number" ||
|
|
143
|
+
value === null ||
|
|
144
|
+
value === undefined) {
|
|
145
|
+
row[col.key] = value;
|
|
146
|
+
}
|
|
147
|
+
else if (typeof value === "boolean") {
|
|
148
|
+
row[col.key] = value ? "Yes" : "No";
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
// Para outros tipos (objects, etc), converter para string
|
|
152
|
+
row[col.key] = String(value);
|
|
153
|
+
}
|
|
154
|
+
// source: report.source ? `${report.source.carrier} - ${report.source.loginData?.agency || 'N/A'}` : 'N/A',
|
|
155
|
+
});
|
|
156
|
+
worksheet.addRow(row);
|
|
157
|
+
});
|
|
158
|
+
worksheet.getRow(1).eachCell((cell) => {
|
|
159
|
+
cell.font = { bold: true };
|
|
160
|
+
cell.fill = {
|
|
161
|
+
type: "pattern",
|
|
162
|
+
pattern: "solid",
|
|
163
|
+
fgColor: { argb: "FFE0E0E0" },
|
|
164
|
+
};
|
|
165
|
+
});
|
|
166
|
+
const buffer = await workbook.xlsx.writeBuffer();
|
|
167
|
+
return buffer;
|
|
168
|
+
}
|
|
169
|
+
filterToWhere(filters, dataSearch) {
|
|
170
|
+
const filtersObject = filters.reduce((pv, cv) => ({ ...pv, [cv.key]: cv }), {});
|
|
171
|
+
const TadDataFiltersFunctions = getTadDataFiltersFunctions();
|
|
172
|
+
const where = {};
|
|
173
|
+
Object.entries(dataSearch.filter).forEach(([k, v]) => {
|
|
174
|
+
const whereFilter = TadDataFiltersFunctions[filtersObject[k].typeFilter](k, v);
|
|
175
|
+
Object.assign(where, whereFilter);
|
|
176
|
+
});
|
|
177
|
+
return {
|
|
178
|
+
where,
|
|
179
|
+
filtersObject,
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
formatColumns(columns, list) {
|
|
183
|
+
const filterColumns = columns.filter((el) => el.format);
|
|
184
|
+
filterColumns.forEach((col) => {
|
|
185
|
+
if (list[0] && col.key in list[0]) {
|
|
186
|
+
list.forEach((item) => {
|
|
187
|
+
if (col.format) {
|
|
188
|
+
item[col.key] = col.format(item[col.key], item);
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
exports.TadCore = TadCore;
|
|
196
|
+
//# sourceMappingURL=tad.core.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tad.core.js","sourceRoot":"","sources":["../src/tad.core.ts"],"names":[],"mappings":";;;AAAA,qCASiB;AACjB,iDAU2B;AAC3B,iCAAiC;AACjC,mCAAmC;AAcnC,SAAS,0BAA0B;IAIjC,MAAM,kBAAkB,GAA0B,CAChD,GAAG,EACH,CAAC,EACoB,EAAE;QACvB,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC3B,IAAI,QAAQ,GAAiB,KAAK,CAAC;QACnC,IAAI,MAAM,GAAiB,KAAK,CAAC;QACjC,IAAI,KAAK,CAAC,CAAC,CAAC;YAAE,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,IAA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GAAG,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,IAAI,CAAe,CAAC;oBAChE,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAhMD,0BAgMC"}
|
package/dist/tad.module.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DynamicModule } from
|
|
2
|
-
import { TadOptions } from
|
|
1
|
+
import { DynamicModule } from "@nestjs/common";
|
|
2
|
+
import { TadOptions } from "./interface";
|
|
3
3
|
export declare class TadModule {
|
|
4
4
|
static forRoot(options: TadOptions): DynamicModule;
|
|
5
5
|
static forRootAsync(options: {
|
package/dist/tad.service.d.ts
CHANGED
|
@@ -1,27 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
type findSchema<T extends ObjectLiteral> = {
|
|
8
|
-
list: T[];
|
|
9
|
-
totalItems: number;
|
|
10
|
-
totalPages: number;
|
|
11
|
-
};
|
|
12
|
-
export declare class TadService {
|
|
13
|
-
private readonly options;
|
|
1
|
+
import { TadCore } from "./tad.core";
|
|
2
|
+
import { TadOptions } from "./interface";
|
|
3
|
+
import { AxiosInstance } from "axios";
|
|
4
|
+
import { TadSearchDTO } from "./dto/tad-search.dto";
|
|
5
|
+
import { ObjectLiteral } from "typeorm";
|
|
6
|
+
export declare class TadService extends TadCore {
|
|
14
7
|
constructor(options: TadOptions);
|
|
15
|
-
|
|
16
|
-
createTadByApi<T extends ObjectLiteral>(api: AxiosInstance, dataSearch: TadSearchDTO<T>, fileExport?: boolean): Promise<ResponseTad<T> | ExcelJS.Buffer>;
|
|
17
|
-
find<T extends ObjectLiteral>(repo: Repository<T>, where: FindOptionsWhere<T>, dataSearch: TadSearchDTO<T>, columns: tadColumns<T>[]): Promise<findSchema<T>>;
|
|
18
|
-
createBundleFunction(fileExport: boolean): (bundle: tadBundleT) => string;
|
|
19
|
-
createFileExport<T extends ObjectLiteral>(metadata: tadMetadata<T>, rows: T[]): Promise<ExcelJS.Buffer>;
|
|
20
|
-
filterToWhere<T extends ObjectLiteral>(filters: tadDataFilterT<T>[], dataSearch: TadSearchDTO<T>): {
|
|
21
|
-
where: FindOptionsWhere<T>;
|
|
22
|
-
filtersObject: tadDataFilterObject<T>;
|
|
23
|
-
};
|
|
24
|
-
formatColumns<T extends ObjectLiteral>(columns: tadColumns<T>[], list: T[]): void;
|
|
8
|
+
createTadByApi<T extends ObjectLiteral>(api: AxiosInstance, dataSearch: TadSearchDTO<T>, fileExport?: boolean): Promise<import("exceljs").Buffer | import("./types/tad.types").ResponseTad<T>>;
|
|
25
9
|
}
|
|
26
|
-
export {};
|
|
27
10
|
//# sourceMappingURL=tad.service.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tad.service.d.ts","sourceRoot":"","sources":["../src/tad.service.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tad.service.d.ts","sourceRoot":"","sources":["../src/tad.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC,qBACa,UAAW,SAAQ,OAAO;gBACJ,OAAO,EAAE,UAAU;IAKrC,cAAc,CAAC,CAAC,SAAS,aAAa,EACnD,GAAG,EAAE,aAAa,EAClB,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC,EAC3B,UAAU,GAAE,OAAe;CAQ9B"}
|
package/dist/tad.service.js
CHANGED
|
@@ -13,179 +13,21 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.TadService = void 0;
|
|
16
|
-
const tokens_1 = require("./tokens");
|
|
17
16
|
const common_1 = require("@nestjs/common");
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
const ExcelJS = require("exceljs");
|
|
22
|
-
function getTadDataFiltersFunctions() {
|
|
23
|
-
const WhereDateTimeRange = (key, v) => {
|
|
24
|
-
const dates = v.split(',');
|
|
25
|
-
let dateFrom = false;
|
|
26
|
-
let dateTo = false;
|
|
27
|
-
if (dates[0])
|
|
28
|
-
dateFrom = moment(dates[0]).toDate() || false;
|
|
29
|
-
// if (dates[1]) dateTo = moment(dates[1]).add('1 day').toDate() || false usar na consulta de Dates
|
|
30
|
-
if (dates[1])
|
|
31
|
-
dateTo = moment(dates[1]).toDate() || false;
|
|
32
|
-
if (dateFrom && dateTo) {
|
|
33
|
-
return { [key]: (0, typeorm_1.Between)(dateFrom, dateTo) };
|
|
34
|
-
}
|
|
35
|
-
else if (dateFrom) {
|
|
36
|
-
return { [key]: (0, typeorm_1.MoreThanOrEqual)(dateFrom) };
|
|
37
|
-
}
|
|
38
|
-
else if (dateTo) {
|
|
39
|
-
return { [key]: (0, typeorm_1.LessThanOrEqual)(dateTo) };
|
|
40
|
-
}
|
|
41
|
-
return {};
|
|
42
|
-
};
|
|
43
|
-
return {
|
|
44
|
-
[tad_types_1.tadDataFiltersEnum.STRING]: (key, v) => ({ [key]: (0, typeorm_1.Like)(`%${v}%`) }),
|
|
45
|
-
[tad_types_1.tadDataFiltersEnum.SELECT_SINGLE]: (key, v) => ({ [key]: v }),
|
|
46
|
-
[tad_types_1.tadDataFiltersEnum.SELECT_MULTIPLE]: (key, v) => ({ [key]: (0, typeorm_1.In)(v.split(',')) }),
|
|
47
|
-
[tad_types_1.tadDataFiltersEnum.NUMBER]: (key, v) => ({ [key]: v }),
|
|
48
|
-
[tad_types_1.tadDataFiltersEnum.NUMBER_RANGE]: (key, v) => ({ [key]: (0, typeorm_1.Between)(v.split(',')[0], v.split(',')[1]) }),
|
|
49
|
-
[tad_types_1.tadDataFiltersEnum.DATE]: (key, v) => ({ [key]: (0, typeorm_1.Between)(moment(v).toDate(), moment(v).add('1 day').toDate()) }),
|
|
50
|
-
[tad_types_1.tadDataFiltersEnum.DATETIME]: (key, v) => ({ [key]: (0, typeorm_1.Between)(moment(v).toDate(), moment(v).add('1 day').toDate()) }),
|
|
51
|
-
[tad_types_1.tadDataFiltersEnum.DATE_RANGE]: (key, v) => ({ [key]: (0, typeorm_1.Between)(moment(v.split(',')[0]).toDate(), moment(v.split(',')[1]).add('1 day').toDate()) }),
|
|
52
|
-
[tad_types_1.tadDataFiltersEnum.DATETIME_RANGE]: WhereDateTimeRange,
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
let TadService = class TadService {
|
|
17
|
+
const tad_core_1 = require("./tad.core");
|
|
18
|
+
const tokens_1 = require("./tokens");
|
|
19
|
+
let TadService = class TadService extends tad_core_1.TadCore {
|
|
56
20
|
constructor(options) {
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
async createTad(repo, filters, columns, dataSearch, fileExport = false) {
|
|
60
|
-
if (fileExport) {
|
|
61
|
-
dataSearch.itemsPerPage = 999999;
|
|
62
|
-
dataSearch.page = 0;
|
|
63
|
-
columns = columns.filter((col) => col.fileExport !== false);
|
|
64
|
-
}
|
|
65
|
-
const { where, filtersObject } = this.filterToWhere(filters, dataSearch);
|
|
66
|
-
const { list, totalPages, totalItems } = await this.find(repo, where, dataSearch, columns);
|
|
67
|
-
this.formatColumns(columns, list);
|
|
68
|
-
const metadata = {
|
|
69
|
-
columns,
|
|
70
|
-
filters: filtersObject,
|
|
71
|
-
totalItems,
|
|
72
|
-
totalPages,
|
|
73
|
-
sort: dataSearch.sort,
|
|
74
|
-
page: dataSearch.page,
|
|
75
|
-
itemsPerPage: dataSearch.itemsPerPage,
|
|
76
|
-
filter: dataSearch.filter,
|
|
77
|
-
};
|
|
78
|
-
if (fileExport)
|
|
79
|
-
return await this.createFileExport(metadata, list); // returns Excel File
|
|
80
|
-
return { metadata, rows: list }; // returns responseTad
|
|
21
|
+
super(options);
|
|
81
22
|
}
|
|
23
|
+
// opcional: “traduzir” erros do core para HTTP do Nest
|
|
82
24
|
async createTadByApi(api, dataSearch, fileExport = false) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
25
|
+
try {
|
|
26
|
+
return await super.createTadByApi(api, dataSearch, fileExport);
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
throw new common_1.BadRequestException(e?.message ?? "Falha na API.");
|
|
86
30
|
}
|
|
87
|
-
const data = await api.post('', dataSearch)
|
|
88
|
-
.then((response) => {
|
|
89
|
-
return response.data;
|
|
90
|
-
}).catch((error) => {
|
|
91
|
-
throw new common_1.BadRequestException(' Falha no consumo da API de Integração.');
|
|
92
|
-
});
|
|
93
|
-
if (fileExport)
|
|
94
|
-
return await this.createFileExport(data.metadata, data.rows); // returns Excel File
|
|
95
|
-
return data; // returns responseTad
|
|
96
|
-
}
|
|
97
|
-
async find(repo, where, dataSearch, columns) {
|
|
98
|
-
const skip = dataSearch.page ? (dataSearch.page - 1) * dataSearch.itemsPerPage : 0;
|
|
99
|
-
const select = columns.map((col) => col.key);
|
|
100
|
-
const list = await repo.find({
|
|
101
|
-
select,
|
|
102
|
-
skip,
|
|
103
|
-
take: dataSearch.itemsPerPage || undefined,
|
|
104
|
-
where,
|
|
105
|
-
order: dataSearch.sort,
|
|
106
|
-
});
|
|
107
|
-
const total = await repo.count({ where });
|
|
108
|
-
const totalPages = Math.ceil(total / dataSearch.itemsPerPage);
|
|
109
|
-
return {
|
|
110
|
-
list,
|
|
111
|
-
totalItems: total,
|
|
112
|
-
totalPages,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
createBundleFunction(fileExport) {
|
|
116
|
-
const bundleFunc = (bundle) => {
|
|
117
|
-
if (fileExport === true)
|
|
118
|
-
return bundle.text || '';
|
|
119
|
-
return JSON.stringify(bundle);
|
|
120
|
-
};
|
|
121
|
-
return bundleFunc;
|
|
122
|
-
}
|
|
123
|
-
async createFileExport(metadata, rows) {
|
|
124
|
-
// Criar workbook
|
|
125
|
-
const workbook = new ExcelJS.Workbook();
|
|
126
|
-
const worksheet = workbook.addWorksheet('Reports');
|
|
127
|
-
worksheet.columns = metadata.columns.map((col) => ({
|
|
128
|
-
header: col.label,
|
|
129
|
-
key: col.key,
|
|
130
|
-
width: 30,
|
|
131
|
-
}));
|
|
132
|
-
rows.forEach((report) => {
|
|
133
|
-
const row = {};
|
|
134
|
-
metadata.columns.forEach((col) => {
|
|
135
|
-
const value = report[col.key];
|
|
136
|
-
// Formatar data se necessário (type guard)
|
|
137
|
-
if (col.cellType === tad_types_1.tadCellType.DATE_TIME && value !== null && value !== undefined && Object.prototype.toString.call(value) === '[object Date]') {
|
|
138
|
-
row[col.key] = moment(value).format('DD/MM/YYYY HH:mm:ss');
|
|
139
|
-
}
|
|
140
|
-
else if (typeof value === 'string' || typeof value === 'number' || value === null || value === undefined) {
|
|
141
|
-
row[col.key] = value;
|
|
142
|
-
}
|
|
143
|
-
else if (typeof value === 'boolean') {
|
|
144
|
-
row[col.key] = value ? 'Yes' : 'No';
|
|
145
|
-
}
|
|
146
|
-
else {
|
|
147
|
-
// Para outros tipos (objects, etc), converter para string
|
|
148
|
-
row[col.key] = String(value);
|
|
149
|
-
}
|
|
150
|
-
// source: report.source ? `${report.source.carrier} - ${report.source.loginData?.agency || 'N/A'}` : 'N/A',
|
|
151
|
-
});
|
|
152
|
-
worksheet.addRow(row);
|
|
153
|
-
});
|
|
154
|
-
worksheet.getRow(1).eachCell((cell) => {
|
|
155
|
-
cell.font = { bold: true };
|
|
156
|
-
cell.fill = {
|
|
157
|
-
type: 'pattern',
|
|
158
|
-
pattern: 'solid',
|
|
159
|
-
fgColor: { argb: 'FFE0E0E0' },
|
|
160
|
-
};
|
|
161
|
-
});
|
|
162
|
-
const buffer = await workbook.xlsx.writeBuffer();
|
|
163
|
-
return buffer;
|
|
164
|
-
}
|
|
165
|
-
filterToWhere(filters, dataSearch) {
|
|
166
|
-
const filtersObject = filters.reduce((pv, cv) => ({ ...pv, [cv.key]: cv }), {});
|
|
167
|
-
const TadDataFiltersFunctions = getTadDataFiltersFunctions();
|
|
168
|
-
const where = {};
|
|
169
|
-
Object.entries(dataSearch.filter).forEach(([k, v]) => {
|
|
170
|
-
const whereFilter = TadDataFiltersFunctions[filtersObject[k].typeFilter](k, v);
|
|
171
|
-
Object.assign(where, whereFilter);
|
|
172
|
-
});
|
|
173
|
-
return {
|
|
174
|
-
where,
|
|
175
|
-
filtersObject
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
formatColumns(columns, list) {
|
|
179
|
-
const filterColumns = columns.filter((el) => el.format);
|
|
180
|
-
filterColumns.forEach((col) => {
|
|
181
|
-
if (list[0] && col.key in list[0]) {
|
|
182
|
-
list.forEach((item) => {
|
|
183
|
-
if (col.format) {
|
|
184
|
-
item[col.key] = col.format(item[col.key], item);
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
});
|
|
189
31
|
}
|
|
190
32
|
};
|
|
191
33
|
exports.TadService = TadService;
|
package/dist/tad.service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tad.service.js","sourceRoot":"","sources":["../src/tad.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"tad.service.js","sourceRoot":"","sources":["../src/tad.service.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAAyE;AACzE,yCAAqC;AACrC,qCAAuC;AAOhC,IAAM,UAAU,GAAhB,MAAM,UAAW,SAAQ,kBAAO;IACrC,YAAiC,OAAmB;QAClD,KAAK,CAAC,OAAO,CAAC,CAAC;IACjB,CAAC;IAED,uDAAuD;IAC9C,KAAK,CAAC,cAAc,CAC3B,GAAkB,EAClB,UAA2B,EAC3B,aAAsB,KAAK;QAE3B,IAAI,CAAC;YACH,OAAO,MAAM,KAAK,CAAC,cAAc,CAAI,GAAG,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;QACpE,CAAC;QAAC,OAAO,CAAM,EAAE,CAAC;YAChB,MAAM,IAAI,4BAAmB,CAAC,CAAC,EAAE,OAAO,IAAI,eAAe,CAAC,CAAC;QAC/D,CAAC;IACH,CAAC;CACF,CAAA;AAjBY,gCAAU;qBAAV,UAAU;IADtB,IAAA,mBAAU,GAAE;IAEE,WAAA,IAAA,eAAM,EAAC,oBAAW,CAAC,CAAA;;GADrB,UAAU,CAiBtB"}
|