@hedhog/admin 0.0.8 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hedhog/admin",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -32,6 +32,38 @@ export class Migrate implements MigrationInterface {
32
32
  ],
33
33
  }),
34
34
  );
35
+
36
+ await queryRunner.manager
37
+ .createQueryBuilder()
38
+ .insert()
39
+ .into('screens')
40
+ .values([
41
+ {
42
+ name: 'Users',
43
+ slug: '/management/users',
44
+ description: 'Check all users registered in the system.',
45
+ icon: 'users',
46
+ },
47
+ {
48
+ name: 'Roles',
49
+ slug: '/management/roles',
50
+ description: 'Check all roles registered in the system.',
51
+ icon: 'circles',
52
+ },
53
+ {
54
+ name: 'Screens',
55
+ slug: '/management/screens',
56
+ description: 'Check all screens registered in the system.',
57
+ icon: 'monitor',
58
+ },
59
+ {
60
+ name: 'Menus',
61
+ slug: '/management/menus',
62
+ description: 'Check all menus registered in the system.',
63
+ icon: 'menu',
64
+ },
65
+ ])
66
+ .execute();
35
67
  }
36
68
 
37
69
  async down(queryRunner: QueryRunner) {
@@ -31,6 +31,126 @@ export class Migrate implements MigrationInterface {
31
31
  name: 'unique_routes',
32
32
  }),
33
33
  );
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',
66
+ method: 'DELETE',
67
+ },
68
+ {
69
+ url: '/menus/order',
70
+ method: 'PATCH',
71
+ },
72
+ {
73
+ url: '/permissions',
74
+ method: 'GET',
75
+ },
76
+ {
77
+ url: '/permissions/:permissionId',
78
+ method: 'GET',
79
+ },
80
+ {
81
+ url: '/permissions',
82
+ method: 'POST',
83
+ },
84
+ {
85
+ url: '/permissions/:permissionId',
86
+ method: 'PATCH',
87
+ },
88
+ {
89
+ url: '/permissions',
90
+ method: 'DELETE',
91
+ },
92
+ {
93
+ url: '/screens',
94
+ method: 'GET',
95
+ },
96
+ {
97
+ url: '/screens/:screenId',
98
+ method: 'GET',
99
+ },
100
+ {
101
+ url: '/screens',
102
+ method: 'POST',
103
+ },
104
+ {
105
+ url: '/screens/:screenId',
106
+ method: 'PATCH',
107
+ },
108
+ {
109
+ url: '/screens',
110
+ method: 'DELETE',
111
+ },
112
+ {
113
+ url: '/settings',
114
+ method: 'GET',
115
+ },
116
+ {
117
+ url: '/settings/:settingId',
118
+ method: 'GET',
119
+ },
120
+ {
121
+ url: '/settings',
122
+ method: 'POST',
123
+ },
124
+ {
125
+ url: '/settings/:settingId',
126
+ method: 'PATCH',
127
+ },
128
+ {
129
+ url: '/settings',
130
+ method: 'DELETE',
131
+ },
132
+ {
133
+ url: '/users',
134
+ method: 'GET',
135
+ },
136
+ {
137
+ url: '/users/:userId',
138
+ method: 'GET',
139
+ },
140
+ {
141
+ url: '/users',
142
+ method: 'POST',
143
+ },
144
+ {
145
+ url: '/users/:userId',
146
+ method: 'PATCH',
147
+ },
148
+ {
149
+ url: '/users',
150
+ method: 'DELETE',
151
+ },
152
+ ])
153
+ .execute();
34
154
  }
35
155
  async down(queryRunner: QueryRunner) {
36
156
  await queryRunner.dropTable('routes');
@@ -46,23 +46,6 @@ export class Migrate implements MigrationInterface {
46
46
  name: 'fk_role_menus_menus',
47
47
  }),
48
48
  ]);
