@hedhog/admin 0.0.37 → 0.0.38

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