emilsoftware-utilities 1.3.6 → 1.3.8
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/{autobind.js → dist/autobind.js} +3 -4
- package/{log-execution-time.js → dist/log-execution-time.js} +3 -3
- package/{logger.d.ts → dist/logger.d.ts} +12 -3
- package/dist/logger.js +273 -0
- package/{orm.js → dist/orm.js} +2 -2
- package/{routes-logger.js → dist/routes-logger.js} +1 -2
- package/package.json +10 -4
- package/.idea/.name +0 -1
- package/.idea/emilsoftware-utilities.iml +0 -12
- package/.idea/inspectionProfiles/Project_Default.xml +0 -10
- package/.idea/modules.xml +0 -8
- package/.idea/vcs.xml +0 -6
- package/logger.js +0 -195
- package/src/autobind.ts +0 -93
- package/src/index.ts +0 -6
- package/src/log-execution-time.ts +0 -23
- package/src/logger.ts +0 -144
- package/src/node-firebird.ts +0 -1
- package/src/orm.ts +0 -221
- package/src/routes-logger.ts +0 -16
- package/src/utilities.ts +0 -194
- package/tsconfig.json +0 -16
- /package/{autobind.d.ts → dist/autobind.d.ts} +0 -0
- /package/{index.d.ts → dist/index.d.ts} +0 -0
- /package/{index.js → dist/index.js} +0 -0
- /package/{log-execution-time.d.ts → dist/log-execution-time.d.ts} +0 -0
- /package/{node-firebird.d.ts → dist/node-firebird.d.ts} +0 -0
- /package/{node-firebird.js → dist/node-firebird.js} +0 -0
- /package/{orm.d.ts → dist/orm.d.ts} +0 -0
- /package/{routes-logger.d.ts → dist/routes-logger.d.ts} +0 -0
- /package/{utilities.d.ts → dist/utilities.d.ts} +0 -0
- /package/{utilities.js → dist/utilities.js} +0 -0
package/src/utilities.ts
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
import {Response} from 'express';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
enum STATUS_CODE {
|
|
5
|
-
OK = 0, WARNING = 1, ERROR = 2,
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const parseDate = (date: string) => {
|
|
9
|
-
const parts: string[] = date.split("/");
|
|
10
|
-
return new Date(Number(parts[2]), Number(parts[1]) - 1, Number(parts[0]));
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const sendOKMessage = (res: Response, message: string): Response => {
|
|
14
|
-
return res.send({
|
|
15
|
-
severity: "success", status: 200, statusCode: STATUS_CODE.OK, message,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const getNowDateString = (): string => {
|
|
21
|
-
const now: Date = new Date();
|
|
22
|
-
const day: string | number = now.getDate() < 9 ? "0" + now.getDate() : now.getDate();
|
|
23
|
-
const month: string | number = (now.getMonth() + 1) < 9 ? "0" + (now.getMonth() + 1) : (now.getMonth() + 1);
|
|
24
|
-
const year: number = now.getFullYear();
|
|
25
|
-
const hours: string | number = now.getHours() < 9 ? "0" + now.getHours() : now.getHours();
|
|
26
|
-
const minutes: string | number = now.getMinutes() < 9 ? "0" + now.getMinutes() : now.getMinutes();
|
|
27
|
-
const seconds: string | number = now.getSeconds() < 9 ? "0" + now.getSeconds() : now.getSeconds();
|
|
28
|
-
return day + "." + month + "." + year + " " + hours + ":" + minutes + ":" + seconds;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
const sendErrorMessage = (res: Response, error: any, tag: string = "[BASE ERROR]", status: number = 500): Response => {
|
|
33
|
-
return res.status(status).send({
|
|
34
|
-
severity: "error",
|
|
35
|
-
status: 500,
|
|
36
|
-
statusCode: STATUS_CODE.ERROR,
|
|
37
|
-
message: " Si è verificato un errore",
|
|
38
|
-
error: tag + ": " + error,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const sendBaseResponse = (res: Response, payload: any): Response => {
|
|
43
|
-
try {
|
|
44
|
-
payload = JSON.parse(JSON.stringify(payload));
|
|
45
|
-
const clearPayload = payload; // this.keysToCamel(payload);
|
|
46
|
-
const response = {
|
|
47
|
-
Status: {
|
|
48
|
-
errorCode: "0", errorDescription: "",
|
|
49
|
-
}, Result: clearPayload, Message: ""
|
|
50
|
-
};
|
|
51
|
-
return res.send(response);
|
|
52
|
-
} catch (error) {
|
|
53
|
-
return sendErrorMessage(res, "Errore nell'invio della risposta: " + error, "[UTILITIES]", 500);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const toCamel = (s: any) => {
|
|
59
|
-
return s.replace(/([-_][a-z])/gi, ($1: string) => {
|
|
60
|
-
return $1.toUpperCase().replace("-", "").replace("_", "");
|
|
61
|
-
});
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
const isArray = (a: any): boolean => {
|
|
65
|
-
return Array.isArray(a);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const isObject = (o: any): boolean => {
|
|
69
|
-
return o === Object(o) && !isArray(o) && typeof o !== "function";
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const keysToCamel = (o: any): any => {
|
|
74
|
-
if (isObject(o)) {
|
|
75
|
-
const n = {};
|
|
76
|
-
|
|
77
|
-
Object.keys(o).forEach((k: any) => {
|
|
78
|
-
// @ts-ignore
|
|
79
|
-
n[toCamel(k)] = keysToCamel(o[k]);
|
|
80
|
-
});
|
|
81
|
-
return n;
|
|
82
|
-
} else if (isArray(o)) {
|
|
83
|
-
return o.map((i: any) => {
|
|
84
|
-
return keysToCamel(i);
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
return o;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const addStartingZeros = (num: number, totalLength: number): string => {
|
|
92
|
-
return String(num).padStart(totalLength, '0');
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
const dateToMoncler = (dData: Date, bAddMs: boolean = false): string => {
|
|
96
|
-
const yy: number = dData.getFullYear();
|
|
97
|
-
const mm: string = addStartingZeros(dData.getMonth() + 1, 2);
|
|
98
|
-
const dd: string = addStartingZeros(dData.getDate(), 2);
|
|
99
|
-
const hh: string = addStartingZeros(dData.getHours(), 2);
|
|
100
|
-
const nn: string = addStartingZeros(dData.getMinutes(), 2);
|
|
101
|
-
const ss: string = addStartingZeros(dData.getSeconds(), 2);
|
|
102
|
-
const ms: string = addStartingZeros(dData.getMilliseconds(), 3);
|
|
103
|
-
if (bAddMs) {
|
|
104
|
-
return yy + mm + dd + hh + nn + ss + ms;
|
|
105
|
-
} else {
|
|
106
|
-
return yy + mm + dd + hh + nn + ss;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const dateToSql = (dData: Date, bAddMs: boolean = false): string => {
|
|
111
|
-
const yy: number = dData.getFullYear();
|
|
112
|
-
const mm: string = addStartingZeros(dData.getMonth() + 1, 2);
|
|
113
|
-
const dd: string = addStartingZeros(dData.getDate(), 2);
|
|
114
|
-
const hh: string = addStartingZeros(dData.getHours(), 2);
|
|
115
|
-
const nn: string = addStartingZeros(dData.getMinutes(), 2);
|
|
116
|
-
const ss: string = addStartingZeros(dData.getSeconds(), 2);
|
|
117
|
-
const ms: string = addStartingZeros(dData.getMilliseconds(), 3);
|
|
118
|
-
if (bAddMs) {
|
|
119
|
-
return yy + '-' + mm + '-' + dd + ' ' + hh + ':' + nn + ':' + ss + '.' + ms;
|
|
120
|
-
} else {
|
|
121
|
-
return yy + '-' + mm + '-' + dd + ' ' + hh + ':' + nn + ':' + ss;
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const dateToSimple = (dData: Date): string => {
|
|
127
|
-
const yy: number = dData.getFullYear();
|
|
128
|
-
const mm: string = addStartingZeros(dData.getMonth() + 1, 2);
|
|
129
|
-
const dd: string = addStartingZeros(dData.getDate(), 2);
|
|
130
|
-
return dd + '-' + mm + '-' + yy;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const sendExecMessage = (res: Response, executionObject: any, title: string): Response => {
|
|
134
|
-
try {
|
|
135
|
-
let sSql = "";
|
|
136
|
-
let response = {
|
|
137
|
-
Status: {
|
|
138
|
-
errorCode: "0", errorDescription: "",
|
|
139
|
-
}, Sql: sSql, ID: executionObject?.id, data: executionObject, Title: title
|
|
140
|
-
};
|
|
141
|
-
return res.send(response);
|
|
142
|
-
} catch (error) {
|
|
143
|
-
return sendErrorMessage(res, "Errore nell'invio della risposta: " + error, title, 500);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
const printQueryWithParams = (query: string = "", params: any[]): string => {
|
|
148
|
-
try {
|
|
149
|
-
params.forEach(param => {
|
|
150
|
-
query = query.replace("?", param);
|
|
151
|
-
});
|
|
152
|
-
return query;
|
|
153
|
-
} catch (error) {
|
|
154
|
-
throw error;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
interface Utilities {
|
|
160
|
-
parseDate: (date: string) => Date,
|
|
161
|
-
printQueryWithParams: (query: string, params: any[]) => string,
|
|
162
|
-
sendOKMessage: (res: Response, message: string) => Response,
|
|
163
|
-
sendExecMessage: (res: Response, executionObject: any, title: string) => Response,
|
|
164
|
-
getNowDateString: () => {},
|
|
165
|
-
sendErrorMessage: (res: Response, error: any, tag?: string, status?: number) => Response,
|
|
166
|
-
sendBaseResponse: (res: Response, payload: any) => Response,
|
|
167
|
-
toCamel: (s: any) => any,
|
|
168
|
-
isArray: (a: any) => boolean,
|
|
169
|
-
isObject: (o: any) => boolean,
|
|
170
|
-
keysToCamel: (o: any) => any,
|
|
171
|
-
addStartingZeros: (num: number, totalLength: number) => string,
|
|
172
|
-
dateToMoncler: (dData: Date, bAddMs?: boolean) => string,
|
|
173
|
-
dateToSql: (dData: Date, bAddMs?: boolean) => string,
|
|
174
|
-
dateToSimple: (dData: Date) => string
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export const Utilities: Utilities = {
|
|
178
|
-
parseDate,
|
|
179
|
-
printQueryWithParams,
|
|
180
|
-
sendOKMessage,
|
|
181
|
-
sendExecMessage,
|
|
182
|
-
getNowDateString,
|
|
183
|
-
sendErrorMessage,
|
|
184
|
-
sendBaseResponse,
|
|
185
|
-
toCamel,
|
|
186
|
-
isArray,
|
|
187
|
-
isObject,
|
|
188
|
-
keysToCamel,
|
|
189
|
-
addStartingZeros,
|
|
190
|
-
dateToMoncler,
|
|
191
|
-
dateToSql,
|
|
192
|
-
dateToSimple
|
|
193
|
-
}
|
|
194
|
-
|
package/tsconfig.json
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|