49
-
50
- const menus = await queryRunner.manager
51
- .createQueryBuilder()
52
- .select()
53
- .from('menus', 'm')
54
- .execute();
55
-
56
- for (const menu of menus) {
57
- await queryRunner.manager
58
- .createQueryBuilder()
59
- .insert()
60
- .into('role_menus')
61
- .values({
62
- role_id: 1,
63
- menu_id: menu.id,
64
- });
65
- }
66
49
  }
67
50
 
68
51
  async down(queryRunner: QueryRunner) {
@@ -46,76 +46,9 @@ export class Migrate implements MigrationInterface {
46
46
  name: 'fk_role_screens_screens',
47
47
  }),
48
48
  ]);
49
-
50
- const screenIdScreen = await queryRunner.manager
51
- .createQueryBuilder()
52
- .select()
53
- .from('screens', 's')
54
- .where('slug = :slug', { slug: '/management/screens' })
55
- .execute();
56
-
57
- const screenIdRole = await queryRunner.manager
58
- .createQueryBuilder()
59
- .select()
60
- .from('screens', 's')
61
- .where('slug = :slug', { slug: '/management/roles' })
62
- .execute();
63
-
64
- const screenIdUser = await queryRunner.manager
65
- .createQueryBuilder()
66
- .select()
67
- .from('screens', 's')
68
- .where('slug = :slug', { slug: '/management/users' })
69
- .execute();
70
-
71
- const screenIdMenu = await queryRunner.manager
72
- .createQueryBuilder()
73
- .select()
74
- .from('screens', 's')
75
- .where('slug = :slug', { slug: '/management/menus' })
76
- .execute();
77
-
78
- for (const { url, screendId } of [
79
- { url: '/screens%', screendId: screenIdScreen[0].id },
80
- { url: '/roles%', screendId: screenIdRole[0].id },
81
- { url: '/users%', screendId: screenIdUser[0].id },
82
- { url: '/menus%', screendId: screenIdMenu[0].id },
83
- ]) {
84
- const routesScreens = await queryRunner.manager
85
- .createQueryBuilder()
86
- .select()
87
- .from('routes', 's')
88
- .where('s.url LIKE :url', { url })
89
- .execute();
90
-
91
- for (const route of routesScreens) {
92
- await queryRunner.manager
93
- .createQueryBuilder()
94
- .insert()
95
- .into('route_screens')
96
- .values({
97
- route_id: route.id,
98
- screen_id: screendId,
99
- })
100
- .execute();
101
- }
102
- }
103
49
  }
104
50
 
105
51
  async down(queryRunner: QueryRunner) {
106
- for (const slug of [
107
- '/management/users',
108
- '/management/roles',
109
- '/management/screens',
110
- '/management/menus',
111
- ]) {
112
- await queryRunner.manager
113
- .createQueryBuilder()
114
- .delete()
115
- .from('screens')
116
- .where('slug = :slug', { slug })
117
- .execute();
118
- }
119
52
  await queryRunner.dropTable('role_screens');
120
53
  }
121
54
  }
@@ -1,55 +1,55 @@
1
- import { MigrationInterface, QueryRunner } from 'typeorm';
1
+ import { timestampColumn } from '@hedhog/utils';
2
+ import {
3
+ MigrationInterface,
4
+ QueryRunner,
5
+ Table,
6
+ TableForeignKey,
7
+ } from 'typeorm';
2
8
 
