@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
@@ -1,26 +1,52 @@
1
- import { idColumn, timestampColumn } from '@hedhog/utils';
2
1
  import {
3
2
  MigrationInterface,
4
3
  QueryRunner,
5
4
  Table,
6
5
  TableForeignKey,
7
6
  } from 'typeorm';
7
+ import { idColumn, timestampColumn } from '@hedhog/utils';
8
8
 
9
9
  export class Migrate implements MigrationInterface {
10
- async up(queryRunner: QueryRunner) {
10
+ public async up(queryRunner: QueryRunner): Promise<void> {
11
11
  await queryRunner.createTable(
12
12
  new Table({
13
- name: 'roles',
14
- columns: [idColumn(), timestampColumn(), timestampColumn('updated_at')],
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
+ ],
15
41
  }),
16
42
  );
17
43
 
18
44
  await queryRunner.createTable(
19
45
  new Table({
20
- name: 'role_translations',
46
+ name: 'menu_translations',
21
47
  columns: [
22
48
  {
23
- name: 'role_id',
49
+ name: 'menu_id',
24
50
  type: 'int',
25
51
  unsigned: true,
26
52
  isPrimary: true,
@@ -34,87 +60,204 @@ export class Migrate implements MigrationInterface {
34
60
  {
35
61
  name: 'name',
36
62
  type: 'varchar',
37
- isNullable: false,
38
- },
39
- {
40
- name: 'description',
41
- type: 'varchar',
42
63
  },
43
64
  timestampColumn(),
44
65
  timestampColumn('updated_at'),
45
66
  ],
46
67
  foreignKeys: [
47
68
  new TableForeignKey({
48
- columnNames: ['role_id'],
49
- referencedTableName: 'roles',
69
+ columnNames: ['menu_id'],
50
70
  referencedColumnNames: ['id'],
71
+ referencedTableName: 'menus',
51
72
  onDelete: 'CASCADE',
52
73
  }),
53
74
  new TableForeignKey({
54
75
  columnNames: ['locale_id'],
55
- referencedTableName: 'locales',
56
76
  referencedColumnNames: ['id'],
77
+ referencedTableName: 'locales',
57
78
  onDelete: 'CASCADE',
58
79
  }),
59
80
  ],
60
81
  }),
61
82
  );
62
83
 
63
- const roles = [
84
+ await queryRunner.createTable(
85
+ new Table({
86
+ name: 'menu_screens',
87
+ columns: [
88
+ {
89
+ name: 'menu_id',
90
+ type: 'int',
91
+ isPrimary: true,
92
+ unsigned: true,
93
+ },
94
+ {
95
+ name: 'screen_id',
96
+ type: 'int',
97
+ isPrimary: true,
98
+ unsigned: true,
99
+ },
100
+ ],
101
+ }),
102
+ );
103
+
104
+ await queryRunner.createForeignKey(
105
+ 'menu_screens',
106
+ new TableForeignKey({
107
+ columnNames: ['menu_id'],
108
+ referencedColumnNames: ['id'],
109
+ referencedTableName: 'menus',
110
+ onDelete: 'CASCADE',
111
+ }),
112
+ );
113
+
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 = [
64
125
  {
65
- id: 1,
66
- name_en: 'Administrator',
67
- name_pt: 'Administrador',
68
- description_en: 'System administrator',
69
- description_pt: 'Administrador do sistema',
126
+ name_en: 'Dashboard',
127
+ name_pt: 'Dashboard',
128
+ url: '/',
129
+ order: 0,
130
+ icon: 'dashboard',
70
131
  },
71
132
  {
72
- id: 2,
73
- name_en: 'Screen Manager',
74
- name_pt: 'Gerenciador de telas',
75
- description_en: 'Screen manager',
76
- description_pt: 'Gerenciador de telas',
133
+ name_en: 'Management',
134
+ name_pt: 'Gereciamento',
135
+ url: '/management',
136
+ order: 1,
137
+ icon: 'settings',
77
138
  },
78
139
  ];
79
140
 
80
- for (const role of roles) {
81
- await queryRunner.manager
141
+ for (const menu of menus) {
142
+ const m = await queryRunner.manager
82
143
  .createQueryBuilder()
83
144
  .insert()
84
- .into('roles', ['id'])
145
+ .into('menus', ['url', 'order', 'icon'])
85
146
  .values({
86
- id: role.id,
147
+ url: menu.url,
148
+ order: menu.order,
149
+ icon: menu.icon,
87
150
  })
151
+ .returning('id')
88
152
  .execute();
89
153
 
90
154
  await queryRunner.manager
91
155
  .createQueryBuilder()
92
156
  .insert()
93
- .into('role_translations', [
94
- 'role_id',
95
- 'locale_id',
96
- 'name',
97
- 'description',
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
+ },
98
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
219
+ .createQueryBuilder()
220
+ .select('id')
221
+ .from('menus', 'm')
222
+ .where('m.url = :url', { url: '/management' })
223
+ .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'])
99
243
  .values([
100
244
  {
101
- role_id: role.id,
245
+ menu_id: m.raw[0].id,
102
246
  locale_id: 1,
103
- name: role.name_en,
104
- description: role.description_en,
247
+ name: menu.name_en,
105
248
  },
106
249
  {
107
- role_id: role.id,
250
+ menu_id: m.raw[0].id,
108
251
  locale_id: 2,
109
- name: role.name_pt,
110
- description: role.description_pt,
252
+ name: menu.name_pt,
111
253
  },
112
254
  ])
113
255
  .execute();
114
256
  }
115
257
  }
116
258
 
117
- async down(queryRunner: QueryRunner) {
118
- await queryRunner.dropTable('roles');
259
+ public async down(queryRunner: QueryRunner): Promise<void> {
260
+ await queryRunner.dropTable('menu_screens');
261
+ await queryRunner.dropTable('menus');
119
262
  }
120
263
  }
@@ -1,28 +1,22 @@
1
- import { timestampColumn } from '@hedhog/utils';
2
- import {
3
- MigrationInterface,
4
- QueryRunner,
5
- Table,
6
- TableForeignKey,
7
- } from 'typeorm';
1
+ import { idColumn, timestampColumn } from '@hedhog/utils';
2
+
3
+ import { MigrationInterface, QueryRunner, Table, TableUnique } from 'typeorm';
8
4
 
9
5
  export class Migrate implements MigrationInterface {
10
6
  async up(queryRunner: QueryRunner) {
11
7
  await queryRunner.createTable(
12
8
  new Table({
13
- name: 'role_menus',
9
+ name: 'routes',
14
10
  columns: [
11
+ idColumn(),
15
12
  {
16
- name: 'role_id',
17
- type: 'int',
18
- isPrimary: true,
19
- unsigned: true,
13
+ name: 'url',
14
+ type: 'varchar',
20
15
  },
21
16
  {
22
- name: 'menu_id',
23
- type: 'int',
24
- isPrimary: true,
25
- unsigned: true,
17
+ name: 'method',
18
+ type: 'enum',
19
+ enum: ['GET', 'POST', 'PATCH', 'DELETE', 'PUT', 'OPTIONS', 'HEAD'],
26
20
  },
27
21
  timestampColumn(),
28
22
  timestampColumn('updated_at'),
@@ -30,25 +24,243 @@ export class Migrate implements MigrationInterface {
30
24
  }),
31
25
  );
32
26
 
33
- await queryRunner.createForeignKeys('role_menus', [
34
- new TableForeignKey({
35
- columnNames: ['role_id'],
36
- referencedColumnNames: ['id'],
37
- referencedTableName: 'roles',
38
- onDelete: 'CASCADE',
39
- name: 'fk_role_menus_roles',
40
- }),
41
- new TableForeignKey({
42
- columnNames: ['menu_id'],
43
- referencedColumnNames: ['id'],
44
- referencedTableName: 'menus',
45
- onDelete: 'CASCADE',
46
- name: 'fk_role_menus_menus',
27
+ await queryRunner.createUniqueConstraint(
28
+ 'routes',
29
+ new TableUnique({
30
+ columnNames: ['url', 'method'],
31
+ name: 'unique_routes',
47
32
  }),
48
- ]);
49
- }
33
+ );
50
34
 
35
+ await queryRunner.manager
36
+ .createQueryBuilder()
37
+ .insert()
38
+ .into('routes', ['url', 'method'])
39
+ .values([
40
+ {
41
+ url: '/auth/verify',
42
+ method: 'GET',
43
+ },
44
+ {
45
+ url: '/menus',
46
+ method: 'GET',
47
+ },
48
+ {
49
+ url: '/menus/system',
50
+ method: 'GET',
51
+ },
52
+ {
53
+ url: '/menus/:menuId',
54
+ method: 'GET',
55
+ },
56
+ {
57
+ url: '/menus',
58
+ method: 'POST',
59
+ },
60
+ {
61
+ url: '/menus/:menuId',
62
+ method: 'PATCH',
63
+ },
64
+ {
65
+ url: '/menus/:menuId/roles',
66
+ method: 'GET',
67
+ },
68
+ {
69
+ url: '/menus/:menuId/roles',
70
+ method: 'PATCH',
71
+ },
72
+ {
73
+ url: '/menus/:menuId/screens',
74
+ method: 'GET',
75
+ },
76
+ {
77
+ url: '/menus/:menuId/screens',
78
+ method: 'PATCH',
79
+ },
80
+ {
81
+ url: '/menus',
82
+ method: 'DELETE',
83
+ },
84
+ {
85
+ url: '/menus/order',
86
+ method: 'PATCH',
87
+ },
88
+ {
89
+ url: '/roles',
90
+ method: 'GET',
91
+ },
92
+ {
93
+ url: '/roles/:roleId',
94
+ method: 'GET',
95
+ },
96
+ {
97
+ url: '/roles/:roleId/users',
98
+ method: 'GET',
99
+ },
100
+ {
101
+ url: '/roles/:roleId/menus',
102
+ method: 'GET',
103
+ },
104
+ {
105
+ url: '/roles/:roleId/routes',
106
+ method: 'GET',
107
+ },
108
+ {
109
+ url: '/roles/:roleId/screens',
110
+ method: 'GET',
111
+ },
112
+ {
113
+ url: '/roles/:roleId/users',
114
+ method: 'PATCH',
115
+ },
116
+ {
117
+ url: '/roles/:roleId/menus',
118
+ method: 'PATCH',
119
+ },
120
+ {
121
+ url: '/roles/:roleId/routes',
122
+ method: 'PATCH',
123
+ },
124
+ {
125
+ url: '/roles/:roleId/screens',
126
+ method: 'PATCH',
127
+ },
128
+ {
129
+ url: '/roles',
130
+ method: 'POST',
131
+ },
132
+ {
133
+ url: '/roles/:roleId',
134
+ method: 'PATCH',
135
+ },
136
+ {
137
+ url: '/roles',
138
+ method: 'DELETE',
139
+ },
140
+ {
141
+ url: '/screens',
142
+ method: 'GET',
143
+ },
144
+ {
145
+ url: '/screens/:screenId',
146
+ method: 'GET',
147
+ },
148
+ {
149
+ url: '/screens/:screenId/roles',
150
+ method: 'GET',
151
+ },
152
+ {
153
+ url: '/screens/:screenId/routes',
154
+ method: 'GET',
155
+ },
156
+ {
157
+ url: '/screens/:screenId/roles',
158
+ method: 'PATCH',
159
+ },
160
+ {
161
+ url: '/screens/:screenId/routes',
162
+ method: 'PATCH',
163
+ },
164
+ {
165
+ url: '/screens',
166
+ method: 'POST',
167
+ },
168
+ {
169
+ url: '/screens/:screenId',
170
+ method: 'PATCH',
171
+ },
172
+ {
173
+ url: '/screens',
174
+ method: 'DELETE',
175
+ },
176
+ {
177
+ url: '/settings',
178
+ method: 'GET',
179
+ },
180
+ {
181
+ url: '/settings/:settingId',
182
+ method: 'GET',
183
+ },
184
+ {
185
+ url: '/settings',
186
+ method: 'POST',
187
+ },
188
+ {
189
+ url: '/settings/:settingId',
190
+ method: 'PATCH',
191
+ },
192
+ {
193
+ url: '/settings',
194
+ method: 'DELETE',
195
+ },
196
+ {
197
+ url: '/users',
198
+ method: 'GET',
199
+ },
200
+ {
201
+ url: '/users/:userId',
202
+ method: 'GET',
203
+ },
204
+ {
205
+ url: '/users/:userId/roles',
206
+ method: 'GET',
207
+ },
208
+ {
209
+ url: '/users',
210
+ method: 'POST',
211
+ },
212
+ {
213
+ url: '/users/:userId',
214
+ method: 'PATCH',
215
+ },
216
+ {
217
+ url: '/users/:userId/roles',
218
+ method: 'PATCH',
219
+ },
220
+ {
221
+ url: '/users',
222
+ method: 'DELETE',
223
+ },
224
+ {
225
+ url: '/routes',
226
+ method: 'GET',
227
+ },
228
+ {
229
+ url: '/routes',
230
+ method: 'POST',
231
+ },
232
+ {
233
+ url: '/routes',
234
+ method: 'DELETE',
235
+ },
236
+ {
237
+ url: '/routes/:routeId',
238
+ method: 'GET',
239
+ },
240
+ {
241
+ url: '/routes/:routeId',
242
+ method: 'PATCH',
243
+ },
244
+ {
245
+ url: '/routes/:routeId/roles',
246
+ method: 'GET',
247
+ },
248
+ {
249
+ url: '/routes/:routeId/roles',
250
+ method: 'PATCH',
251
+ },
252
+ {
253
+ url: '/routes/:routeId/screens',
254
+ method: 'GET',
255
+ },
256
+ {
257
+ url: '/routes/:routeId/screens',
258
+ method: 'PATCH',
259
+ },
260
+ ])
261
+ .execute();
262
+ }
51
263
  async down(queryRunner: QueryRunner) {
52
- await queryRunner.dropTable('role_menus');
264
+ await queryRunner.dropTable('routes');
53
265
  }
54
266
  }