mblabs-roccato-backend-commons 1.0.78 → 1.0.80

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.
@@ -113,7 +113,6 @@ class CreateAccountsTable1748448589934 {
113
113
  'chainLinkId',
114
114
  'name',
115
115
  'email',
116
- 'cellphone',
117
116
  'personalDocument',
118
117
  'businessDocument',
119
118
  'profileId',
@@ -1,9 +1,16 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.AddCanAddWidgetToAccountModuleTable1759768335075 = void 0;
4
7
  const typeorm_1 = require("typeorm");
8
+ const utils_1 = __importDefault(require("../utils"));
5
9
  class AddCanAddWidgetToAccountModuleTable1759768335075 {
6
10
  async up(queryRunner) {
11
+ const hasColumn = await utils_1.default.checkHasColumn('account_module', 'canAddWidget', queryRunner);
12
+ if (hasColumn)
13
+ return;
7
14
  await queryRunner.addColumn('account_module', new typeorm_1.TableColumn({
8
15
  name: 'canAddWidget',
9
16
  type: 'boolean',
@@ -12,6 +19,9 @@ class AddCanAddWidgetToAccountModuleTable1759768335075 {
12
19
  }));
13
20
  }
14
21
  async down(queryRunner) {
22
+ const hasColumn = await utils_1.default.checkHasColumn('account_module', 'canAddWidget', queryRunner);
23
+ if (!hasColumn)
24
+ return;
15
25
  await queryRunner.dropColumn('account_module', 'canAddWidget');
16
26
  }
17
27
  }
@@ -1,9 +1,16 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.AddCanAddWidgetToGroupModuleTable1759768342995 = void 0;
4
7
  const typeorm_1 = require("typeorm");
8
+ const utils_1 = __importDefault(require("../utils"));
5
9
  class AddCanAddWidgetToGroupModuleTable1759768342995 {
6
10
  async up(queryRunner) {
11
+ const hasColumn = await utils_1.default.checkHasColumn('group_module', 'canAddWidget', queryRunner);
12
+ if (hasColumn)
13
+ return;
7
14
  await queryRunner.addColumn('group_module', new typeorm_1.TableColumn({
8
15
  name: 'canAddWidget',
9
16
  type: 'boolean',
@@ -12,6 +19,9 @@ class AddCanAddWidgetToGroupModuleTable1759768342995 {
12
19
  }));
13
20
  }
14
21
  async down(queryRunner) {
22
+ const hasColumn = await utils_1.default.checkHasColumn('group_module', 'canAddWidget', queryRunner);
23
+ if (!hasColumn)
24
+ return;
15
25
  await queryRunner.dropColumn('group_module', 'canAddWidget');
16
26
  }
17
27
  }
@@ -1,9 +1,16 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.AddCanAddWidgetToProfileModuleTable1759768354127 = void 0;
4
7
  const typeorm_1 = require("typeorm");
8
+ const utils_1 = __importDefault(require("../utils"));
5
9
  class AddCanAddWidgetToProfileModuleTable1759768354127 {
6
10
  async up(queryRunner) {
11
+ const hasColumn = await utils_1.default.checkHasColumn('profile_module', 'canAddWidget', queryRunner);
12
+ if (hasColumn)
13
+ return;
7
14
  await queryRunner.addColumn('profile_module', new typeorm_1.TableColumn({
8
15
  name: 'canAddWidget',
9
16
  type: 'boolean',
@@ -12,6 +19,9 @@ class AddCanAddWidgetToProfileModuleTable1759768354127 {
12
19
  }));
13
20
  }
14
21
  async down(queryRunner) {
22
+ const hasColumn = await utils_1.default.checkHasColumn('profile_module', 'canAddWidget', queryRunner);
23
+ if (!hasColumn)
24
+ return;
15
25
  await queryRunner.dropColumn('profile_module', 'canAddWidget');
16
26
  }
17
27
  }
@@ -10,6 +10,27 @@ declare class DatabaseUtils {
10
10
  dropUniqueConstraint(tableName: string, uniqueConstraintName: string, queryRunner: QueryRunner): Promise<void>;
11
11
  serializeOrderBy<Entity>(entity: EntityTarget<Entity>, orderBy: string): string;
12
12
  serializeEntity<T>(entity: ClassConstructor<T>, data: T): T;
13
+ serializeError(err: unknown): {
14
+ name: string;
15
+ message: string;
16
+ details: {
17
+ query: string;
18
+ parameters: any[];
19
+ driverError: any;
20
+ };
21
+ } | {
22
+ name: string;
23
+ message: string;
24
+ details?: undefined;
25
+ } | {
26
+ name: string;
27
+ message: string;
28
+ details: string;
29
+ } | {
30
+ name?: undefined;
31
+ message?: undefined;
32
+ details?: undefined;
33
+ };
13
34
  }
14
35
  declare const _default: DatabaseUtils;
15
36
  export default _default;
@@ -78,5 +78,32 @@ class DatabaseUtils {
78
78
  const entitySerialized = (0, class_transformer_1.plainToInstance)(entity, data);
79
79
  return entitySerialized;
80
80
  }
81
+ serializeError(err) {
82
+ if (err instanceof typeorm_1.QueryFailedError) {
83
+ return {
84
+ name: typeorm_1.QueryFailedError.name,
85
+ message: err.message,
86
+ details: {
87
+ query: err.query,
88
+ parameters: err.parameters,
89
+ driverError: err.driverError,
90
+ },
91
+ };
92
+ }
93
+ if (err instanceof typeorm_1.EntityNotFoundError) {
94
+ return {
95
+ name: typeorm_1.EntityNotFoundError.name,
96
+ message: err.message,
97
+ };
98
+ }
99
+ if (err instanceof Error) {
100
+ return {
101
+ name: err.name,
102
+ message: err.message,
103
+ details: err.stack,
104
+ };
105
+ }
106
+ return {};
107
+ }
81
108
  }
82
109
  exports.default = new DatabaseUtils();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mblabs-roccato-backend-commons",
3
- "version": "1.0.78",
3
+ "version": "1.0.80",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -112,7 +112,6 @@ export class CreateAccountsTable1748448589934 implements MigrationInterface {
112
112
  'chainLinkId',
113
113
  'name',
114
114
  'email',
115
- 'cellphone',
116
115
  'personalDocument',
117
116
  'businessDocument',
118
117
  'profileId',
@@ -1,8 +1,14 @@
1
1
  import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm';
2
2
 
3
+ import DatabaseUtils from '../utils';
4
+
3
5
  export class AddCanAddWidgetToAccountModuleTable1759768335075 implements MigrationInterface {
4
6
 
5
7
  public async up (queryRunner: QueryRunner): Promise<void> {
8
+ const hasColumn = await DatabaseUtils.checkHasColumn('account_module', 'canAddWidget', queryRunner);
9
+
10
+ if (hasColumn) return;
11
+
6
12
  await queryRunner.addColumn('account_module', new TableColumn({
7
13
  name: 'canAddWidget',
8
14
  type: 'boolean',
@@ -12,6 +18,10 @@ export class AddCanAddWidgetToAccountModuleTable1759768335075 implements Migrati
12
18
  }
13
19
 
14
20
  public async down (queryRunner: QueryRunner): Promise<void> {
21
+ const hasColumn = await DatabaseUtils.checkHasColumn('account_module', 'canAddWidget', queryRunner);
22
+
23
+ if (!hasColumn) return;
24
+
15
25
  await queryRunner.dropColumn('account_module', 'canAddWidget');
16
26
  }
17
- }
27
+ }
@@ -1,8 +1,14 @@
1
1
  import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm';
2
2
 
3
+ import DatabaseUtils from '../utils';
4
+
3
5
  export class AddCanAddWidgetToGroupModuleTable1759768342995 implements MigrationInterface {
4
6
 
5
7
  public async up (queryRunner: QueryRunner): Promise<void> {
8
+ const hasColumn = await DatabaseUtils.checkHasColumn('group_module', 'canAddWidget', queryRunner);
9
+
10
+ if (hasColumn) return;
11
+
6
12
  await queryRunner.addColumn('group_module', new TableColumn({
7
13
  name: 'canAddWidget',
8
14
  type: 'boolean',
@@ -12,6 +18,10 @@ export class AddCanAddWidgetToGroupModuleTable1759768342995 implements Migration
12
18
  }
13
19
 
14
20
  public async down (queryRunner: QueryRunner): Promise<void> {
21
+ const hasColumn = await DatabaseUtils.checkHasColumn('group_module', 'canAddWidget', queryRunner);
22
+
23
+ if (!hasColumn) return;
24
+
15
25
  await queryRunner.dropColumn('group_module', 'canAddWidget');
16
26
  }
17
27
 
@@ -1,8 +1,14 @@
1
1
  import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm';
2
2
 
3
+ import DatabaseUtils from '../utils';
4
+
3
5
  export class AddCanAddWidgetToProfileModuleTable1759768354127 implements MigrationInterface {
4
6
 
5
7
  public async up (queryRunner: QueryRunner): Promise<void> {
8
+ const hasColumn = await DatabaseUtils.checkHasColumn('profile_module', 'canAddWidget', queryRunner);
9
+
10
+ if (hasColumn) return;
11
+
6
12
  await queryRunner.addColumn('profile_module', new TableColumn({
7
13
  name: 'canAddWidget',
8
14
  type: 'boolean',
@@ -12,6 +18,10 @@ export class AddCanAddWidgetToProfileModuleTable1759768354127 implements Migrati
12
18
  }
13
19
 
14
20
  public async down (queryRunner: QueryRunner): Promise<void> {
21
+ const hasColumn = await DatabaseUtils.checkHasColumn('profile_module', 'canAddWidget', queryRunner);
22
+
23
+ if (!hasColumn) return;
24
+
15
25
  await queryRunner.dropColumn('profile_module', 'canAddWidget');
16
26
  }
17
27
 
@@ -1,5 +1,16 @@
1
- import { ClassConstructor, plainToInstance } from 'class-transformer';
2
- import { EntityTarget, getMetadataArgsStorage, QueryRunner, Table, TableForeignKey } from 'typeorm';
1
+ import {
2
+ ClassConstructor,
3
+ plainToInstance,
4
+ } from 'class-transformer';
5
+ import {
6
+ EntityNotFoundError,
7
+ EntityTarget,
8
+ getMetadataArgsStorage,
9
+ QueryFailedError,
10
+ QueryRunner,
11
+ Table,
12
+ TableForeignKey,
13
+ } from 'typeorm';
3
14
 
4
15
  class DatabaseUtils {
5
16
  async dropTableForeignKeys (
@@ -143,6 +154,37 @@ class DatabaseUtils {
143
154
 
144
155
  return entitySerialized;
145
156
  }
157
+
158
+ public serializeError (err: unknown) {
159
+ if (err instanceof QueryFailedError) {
160
+ return {
161
+ name: QueryFailedError.name,
162
+ message: err.message,
163
+ details: {
164
+ query: err.query,
165
+ parameters: err.parameters,
166
+ driverError: err.driverError,
167
+ },
168
+ };
169
+ }
170
+
171
+ if (err instanceof EntityNotFoundError) {
172
+ return {
173
+ name: EntityNotFoundError.name,
174
+ message: err.message,
175
+ };
176
+ }
177
+
178
+ if (err instanceof Error) {
179
+ return {
180
+ name: err.name,
181
+ message: err.message,
182
+ details: err.stack,
183
+ };
184
+ }
185
+
186
+ return {};
187
+ }
146
188
  }
147
189
 
148
190
  export default new DatabaseUtils();