3
9
  export class Migrate implements MigrationInterface {
4
10
  async up(queryRunner: QueryRunner) {
5
- const screens = await queryRunner.manager
6
- .createQueryBuilder()
7
- .insert()
8
- .into('screens', ['name', 'slug', 'description', 'icon'])
9
- .values([
10
- {
11
- name: 'Users',
12
- slug: '/management/users',
13
- description: 'Check all users registered in the system.',
14
- icon: 'users',
15
- },
16
- {
17
- name: 'Roles',
18
- slug: '/management/roles',
19
- description: 'Check all roles registered in the system.',
20
- icon: 'circles',
21
- },
22
- {
23
- name: 'Screens',
24
- slug: '/management/screens',
25
- description: 'Check all screens registered in the system.',
26
- icon: 'monitor',
27
- },
28
- {
29
- name: 'Menus',
30
- slug: '/management/menus',
31
- description: 'Check all menus registered in the system.',
32
- icon: 'menu',
33
- },
34
- ])
35
- .returning('id')
36
- .execute();
11
+ await queryRunner.createTable(
12
+ new Table({
13
+ name: 'role_users',
14
+ columns: [
15
+ {
16
+ name: 'role_id',
17
+ type: 'int',
18
+ isPrimary: true,
19
+ unsigned: true,
20
+ },
21
+ {
22
+ name: 'user_id',
23
+ type: 'int',
24
+ isPrimary: true,
25
+ unsigned: true,
26
+ },
27
+ timestampColumn(),
28
+ timestampColumn('updated_at'),
29
+ ],
30
+ }),
31
+ );
37
32
 
38
- for (const screen of screens.raw) {
39
- await queryRunner.manager
40
- .createQueryBuilder()
41
- .insert()
42
- .into('role_screens')
43
- .values({
44
- role_id: 1,
45
- screen_id: screen.id,
46
- })
47
- .execute();
48
- }
33
+ await queryRunner.createForeignKeys('role_users', [
34
+ new TableForeignKey({
35
+ columnNames: ['role_id'],
36
+ referencedColumnNames: ['id'],
37
+ referencedTableName: 'roles',
38
+ onDelete: 'CASCADE',
39
+ name: 'fk_role_users_roles',
40
+ }),
41
+
42
+ new TableForeignKey({
43
+ columnNames: ['user_id'],
44
+ referencedColumnNames: ['id'],
45
+ referencedTableName: 'users',
46
+ onDelete: 'CASCADE',
47
+ name: 'fk_role_users_users',
48
+ }),
49
+ ]);
49
50
  }
50
51
 
51
52
  async down(queryRunner: QueryRunner) {
52
- await queryRunner.dropTable('screens');
53
- await queryRunner.dropTable('role_screens');
53
+ await queryRunner.dropTable('role_users');
54
54
  }
55
55
  }
