@hedhog/admin 0.0.37 → 0.0.38

Sign up to get free protection for your applications and to get access to all the features.
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,48 +5,24 @@ import {
5
5
  TableForeignKey,
6
6
  } from 'typeorm';
7
7
  import { idColumn, timestampColumn } from '@hedhog/utils';
8
+ import * as bcrypt from 'bcrypt';
8
9
 
9
10
  export class Migrate implements MigrationInterface {
10
- public async up(queryRunner: QueryRunner): Promise<void> {
11
+ async up(queryRunner: QueryRunner) {
11
12
  await queryRunner.createTable(
12
13
  new Table({
13
- name: 'menus',
14
- columns: [
15
- idColumn(),
16
- {
17
- name: 'url',
18
- type: 'varchar',
19
- isNullable: true,
20
- },
21
- {
22
- name: 'order',
23
- type: 'int',
24
- default: 0,
25
- unsigned: true,
26
- },
27
- {
28
- name: 'menu_id',
29
- type: 'int',
30
- isNullable: true,
31
- unsigned: true,
32
- },
33
- {
34
- name: 'icon',
35
- type: 'varchar',
36
- isNullable: true,
37
- },
38
- timestampColumn(),
39
- timestampColumn('updated_at'),
40
- ],
14
+ name: 'multifactors',
15
+ columns: [idColumn(), timestampColumn(), timestampColumn('updated_at')],
41
16
  }),
17
+ true,
42
18
  );
43
19
 
44
20
  await queryRunner.createTable(
45
21
  new Table({
46
- name: 'menu_translations',
22
+ name: 'multifactor_translations',
47
23
  columns: [
48
24
  {
49
- name: 'menu_id',
25
+ name: 'multifactor_id',
50
26
  type: 'int',
51
27
  unsigned: true,
52
28
  isPrimary: true,
@@ -66,198 +42,128 @@ export class Migrate implements MigrationInterface {
66
42
  ],
67
43
  foreignKeys: [
68
44
  new TableForeignKey({
69
- columnNames: ['menu_id'],
45
+ columnNames: ['multifactor_id'],
46
+ referencedTableName: 'multifactors',
70
47
  referencedColumnNames: ['id'],
71
- referencedTableName: 'menus',
72
48
  onDelete: 'CASCADE',
73
49
  }),
74
50
  new TableForeignKey({
75
51
  columnNames: ['locale_id'],
76
- referencedColumnNames: ['id'],
77
52
  referencedTableName: 'locales',
53
+ referencedColumnNames: ['id'],
78
54
  onDelete: 'CASCADE',
79
55
  }),
80
56
  ],
81
57
  }),
58
+ true,
82
59
  );
83
60
 
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();
102
+
84
103
  await queryRunner.createTable(
85
104
  new Table({
86
- name: 'menu_screens',
105
+ name: 'users',
87
106
  columns: [
107
+ idColumn(),
88
108
  {
89
- name: 'menu_id',
90
- type: 'int',
91
- isPrimary: true,
92
- unsigned: true,
109
+ name: 'name',
110
+ type: 'varchar',
93
111
  },
94
112
  {
95
- name: 'screen_id',
113
+ name: 'email',
114
+ type: 'varchar',
115
+ },
116
+ {
117
+ name: 'password',
118
+ type: 'varchar',
119
+ },
120
+ {
121
+ name: 'multifactor_id',
96
122
  type: 'int',
97
- isPrimary: true,
123
+ isNullable: true,
98
124
  unsigned: true,
99
125
  },
126
+ {
127
+ name: 'code',
128
+ type: 'varchar',
129
+ isNullable: true,
130
+ },
131
+ timestampColumn(),
132
+ timestampColumn('updated_at'),
100
133
  ],
101
134
  }),
102
135
  );
103
136
 
104
- await queryRunner.createForeignKey(
105
- 'menu_screens',
137
+ await queryRunner.createForeignKeys('users', [
106
138
  new TableForeignKey({
107
- columnNames: ['menu_id'],
139
+ columnNames: ['multifactor_id'],
108
140
  referencedColumnNames: ['id'],
109
- referencedTableName: 'menus',
110
- onDelete: 'CASCADE',
141
+ referencedTableName: 'multifactors',
142
+ name: 'fk_users_to_multifactors_on_multifactor_id',
143
+ onDelete: 'Cascade',
111
144
  }),
112
- );
145
+ ]);
113
146
 
114
- await queryRunner.createForeignKey(
115
- 'menu_screens',
116
- new TableForeignKey({
117
- columnNames: ['screen_id'],
118
- referencedColumnNames: ['id'],
119
- referencedTableName: 'screens',
120
- onDelete: 'CASCADE',
121
- }),
122
- );
123
-
124
- const menus = [
125
- {
126
- name_en: 'Dashboard',
127
- name_pt: 'Dashboard',
128
- url: '/',
129
- order: 0,
130
- icon: 'dashboard',
131
- },
132
- {
133
- name_en: 'Management',
134
- name_pt: 'Gereciamento',
135
- url: '/management',
136
- order: 1,
137
- icon: 'settings',
138
- },
139
- ];
140
-
141
- for (const menu of menus) {
142
- const m = await queryRunner.manager
143
- .createQueryBuilder()
144
- .insert()
145
- .into('menus', ['url', 'order', 'icon'])
146
- .values({
147
- url: menu.url,
148
- order: menu.order,
149
- icon: menu.icon,
150
- })
151
- .returning('id')
152
- .execute();
153
-
154
- await queryRunner.manager
155
- .createQueryBuilder()
156
- .insert()
157
- .into('menu_translations', ['menu_id', 'locale_id', 'name'])
158
- .values([
159
- {
160
- menu_id: m.raw[0].id,
161
- locale_id: 1,
162
- name: menu.name_en,
163
- },
164
- {
165
- menu_id: m.raw[0].id,
166
- locale_id: 2,
167
- name: menu.name_pt,
168
- },
169
- ])
170
- .execute();
171
- }
172
-
173
- const menusManagement = [
174
- {
175
- name_en: 'Users',
176
- name_pt: 'Usuários',
177
- url: '/management/users',
178
- order: 0,
179
- icon: 'users',
180
- },
181
- {
182
- name_en: 'Roles',
183
- name_pt: 'Funções',
184
- url: '/management/roles',
185
- order: 1,
186
- icon: 'circles',
187
- },
188
- {
189
- name_en: 'Screens',
190
- name_pt: 'Telas',
191
- url: '/management/screens',
192
- order: 2,
193
- icon: 'device-tv',
194
- },
195
- {
196
- name_en: 'Menus',
197
- name_pt: 'Menus',
198
- url: '/management/menus',
199
- order: 3,
200
- icon: 'menu',
201
- },
202
- {
203
- name_en: 'Routes',
204
- name_pt: 'Rotas',
205
- url: '/management/routes',
206
- order: 4,
207
- icon: 'route',
208
- },
209
- {
210
- name_en: 'Settings',
211
- name_pt: 'Configurações',
212
- url: '/management/settings',
213
- order: 5,
214
- icon: 'settings',
215
- },
216
- ];
217
-
218
- const menuManagement = await queryRunner.manager
147
+ await queryRunner.manager
219
148
  .createQueryBuilder()
220
- .select('id')
221
- .from('menus', 'm')
222
- .where('m.url = :url', { url: '/management' })
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
+ ])
223
163
  .execute();
224
-
225
- for (const menu of menusManagement) {
226
- const m = await queryRunner.manager
227
- .createQueryBuilder()
228
- .insert()
229
- .into('menus', ['url', 'order', 'icon', 'menu_id'])
230
- .values({
231
- url: menu.url,
232
- order: menu.order,
233
- icon: menu.icon,
234
- menu_id: menuManagement[0].id,
235
- })
236
- .returning('id')
237
- .execute();
238
-
239
- await queryRunner.manager
240
- .createQueryBuilder()
241
- .insert()
242
- .into('menu_translations', ['menu_id', 'locale_id', 'name'])
243
- .values([
244
- {
245
- menu_id: m.raw[0].id,
246
- locale_id: 1,
247
- name: menu.name_en,
248
- },
249
- {
250
- menu_id: m.raw[0].id,
251
- locale_id: 2,
252
- name: menu.name_pt,
253
- },
254
- ])
255
- .execute();
256
- }
257
164
  }
258
-
259
- public async down(queryRunner: QueryRunner): Promise<void> {
260
- await queryRunner.dropTable('menu_screens');
261
- await queryRunner.dropTable('menus');
165
+ async down(queryRunner: QueryRunner) {
166
+ await queryRunner.dropTable('multifactors');
167
+ await queryRunner.dropTable('users');
262
168
  }
263
169
  }