test-entity-library-asm 1.7.5 → 1.7.7

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.
@@ -18,8 +18,8 @@ var Local_1 = require("./Local");
18
18
  var PartnerRole_1 = require("./PartnerRole");
19
19
  var Terminal_1 = require("./Terminal");
20
20
  var TerminalSession_1 = require("./TerminalSession");
21
- var transformations_1 = require("../transformations");
22
21
  var dateTransformer_1 = require("../transformers/dateTransformer");
22
+ var jsonTransformer_1 = require("../transformers/jsonTransformer");
23
23
  var Partner = /** @class */ (function () {
24
24
  function Partner() {
25
25
  }
@@ -98,7 +98,7 @@ var Partner = /** @class */ (function () {
98
98
  (0, typeorm_1.Column)({
99
99
  type: 'longtext',
100
100
  nullable: true,
101
- transformer: transformations_1.jsonTransformer,
101
+ transformer: jsonTransformer_1.jsonTransformer,
102
102
  comment: 'Campo de tipo JSON donde se guarda información necesaria para el registro.',
103
103
  }),
104
104
  __metadata("design:type", Object)
@@ -1,7 +1,5 @@
1
1
  import { ValueTransformer } from 'typeorm';
2
2
  export declare class DateTransformer implements ValueTransformer {
3
- private format;
4
- constructor(format?: string);
5
- from(value: Date): string;
6
- to(value: Date): Date;
3
+ to(value: string): string;
4
+ from(value: string): string;
7
5
  }
@@ -1,26 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DateTransformer = void 0;
4
- var date_fns_tz_1 = require("date-fns-tz");
5
- var __1 = require("..");
4
+ var moment = require("moment-timezone");
6
5
  var DateTransformer = /** @class */ (function () {
7
- function DateTransformer(format) {
8
- if (format === void 0) { format = 'yyyy-MM-dd HH:mm:ss'; }
9
- this.format = format;
6
+ function DateTransformer() {
10
7
  }
11
- DateTransformer.prototype.from = function (value) {
12
- var timeZone = (0, __1.getTimeZone)();
13
- console.log("Converting ".concat(value, " from UTC to ").concat(timeZone));
14
- var zonedDate = (0, date_fns_tz_1.toZonedTime)(value, timeZone);
15
- console.log("Converted date: ".concat(zonedDate));
16
- console.log("Formatted date than return: ".concat((0, date_fns_tz_1.format)(zonedDate, this.format, {
17
- timeZone: timeZone,
18
- })));
19
- return (0, date_fns_tz_1.format)(zonedDate, this.format, { timeZone: timeZone });
20
- };
21
8
  DateTransformer.prototype.to = function (value) {
22
- console.log("Converting ".concat(value, " to UTC"));
23
- return new Date(value); // Assuming the input is already in UTC
9
+ return value; // Deja la fecha en UTC al guardar en la base de datos
10
+ };
11
+ DateTransformer.prototype.from = function (value) {
12
+ return moment.utc(value).tz('America/Bogota').format('YYYY-MM-DD HH:mm:ss'); // Convierte de UTC a la zona horaria local al recuperar de la base de datos
24
13
  };
25
14
  return DateTransformer;
26
15
  }());
@@ -0,0 +1,4 @@
1
+ export declare const jsonTransformer: {
2
+ to: (value: any) => string;
3
+ from: (value: string) => any;
4
+ };
@@ -1 +1,16 @@
1
1
  "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.jsonTransformer = void 0;
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
+ exports.jsonTransformer = {
6
+ to: function (value) { return JSON.stringify(value); },
7
+ from: function (value) {
8
+ try {
9
+ return JSON.parse(value);
10
+ }
11
+ catch (error) {
12
+ console.error('Error parsing JSON:', error);
13
+ return null;
14
+ }
15
+ },
16
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-entity-library-asm",
3
- "version": "1.7.5",
3
+ "version": "1.7.7",
4
4
  "description": "Entidades de ejemplo para una base de datos",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,6 +15,7 @@
15
15
  "date-fns-tz": "^3.1.3",
16
16
  "dotenv": "^16.4.5",
17
17
  "express": "^4.19.2",
18
+ "moment-timezone": "^0.5.45",
18
19
  "typeorm": "^0.3.20"
19
20
  },
20
21
  "devDependencies": {
@@ -15,8 +15,8 @@ import { Local } from './Local'
15
15
  import { PartnerRole } from './PartnerRole'
16
16
  import { Terminal } from './Terminal'
17
17
  import { TerminalSession } from './TerminalSession'
18
- import { jsonTransformer } from '../transformations'
19
18
  import { DateTransformer } from '../transformers/dateTransformer'
19
+ import { jsonTransformer } from '../transformers/jsonTransformer'
20
20
 
21
21
  @Entity({
22
22
  comment:
@@ -1,32 +1,12 @@
1
- // dateTransformer.ts
2
1
  import { ValueTransformer } from 'typeorm'
3
- import { format, toZonedTime } from 'date-fns-tz'
4
- import { getTimeZone } from '..'
2
+ import * as moment from 'moment-timezone'
5
3
 
6
4
  export class DateTransformer implements ValueTransformer {
7
- private format: string
8
-
9
- constructor(format: string = 'yyyy-MM-dd HH:mm:ss') {
10
- this.format = format
5
+ to(value: string): string {
6
+ return value // Deja la fecha en UTC al guardar en la base de datos
11
7
  }
12
8
 
13
- from(value: Date): string {
14
- const timeZone = getTimeZone()
15
- console.log(`Converting ${value} from UTC to ${timeZone}`)
16
- const zonedDate = toZonedTime(value, timeZone)
17
- console.log(`Converted date: ${zonedDate}`)
18
- console.log(
19
- `Formatted date than return: ${format(zonedDate, this.format, {
20
- timeZone,
21
- })}`
22
- )
23
-
24
- return format(zonedDate, this.format, { timeZone })
25
- }
26
-
27
- to(value: Date): Date {
28
- console.log(`Converting ${value} to UTC`)
29
-
30
- return new Date(value) // Assuming the input is already in UTC
9
+ from(value: string): string {
10
+ return moment.utc(value).tz('America/Bogota').format('YYYY-MM-DD HH:mm:ss') // Convierte de UTC a la zona horaria local al recuperar de la base de datos
31
11
  }
32
12
  }
@@ -0,0 +1,13 @@
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
+ 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
+
@@ -1,12 +0,0 @@
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
- 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
- }