test-entity-library-asm 1.9.4 → 1.9.6

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.
@@ -19,7 +19,7 @@ export declare class Partner {
19
19
  password: string;
20
20
  profile: any;
21
21
  owner: number;
22
- created: string;
22
+ created: Date;
23
23
  updated: Date;
24
24
  status: number;
25
25
  companies: Company[];
@@ -116,12 +116,13 @@ var Partner = /** @class */ (function () {
116
116
  comment: 'Fecha de creación del registro.',
117
117
  transformer: new dateTransformer_1.DateTransformer(),
118
118
  }),
119
- __metadata("design:type", String)
119
+ __metadata("design:type", Date)
120
120
  ], Partner.prototype, "created", void 0);
121
121
  __decorate([
122
122
  (0, typeorm_1.Column)({
123
123
  type: 'datetime',
124
124
  comment: 'Fecha de actualización del registro.',
125
+ transformer: new dateTransformer_1.DateTransformer(),
125
126
  }),
126
127
  __metadata("design:type", Date)
127
128
  ], Partner.prototype, "updated", void 0);
package/dist/index.js CHANGED
@@ -123,7 +123,6 @@ var async_hooks_1 = require("async_hooks");
123
123
  var asyncLocalStorage = new async_hooks_1.AsyncLocalStorage();
124
124
  function timezoneMiddleware(req, res, next) {
125
125
  var userTimeZone = req.headers['user-timezone'];
126
- console.log(userTimeZone, 'llega?');
127
126
  if (Array.isArray(userTimeZone)) {
128
127
  userTimeZone = userTimeZone[0];
129
128
  }
@@ -136,14 +135,6 @@ exports.timezoneMiddleware = timezoneMiddleware;
136
135
  function getTimeZone() {
137
136
  var _a;
138
137
  var store = asyncLocalStorage.getStore();
139
- console.log(store, 'Prueba aer si funciona');
140
138
  return (_a = store === null || store === void 0 ? void 0 : store.get('timezone')) !== null && _a !== void 0 ? _a : 'UTC';
141
139
  }
142
140
  exports.getTimeZone = getTimeZone;
143
- // module.exports = {
144
- // createDataBaseSource,
145
- // showEntity,
146
- // callStoredProcedure,
147
- // timezoneMiddleware,
148
- // getTimeZone,
149
- // }
@@ -2,16 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DateTransformer = void 0;
4
4
  var moment = require("moment-timezone");
5
+ var __1 = require("..");
5
6
  var DateTransformer = /** @class */ (function () {
6
7
  function DateTransformer() {
7
8
  }
8
9
  DateTransformer.prototype.to = function (value) {
9
- // No es necesario transformar al guardar, se guarda en UTC
10
10
  return moment.utc(value).format('YYYY-MM-DD HH:mm:ss');
11
11
  };
12
12
  DateTransformer.prototype.from = function (value) {
13
- // Convertir de UTC a la zona horaria local
14
- return moment.utc(value).tz('America/Bogota').format('YYYY-MM-DD HH:mm:ss');
13
+ return moment.utc(value).tz((0, __1.getTimeZone)()).format('YYYY-MM-DD HH:mm:ss');
15
14
  };
16
15
  return DateTransformer;
17
16
  }());
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.jsonTransformer = void 0;
4
4
  // DOCUMENTATION: Variable creada para poder transformar los elementos a tipo objeto a los que están en la base de datos como strings que son objetos.
5
5
  exports.jsonTransformer = {
6
- to: function (value) { return JSON.stringify(value); },
6
+ to: function (value) {
7
+ return JSON.stringify(value);
8
+ },
7
9
  from: function (value) {
8
10
  try {
9
11
  return JSON.parse(value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-entity-library-asm",
3
- "version": "1.9.4",
3
+ "version": "1.9.6",
4
4
  "description": "Entidades de ejemplo para una base de datos",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -11,8 +11,6 @@
11
11
  "author": "",
12
12
  "license": "ISC",
13
13
  "dependencies": {
14
- "date-fns": "^3.6.0",
15
- "date-fns-tz": "^3.1.3",
16
14
  "dotenv": "^16.4.5",
17
15
  "express": "^4.19.2",
18
16
  "moment-timezone": "^0.5.45",
@@ -105,11 +105,12 @@ export class Partner {
105
105
  comment: 'Fecha de creación del registro.',
106
106
  transformer: new DateTransformer(),
107
107
  })
108
- created: string
108
+ created: Date
109
109
 
110
110
  @Column({
111
111
  type: 'datetime',
112
112
  comment: 'Fecha de actualización del registro.',
113
+ transformer: new DateTransformer(),
113
114
  })
114
115
  updated: Date
115
116
 
package/src/index.ts CHANGED
@@ -77,7 +77,6 @@ export function timezoneMiddleware(
77
77
  next: NextFunction
78
78
  ) {
79
79
  let userTimeZone = req.headers['user-timezone']
80
- console.log(userTimeZone, 'llega?')
81
80
 
82
81
  if (Array.isArray(userTimeZone)) {
83
82
  userTimeZone = userTimeZone[0]
@@ -92,15 +91,5 @@ export function timezoneMiddleware(
92
91
 
93
92
  export function getTimeZone(): string {
94
93
  const store = asyncLocalStorage.getStore()
95
- console.log(store, 'Prueba aer si funciona')
96
-
97
94
  return store?.get('timezone') ?? 'UTC'
98
95
  }
99
-
100
- // module.exports = {
101
- // createDataBaseSource,
102
- // showEntity,
103
- // callStoredProcedure,
104
- // timezoneMiddleware,
105
- // getTimeZone,
106
- // }
@@ -1,14 +1,13 @@
1
1
  import { ValueTransformer } from 'typeorm'
2
2
  import * as moment from 'moment-timezone'
3
+ import { getTimeZone } from '..'
3
4
 
4
5
  export class DateTransformer implements ValueTransformer {
5
6
  to(value: Date | string): string {
6
- // No es necesario transformar al guardar, se guarda en UTC
7
7
  return moment.utc(value).format('YYYY-MM-DD HH:mm:ss')
8
8
  }
9
9
 
10
10
  from(value: string): string {
11
- // Convertir de UTC a la zona horaria local
12
- return moment.utc(value).tz('America/Bogota').format('YYYY-MM-DD HH:mm:ss')
11
+ return moment.utc(value).tz(getTimeZone()).format('YYYY-MM-DD HH:mm:ss')
13
12
  }
14
13
  }
@@ -1,13 +1,14 @@
1
1
  // DOCUMENTATION: Variable creada para poder transformar los elementos a tipo objeto a los que están en la base de datos como strings que son objetos.
2
2
  export const jsonTransformer = {
3
- to: (value: any) => JSON.stringify(value),
4
- from: (value: string) => {
5
- try {
6
- return JSON.parse(value)
7
- } catch (error) {
8
- console.error('Error parsing JSON:', error)
9
- return null
10
- }
11
- },
12
- }
13
-
3
+ to: (value: any) => {
4
+ return JSON.stringify(value)
5
+ },
6
+ from: (value: string) => {
7
+ try {
8
+ return JSON.parse(value)
9
+ } catch (error) {
10
+ console.error('Error parsing JSON:', error)
11
+ return null
12
+ }
13
+ },
14
+ }