@@ -10,7 +10,7 @@ export class Migrate implements MigrationInterface {
10
10
  async up(queryRunner: QueryRunner) {
11
11
  await queryRunner.createTable(
12
12
  new Table({
13
- name: 'role_users',
13
+ name: 'role_routes',
14
14
  columns: [
15
15
  {
16
16
  name: 'role_id',
@@ -19,7 +19,7 @@ export class Migrate implements MigrationInterface {
19
19
  unsigned: true,
20
20
  },
21
21
  {
22
- name: 'user_id',
22
+ name: 'route_id',
23
23
  type: 'int',
24
24
  isPrimary: true,
25
25
  unsigned: true,
@@ -30,40 +30,25 @@ export class Migrate implements MigrationInterface {
30
30
  }),
31
31
  );
32
32
 
33
- await queryRunner.createForeignKeys('role_users', [
33
+ await queryRunner.createForeignKeys('role_routes', [
34
34
  new TableForeignKey({
35
35
  columnNames: ['role_id'],
36
36
  referencedColumnNames: ['id'],
37
37
  referencedTableName: 'roles',
38
38
  onDelete: 'CASCADE',
39
- name: 'fk_role_users_roles',
39
+ name: 'fk_role_routes_roles',
40
40
  }),
41
-
42
41
  new TableForeignKey({
43
- columnNames: ['user_id'],
42
+ columnNames: ['route_id'],
44
43
  referencedColumnNames: ['id'],
45
- referencedTableName: 'users',
44
+ referencedTableName: 'routes',
46
45
  onDelete: 'CASCADE',
47
- name: 'fk_role_users_users',
46
+ name: 'fk_role_routes_routes',
48
47
  }),
49
48
  ]);
50
-
51
- const roleUsers = [
52
- { role_id: 1, user_id: 1 },
53
- { role_id: 2, user_id: 2 },
54
- ];
55
-
56
- for (const roleUser of roleUsers) {
57
- await queryRunner.manager
58
- .createQueryBuilder()
59
- .insert()
60
- .into('role_users')
61
- .values(roleUser)
62
- .execute();
63
- }
64
49
  }
65
50
 
66
51
  async down(queryRunner: QueryRunner) {
67
- await queryRunner.dropTable('role_users');
52
+ await queryRunner.dropTable('role_routes');
68
53
  }
69
54
  }
@@ -1,91 +1,26 @@
1
- import { timestampColumn } from '@hedhog/utils';
2
- import {
3
- MigrationInterface,
4
- QueryRunner,
5
- Table,
6
- TableForeignKey,
7
- } from 'typeorm';
1
+ import { MigrationInterface, QueryRunner } from 'typeorm';
8
2
 
9
3
  export class Migrate implements MigrationInterface {
10
4
  async up(queryRunner: QueryRunner) {
11
- await queryRunner.createTable(
12
- new Table({
13
- name: 'role_routes',
14
- columns: [
15
- {
16
- name: 'role_id',
17
- type: 'int',
18
- isPrimary: true,
19
- unsigned: true,
20
- },
21
- {
22
- name: 'route_id',
23
- type: 'int',
24
- isPrimary: true,
25
- unsigned: true,
26
- },
27
- timestampColumn(),
28
- timestampColumn('updated_at'),
29
- ],
30
- }),
31
- );
32
-
33
- await queryRunner.createForeignKeys('role_routes', [
34
- new TableForeignKey({
35
- columnNames: ['role_id'],
36
- referencedColumnNames: ['id'],
37
- referencedTableName: 'roles',
38
- onDelete: 'CASCADE',
39
- name: 'fk_role_routes_roles',
40
- }),
41
- new TableForeignKey({
42
- columnNames: ['route_id'],
43
- referencedColumnNames: ['id'],
44
- referencedTableName: 'routes',
45
- onDelete: 'CASCADE',
46
- name: 'fk_role_routes_routes',
47
- }),
48
- ]);
49
-
50
- const routes = await queryRunner.manager
5
+ const menus = await queryRunner.manager
51
6
  .createQueryBuilder()
52
7
  .select()
53
- .from('routes', 'r')
8
+ .from('menus', 'm')
54
9
  .execute();
55
10
 
56
- for (const route of routes) {
11
+ for (const menu of menus) {
57
12
  await queryRunner.manager
58
13
  .createQueryBuilder()
59
14
  .insert()
60
- .into('role_routes')
15
+ .into('role_menus')
61
16
  .values({
62
17
  role_id: 1,
63
- route_id: route.id,
64
- })
65
- .execute();
66
- }
67
-
68
- const routesScreens = await queryRunner.manager
69
- .createQueryBuilder()
70
- .select()
71
- .from('routes', 's')
72
- .where('s.url LIKE :url', { url: '/screens%' })
73
- .execute();
74
-
75
- for (const route of routesScreens) {
76
- await queryRunner.manager
77
- .createQueryBuilder()
78
- .insert()
79
- .into('role_routes')
80
- .values({
81
- role_id: 2,
82
- route_id: route.id,
83
- })
84
- .execute();
18
+ menu_id: menu.id,
19
+ });
85
20
  }
86
21
  }
87
22
 
88
23
  async down(queryRunner: QueryRunner) {
89
- await queryRunner.dropTable('role_routes');
24
+ await queryRunner.manager.delete('role_menus', { role_id: 1 });
90
25
  }
91
26
  }
@@ -2,128 +2,62 @@ import { MigrationInterface, QueryRunner } from 'typeorm';
2
2
 
3
3
  export class Migrate implements MigrationInterface {
4
4
  async up(queryRunner: QueryRunner) {
5
- await queryRunner.manager
5
+ const screenIdScreen = await queryRunner.manager
6
6
  .createQueryBuilder()
7
- .insert()
8
- .into('routes', ['url', 'method'])
9
- .values([
10
- {
11
- url: '/auth/verify',
12
- method: 'GET',
13
- },
14
- {
15
- url: '/menus',
16
- method: 'GET',
17
- },
18
- {
19
- url: '/menus/system',
20
- method: 'GET',
21
- },
22
- {
23
- url: '/menus/:menuId',
24
- method: 'GET',
25
- },
26
- {
27
- url: '/menus',
28
- method: 'POST',
29
- },
30
- {
31
- url: '/menus/:menuId',
32
- method: 'PATCH',
33
- },
34
- {
35
- url: '/menus',
36
- method: 'DELETE',
37
- },
38
- {
39
- url: '/menus/order',
40
- method: 'PATCH',
41
- },
42
- {
43
- url: '/permissions',
44
- method: 'GET',
45
- },
46
- {
47
- url: '/permissions/:permissionId',
48
- method: 'GET',
49
- },
50
- {
51
- url: '/permissions',
52
- method: 'POST',
53
- },
54
- {
55
- url: '/permissions/:permissionId',
56
- method: 'PATCH',
57
- },
58
- {
59
- url: '/permissions',
60
- method: 'DELETE',
61
- },
62
- {
63
- url: '/screens',
64
- method: 'GET',
65
- },
66
- {
67
- url: '/screens/:screenId',
68
- method: 'GET',
69
- },
70
- {
71
- url: '/screens',
72
- method: 'POST',
73
- },
74
- {
75
- url: '/screens/:screenId',
76
- method: 'PATCH',
77
- },
78
- {
79
- url: '/screens',
80
- method: 'DELETE',
81
- },
82
- {
83
- url: '/settings',
84
- method: 'GET',
85
- },
86
- {
87
- url: '/settings/:settingId',
88
- method: 'GET',
89
- },
90
- {
91
- url: '/settings',
92
- method: 'POST',
93
- },
94
- {
95
- url: '/settings/:settingId',
96
- method: 'PATCH',
97
- },
98
- {
99
- url: '/settings',
100
- method: 'DELETE',
101
- },
102
- {
103
- url: '/users',
104
- method: 'GET',
105
- },
106
- {
107
- url: '/users/:userId',
108
- method: 'GET',
109
- },
110
- {
111
- url: '/users',
112
- method: 'POST',
113
- },
114
- {
115
- url: '/users/:userId',
116
- method: 'PATCH',
117
- },
118
- {
119
- url: '/users',
120
- method: 'DELETE',
121
- },
122
- ])
7
+ .select()
8
+ .from('screens', 's')
9
+ .where('slug = :slug', { slug: '/management/screens' })
123
10
  .execute();
11
+
12
+ const screenIdRole = await queryRunner.manager
13
+ .createQueryBuilder()
14
+ .select()
15
+ .from('screens', 's')
16
+ .where('slug = :slug', { slug: '/management/roles' })
17
+ .execute();
18
+
19
+ const screenIdUser = await queryRunner.manager
20
+ .createQueryBuilder()
21
+ .select()
22
+ .from('screens', 's')
23
+ .where('slug = :slug', { slug: '/management/users' })
24
+ .execute();
25
+
26
+ const screenIdMenu = await queryRunner.manager
27
+ .createQueryBuilder()
28
+ .select()
29
+ .from('screens', 's')
30
+ .where('slug = :slug', { slug: '/management/menus' })
31
+ .execute();
32
+
33
+ for (const { url, screendId } of [
34
+ { url: '/screens%', screendId: screenIdScreen[0].id },
35
+ { url: '/roles%', screendId: screenIdRole[0].id },
36
+ { url: '/users%', screendId: screenIdUser[0].id },
37
+ { url: '/menus%', screendId: screenIdMenu[0].id },
38
+ ]) {
39
+ const routesScreens = await queryRunner.manager
40
+ .createQueryBuilder()
41
+ .select()
42
+ .from('routes', 's')
43
+ .where('s.url LIKE :url', { url })
44
+ .execute();
45
+
46
+ for (const route of routesScreens) {
47
+ await queryRunner.manager
48
+ .createQueryBuilder()
49
+ .insert()
50
+ .into('route_screens')
51
+ .values({
52
+ route_id: route.id,
53
+ screen_id: screendId,
54
+ })
55
+ .execute();
56
+ }
57
+ }
124
58
  }
125
59
 
126
60
  async down(queryRunner: QueryRunner) {
127
- await queryRunner.dropTable('routes');
61
+ await queryRunner.manager.delete('route_screens', {});
128
62
  }
129
63
  }
@@ -0,0 +1,20 @@
1
+ import { MigrationInterface, QueryRunner } from 'typeorm';
2
+
3
+ export class Migrate implements MigrationInterface {
4
+ async up(queryRunner: QueryRunner) {
5
+ await queryRunner.manager
6
+ .createQueryBuilder()
7
+ .insert()
8
+ .into('role_users')
9
+ .values([
10
+ { role_id: 1, user_id: 1 },
11
+ { role_id: 2, user_id: 2 },
12
+ ])
13
+ .execute();
14
+ }
15
+
16
+ async down(queryRunner: QueryRunner) {
17
+ await queryRunner.manager.delete('role_users', { role_id: 1 });
18
+ await queryRunner.manager.delete('role_users', { role_id: 2 });
19
+ }
20
+ }
@@ -0,0 +1,47 @@
1
+ import { MigrationInterface, QueryRunner } from 'typeorm';
2
+
3
+ export class Migrate implements MigrationInterface {
4
+ async up(queryRunner: QueryRunner) {
5
+ const routes = await queryRunner.manager
6
+ .createQueryBuilder()
7
+ .select()
8
+ .from('routes', 'r')
9
+ .execute();
10
+
11
+ for (const route of routes) {
12
+ await queryRunner.manager
13
+ .createQueryBuilder()
14
+ .insert()
15
+ .into('role_routes')
16
+ .values({
17
+ role_id: 1,
18
+ route_id: route.id,
19
+ })
20
+ .execute();
21
+ }
22
+
23
+ const routesScreens = await queryRunner.manager
24
+ .createQueryBuilder()
25
+ .select()
26
+ .from('routes', 's')
27
+ .where('s.url LIKE :url', { url: '/screens%' })
28
+ .execute();
29
+
30
+ for (const route of routesScreens) {
31
+ await queryRunner.manager
32
+ .createQueryBuilder()
33
+ .insert()
34
+ .into('role_routes')
35
+ .values({
36
+ role_id: 2,
37
+ route_id: route.id,
38
+ })
39
+ .execute();
40
+ }
41
+ }
42
+
43
+ async down(queryRunner: QueryRunner) {
44
+ await queryRunner.manager.delete('role_routes', { role_id: 1 });
45
+ await queryRunner.manager.delete('role_routes', { role_id: 2 });
46
+ }
47
+ }
@@ -0,0 +1,27 @@
1
+ import { MigrationInterface, QueryRunner } from 'typeorm';
2
+
3
+ export class Migrate implements MigrationInterface {
4
+ async up(queryRunner: QueryRunner) {
5
+ const screens = await queryRunner.manager
6
+ .createQueryBuilder()
7
+ .select()
8
+ .from('screens', 's')
9
+ .execute();
10
+
11
+ for (const screen of screens.raw) {
12
+ await queryRunner.manager
13
+ .createQueryBuilder()
14
+ .insert()
15
+ .into('role_screens')
16
+ .values({
17
+ role_id: 1,
18
+ screen_id: screen.id,
19
+ })
20
+ .execute();
21
+ }
22
+ }
23
+
24
+ async down(queryRunner: QueryRunner) {
25
+ await queryRunner.manager.delete('role_screens', { role_id: 1 });
26
+ }
27
+ }