@hedhog/admin 0.0.37 → 0.0.39

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. package/dist/admin.module.d.ts.map +1 -1
  2. package/dist/admin.module.js +2 -0
  3. package/dist/admin.module.js.map +1 -1
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +3 -0
  7. package/dist/index.js.map +1 -1
  8. package/dist/locale/dto/create.dto.d.ts +7 -0
  9. package/dist/locale/dto/create.dto.d.ts.map +1 -0
  10. package/dist/locale/dto/create.dto.js +33 -0
  11. package/dist/locale/dto/create.dto.js.map +1 -0
  12. package/dist/locale/dto/delete.dto.d.ts +4 -0
  13. package/dist/locale/dto/delete.dto.d.ts.map +1 -0
  14. package/dist/locale/dto/delete.dto.js +23 -0
  15. package/dist/locale/dto/delete.dto.js.map +1 -0
  16. package/dist/locale/dto/update.dto.d.ts +7 -0
  17. package/dist/locale/dto/update.dto.d.ts.map +1 -0
  18. package/dist/locale/dto/update.dto.js +37 -0
  19. package/dist/locale/dto/update.dto.js.map +1 -0
  20. package/dist/locale/index.d.ts +5 -0
  21. package/dist/locale/index.d.ts.map +1 -0
  22. package/dist/locale/index.js +21 -0
  23. package/dist/locale/index.js.map +1 -0
  24. package/dist/locale/locale.controller.d.ts +16 -0
  25. package/dist/locale/locale.controller.d.ts.map +1 -0
  26. package/dist/locale/locale.controller.js +110 -0
  27. package/dist/locale/locale.controller.js.map +1 -0
  28. package/dist/locale/locale.decorator.d.ts +2 -0
  29. package/dist/locale/locale.decorator.d.ts.map +1 -0
  30. package/dist/locale/locale.decorator.js +9 -0
  31. package/dist/locale/locale.decorator.js.map +1 -0
  32. package/dist/locale/locale.middleware.d.ts +10 -0
  33. package/dist/locale/locale.middleware.d.ts.map +1 -0
  34. package/dist/locale/locale.middleware.js +45 -0
  35. package/dist/locale/locale.middleware.js.map +1 -0
  36. package/dist/locale/locale.module.d.ts +5 -0
  37. package/dist/locale/locale.module.d.ts.map +1 -0
  38. package/dist/locale/locale.module.js +35 -0
  39. package/dist/locale/locale.module.js.map +1 -0
  40. package/dist/locale/locale.service.d.ts +26 -0
  41. package/dist/locale/locale.service.d.ts.map +1 -0
  42. package/dist/locale/locale.service.js +166 -0
  43. package/dist/locale/locale.service.js.map +1 -0
  44. package/dist/menu/menu.controller.js +1 -1
  45. package/dist/menu/menu.controller.js.map +1 -1
  46. package/dist/role/role.controller.d.ts.map +1 -1
  47. package/dist/role/role.controller.js +1 -1
  48. package/dist/role/role.controller.js.map +1 -1
  49. package/dist/route/route.controller.js +1 -1
  50. package/dist/route/route.controller.js.map +1 -1
  51. package/dist/screen/screen.controller.js +1 -1
  52. package/dist/screen/screen.controller.js.map +1 -1
  53. package/package.json +1 -3
  54. package/src/migrations/migrate-01.ts +271 -127
  55. package/src/migrations/migrate-02.ts +137 -236
  56. package/src/migrations/migrate-03.ts +98 -192
  57. package/src/migrations/migrate-04.ts +167 -197
  58. package/src/migrations/migrate-05.ts +185 -42
  59. package/src/migrations/migrate-06.ts +245 -33
  60. package/src/migrations/migrate-07.ts +87 -21
  61. package/src/migrations/migrate-08.ts +8 -8
  62. package/src/migrations/migrate-09.ts +13 -14
  63. package/src/migrations/migrate-10.ts +8 -8
  64. package/src/migrations/migrate-11.ts +46 -17
  65. package/src/migrations/migrate-12.ts +46 -71
  66. package/src/migrations/migrate-13.ts +15 -9
  67. package/src/migrations/migrate-14.ts +55 -33
  68. package/src/migrations/migrate-15.ts +9 -16
  69. package/src/migrations/migrate-16.ts +37 -17
  70. package/src/migrations/migrate-17.ts +20 -169
  71. package/src/migrations/migrate-18.ts +30 -191
  72. package/src/migrations/migrate-19.ts +176 -0
  73. package/src/migrations/migrate-20.ts +198 -0
@@ -1,169 +1,313 @@
1
- import {
2
- MigrationInterface,
3
- QueryRunner,
4
- Table,
5
- TableForeignKey,
6
- } from 'typeorm';
1
+ import { MigrationInterface, QueryRunner, Table } from 'typeorm';
7
2
  import { idColumn, timestampColumn } from '@hedhog/utils';
8
- import * as bcrypt from 'bcrypt';
9
3
 
10
4
  export class Migrate implements MigrationInterface {
11
- async up(queryRunner: QueryRunner) {
5
+ public async up(queryRunner: QueryRunner): Promise<void> {
12
6
  await queryRunner.createTable(
13
7
  new Table({
14
- name: 'multifactors',
15
- columns: [idColumn(), timestampColumn(), timestampColumn('updated_at')],
16
- }),
17
- true,
18
- );
19
-
20
- await queryRunner.createTable(
21
- new Table({
22
- name: 'multifactor_translations',
8
+ name: 'countries',
23
9
  columns: [
24
- {
25
- name: 'multifactor_id',
26
- type: 'int',
27
- unsigned: true,
28
- isPrimary: true,
29
- },
30
- {
31
- name: 'locale_id',
32
- type: 'int',
33
- unsigned: true,
34
- isPrimary: true,
35
- },
10
+ idColumn(),
36
11
  {
37
12
  name: 'name',
38
13
  type: 'varchar',
14
+ length: '50',
15
+ isNullable: false,
16
+ },
17
+ {
18
+ name: 'code',
19
+ type: 'char',
20
+ length: '3',
21
+ isNullable: false,
39
22
  },
40
23
  timestampColumn(),
41
24
  timestampColumn('updated_at'),
42
25
  ],
43
- foreignKeys: [
44
- new TableForeignKey({
45
- columnNames: ['multifactor_id'],
46
- referencedTableName: 'multifactors',
47
- referencedColumnNames: ['id'],
48
- onDelete: 'CASCADE',
49
- }),
50
- new TableForeignKey({
51
- columnNames: ['locale_id'],
52
- referencedTableName: 'locales',
53
- referencedColumnNames: ['id'],
54
- onDelete: 'CASCADE',
55
- }),
56
- ],
57
26
  }),
58
27
  true,
59
28
  );
60
29
 
61
- await queryRunner.manager
62
- .createQueryBuilder()
63
- .insert()
64
- .into('multifactors', ['id'])
65
- .values([
66
- {
67
- id: 1,
68
- },
69
- {
70
- id: 2,
71
- },
72
- ])
73
- .execute();
74
-
75
- await queryRunner.manager
76
- .createQueryBuilder()
77
- .insert()
78
- .into('multifactor_translations', ['multifactor_id', 'locale_id', 'name'])
79
- .values([
80
- {
81
- multifactor_id: 1,
82
- locale_id: 1,
83
- name: 'Email',
84
- },
85
- {
86
- multifactor_id: 1,
87
- locale_id: 2,
88
- name: 'E-mail',
89
- },
90
- {
91
- multifactor_id: 2,
92
- locale_id: 1,
93
- name: 'Application',
94
- },
95
- {
96
- multifactor_id: 2,
97
- locale_id: 2,
98
- name: 'Aplicativo',
99
- },
100
- ])
101
- .execute();
30
+ await queryRunner.query(`
31
+ INSERT INTO countries (name, code) VALUES
32
+ ('Afghanistan', 'AFG'),
33
+ ('Albania', 'ALB'),
34
+ ('Algeria', 'DZA'),
35
+ ('Andorra', 'AND'),
36
+ ('Angola', 'AGO'),
37
+ ('Antigua and Barbuda', 'ATG'),
38
+ ('Argentina', 'ARG'),
39
+ ('Armenia', 'ARM'),
40
+ ('Australia', 'AUS'),
41
+ ('Austria', 'AUT'),
42
+ ('Azerbaijan', 'AZE'),
43
+ ('Bahamas', 'BHS'),
44
+ ('Bahrain', 'BHR'),
45
+ ('Bangladesh', 'BGD'),
46
+ ('Barbados', 'BRB'),
47
+ ('Belarus', 'BLR'),
48
+ ('Belgium', 'BEL'),
49
+ ('Belize', 'BLZ'),
50
+ ('Benin', 'BEN'),
51
+ ('Bhutan', 'BTN'),
52
+ ('Bolivia', 'BOL'),
53
+ ('Bosnia and Herzegovina', 'BIH'),
54
+ ('Botswana', 'BWA'),
55
+ ('Brazil', 'BRA'),
56
+ ('Brunei Darussalam', 'BRN'),
57
+ ('Bulgaria', 'BGR'),
58
+ ('Burkina Faso', 'BFA'),
59
+ ('Burundi', 'BDI'),
60
+ ('Cabo Verde', 'CPV'),
61
+ ('Cambodia', 'KHM'),
62
+ ('Cameroon', 'CMR'),
63
+ ('Canada', 'CAN'),
64
+ ('Central African Republic', 'CAF'),
65
+ ('Chad', 'TCD'),
66
+ ('Chile', 'CHL'),
67
+ ('China', 'CHN'),
68
+ ('Colombia', 'COL'),
69
+ ('Comoros', 'COM'),
70
+ ('Congo', 'COG'),
71
+ ('Congo (Democratic Republic)', 'COD'),
72
+ ('Costa Rica', 'CRI'),
73
+ ('Croatia', 'HRV'),
74
+ ('Cuba', 'CUB'),
75
+ ('Cyprus', 'CYP'),
76
+ ('Czech Republic', 'CZE'),
77
+ ('Denmark', 'DNK'),
78
+ ('Djibouti', 'DJI'),
79
+ ('Dominica', 'DMA'),
80
+ ('Dominican Republic', 'DOM'),
81
+ ('Ecuador', 'ECU'),
82
+ ('Egypt', 'EGY'),
83
+ ('El Salvador', 'SLV'),
84
+ ('Equatorial Guinea', 'GNQ'),
85
+ ('Eritrea', 'ERI'),
86
+ ('Estonia', 'EST'),
87
+ ('Eswatini', 'SWZ'),
88
+ ('Ethiopia', 'ETH'),
89
+ ('Fiji', 'FJI'),
90
+ ('Finland', 'FIN'),
91
+ ('France', 'FRA'),
92
+ ('Gabon', 'GAB'),
93
+ ('Gambia', 'GMB'),
94
+ ('Georgia', 'GEO'),
95
+ ('Germany', 'DEU'),
96
+ ('Ghana', 'GHA'),
97
+ ('Greece', 'GRC'),
98
+ ('Grenada', 'GRD'),
99
+ ('Guatemala', 'GTM'),
100
+ ('Guinea', 'GIN'),
101
+ ('Guinea-Bissau', 'GNB'),
102
+ ('Guyana', 'GUY'),
103
+ ('Haiti', 'HTI'),
104
+ ('Honduras', 'HND'),
105
+ ('Hungary', 'HUN'),
106
+ ('Iceland', 'ISL'),
107
+ ('India', 'IND'),
108
+ ('Indonesia', 'IDN'),
109
+ ('Iran', 'IRN'),
110
+ ('Iraq', 'IRQ'),
111
+ ('Ireland', 'IRL'),
112
+ ('Israel', 'ISR'),
113
+ ('Italy', 'ITA'),
114
+ ('Jamaica', 'JAM'),
115
+ ('Japan', 'JPN'),
116
+ ('Jordan', 'JOR'),
117
+ ('Kazakhstan', 'KAZ'),
118
+ ('Kenya', 'KEN'),
119
+ ('Kiribati', 'KIR'),
120
+ ('Kuwait', 'KWT'),
121
+ ('Kyrgyzstan', 'KGZ'),
122
+ ('Laos', 'LAO'),
123
+ ('Latvia', 'LVA'),
124
+ ('Lebanon', 'LBN'),
125
+ ('Lesotho', 'LSO'),
126
+ ('Liberia', 'LBR'),
127
+ ('Libya', 'LBY'),
128
+ ('Liechtenstein', 'LIE'),
129
+ ('Lithuania', 'LTU'),
130
+ ('Luxembourg', 'LUX'),
131
+ ('Madagascar', 'MDG'),
132
+ ('Malawi', 'MWI'),
133
+ ('Malaysia', 'MYS'),
134
+ ('Maldives', 'MDV'),
135
+ ('Mali', 'MLI'),
136
+ ('Malta', 'MLT'),
137
+ ('Marshall Islands', 'MHL'),
138
+ ('Mauritania', 'MRT'),
139
+ ('Mauritius', 'MUS'),
140
+ ('Mexico', 'MEX'),
141
+ ('Micronesia (Federated States)', 'FSM'),
142
+ ('Moldova', 'MDA'),
143
+ ('Monaco', 'MCO'),
144
+ ('Mongolia', 'MNG'),
145
+ ('Montenegro', 'MNE'),
146
+ ('Morocco', 'MAR'),
147
+ ('Mozambique', 'MOZ'),
148
+ ('Myanmar', 'MMR'),
149
+ ('Namibia', 'NAM'),
150
+ ('Nauru', 'NRU'),
151
+ ('Nepal', 'NPL'),
152
+ ('Netherlands', 'NLD'),
153
+ ('New Zealand', 'NZL'),
154
+ ('Nicaragua', 'NIC'),
155
+ ('Niger', 'NER'),
156
+ ('Nigeria', 'NGA'),
157
+ ('North Macedonia', 'MKD'),
158
+ ('Norway', 'NOR'),
159
+ ('Oman', 'OMN'),
160
+ ('Pakistan', 'PAK'),
161
+ ('Palau', 'PLW'),
162
+ ('Panama', 'PAN'),
163
+ ('Papua New Guinea', 'PNG'),
164
+ ('Paraguay', 'PRY'),
165
+ ('Peru', 'PER'),
166
+ ('Philippines', 'PHL'),
167
+ ('Poland', 'POL'),
168
+ ('Portugal', 'PRT'),
169
+ ('Qatar', 'QAT'),
170
+ ('Republic of Korea', 'KOR'),
171
+ ('Romania', 'ROU'),
172
+ ('Russian Federation', 'RUS'),
173
+ ('Rwanda', 'RWA'),
174
+ ('Saint Kitts and Nevis', 'KNA'),
175
+ ('Saint Lucia', 'LCA'),
176
+ ('Saint Vincent and the Grenadines', 'VCT'),
177
+ ('Samoa', 'WSM'),
178
+ ('San Marino', 'SMR'),
179
+ ('Sao Tome and Principe', 'STP'),
180
+ ('Saudi Arabia', 'SAU'),
181
+ ('Senegal', 'SEN'),
182
+ ('Serbia', 'SRB'),
183
+ ('Seychelles', 'SYC'),
184
+ ('Sierra Leone', 'SLE'),
185
+ ('Singapore', 'SGP'),
186
+ ('Slovakia', 'SVK'),
187
+ ('Slovenia', 'SVN'),
188
+ ('Solomon Islands', 'SLB'),
189
+ ('Somalia', 'SOM'),
190
+ ('South Africa', 'ZAF'),
191
+ ('Spain', 'ESP'),
192
+ ('Sri Lanka', 'LKA'),
193
+ ('Sudan', 'SDN'),
194
+ ('Suriname', 'SUR'),
195
+ ('Sweden', 'SWE'),
196
+ ('Switzerland', 'CHE'),
197
+ ('Syrian Arab Republic', 'SYR'),
198
+ ('Tajikistan', 'TJK'),
199
+ ('Thailand', 'THA'),
200
+ ('Timor-Leste', 'TLS'),
201
+ ('Togo', 'TGO'),
202
+ ('Tonga', 'TON'),
203
+ ('Trinidad and Tobago', 'TTO'),
204
+ ('Tunisia', 'TUN'),
205
+ ('Turkey', 'TUR'),
206
+ ('Turkmenistan', 'TKM'),
207
+ ('Tuvalu', 'TUV'),
208
+ ('Uganda', 'UGA'),
209
+ ('Ukraine', 'UKR'),
210
+ ('United Arab Emirates', 'ARE'),
211
+ ('United Kingdom', 'GBR'),
212
+ ('United Republic of Tanzania', 'TZA'),
213
+ ('United States of America', 'USA'),
214
+ ('Uruguay', 'URY'),
215
+ ('Uzbekistan', 'UZB'),
216
+ ('Vanuatu', 'VUT'),
217
+ ('Venezuela', 'VEN'),
218
+ ('Viet Nam', 'VNM'),
219
+ ('Yemen', 'YEM'),
220
+ ('Zambia', 'ZMB'),
221
+ ('Zimbabwe', 'ZWE');
222
+ `);
102
223
 
103
224
  await queryRunner.createTable(
104
225
  new Table({
105
- name: 'users',
226
+ name: 'locales',
106
227
  columns: [
107
228
  idColumn(),
108
229
  {
109
- name: 'name',
110
- type: 'varchar',
111
- },
112
- {
113
- name: 'email',
114
- type: 'varchar',
230
+ name: 'code',
231
+ type: 'char',
232
+ length: '2',
233
+ isNullable: false,
115
234
  },
116
235
  {
117
- name: 'password',
118
- type: 'varchar',
236
+ name: 'region',
237
+ type: 'char',
238
+ length: '2',
239
+ isNullable: false,
119
240
  },
120
241
  {
121
- name: 'multifactor_id',
242
+ name: 'country_id',
122
243
  type: 'int',
123
- isNullable: true,
124
- unsigned: true,
244
+ isNullable: false,
125
245
  },
126
246
  {
127
- name: 'code',
128
- type: 'varchar',
129
- isNullable: true,
247
+ name: 'enabled',
248
+ type: 'boolean',
249
+ default: true,
130
250
  },
131
251
  timestampColumn(),
132
252
  timestampColumn('updated_at'),
133
253
  ],
254
+ foreignKeys: [
255
+ {
256
+ columnNames: ['country_id'],
257
+ referencedColumnNames: ['id'],
258
+ referencedTableName: 'countries',
259
+ onDelete: 'CASCADE',
260
+ },
261
+ ],
134
262
  }),
135
263
  );
136
264
 
137
- await queryRunner.createForeignKeys('users', [
138
- new TableForeignKey({
139
- columnNames: ['multifactor_id'],
140
- referencedColumnNames: ['id'],
141
- referencedTableName: 'multifactors',
142
- name: 'fk_users_to_multifactors_on_multifactor_id',
143
- onDelete: 'Cascade',
144
- }),
145
- ]);
146
-
147
- await queryRunner.manager
265
+ const countryUSA = await queryRunner.manager
148
266
  .createQueryBuilder()
149
- .insert()
150
- .into('users', ['name', 'email', 'password'])
151
- .values([
152
- {
153
- name: 'Superuser',
154
- email: 'root@hedhog.com',
155
- password: await bcrypt.hash(`hedhog`, 12),
156
- },
157
- {
158
- name: 'User',
159
- email: 'user@hedhog.com',
160
- password: await bcrypt.hash(`hedhog`, 12),
161
- },
162
- ])
267
+ .select()
268
+ .from('countries', 'c')
269
+ .where('code = :code', { code: 'USA' })
163
270
  .execute();
271
+ const countryBRA = await queryRunner.manager
272
+ .createQueryBuilder()
273
+ .select()
274
+ .from('countries', 'c')
275
+ .where('code = :code', { code: 'BRA' })
276
+ .execute();
277
+
278
+ const locales = [
279
+ {
280
+ id: 0,
281
+ code: 'en',
282
+ region: 'US',
283
+ country_id: countryUSA[0].id,
284
+ },
285
+ {
286
+ id: 0,
287
+ code: 'pt',
288
+ region: 'BR',
289
+ country_id: countryBRA[0].id,
290
+ },
291
+ ];
292
+
293
+ for (let index = 0; index < locales.length; index++) {
294
+ const localeId = await queryRunner.manager
295
+ .createQueryBuilder()
296
+ .insert()
297
+ .into('locales', ['code', 'region', 'country_id'])
298
+ .values({
299
+ code: locales[index].code,
300
+ region: locales[index].region,
301
+ country_id: locales[index].country_id,
302
+ })
303
+ .returning('id')
304
+ .execute();
305
+
306
+ locales[index].id = localeId.raw[0].id;
307
+ }
164
308
  }
165
- async down(queryRunner: QueryRunner) {
166
- await queryRunner.dropTable('multifactors');
167
- await queryRunner.dropTable('users');
309
+
310
+ public async down(queryRunner: QueryRunner): Promise<void> {
311
+ await queryRunner.dropTable('locales');
168
312
  }
169
313
  }