@hedhog/admin 0.0.9 → 0.0.11

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.9",
3
+ "version": "0.0.11",
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', ['name', 'slug', 'description', 'icon'])
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,109 +46,9 @@ export class Migrate implements MigrationInterface {
46
46
  name: 'fk_role_screens_screens',
47
47
  }),
48
48
  ]);
49
-
50
- await queryRunner.manager
51
- .createQueryBuilder()
52
- .insert()
53
- .into('screens', ['name', 'slug', 'description', 'icon'])
54
- .values([
55
- {
56
- name: 'Users',
57
- slug: '/management/users',
58
- description: 'Check all users registered in the system.',
59
- icon: 'users',
60
- },
61
- {
62
- name: 'Roles',
63
- slug: '/management/roles',
64
- description: 'Check all roles registered in the system.',
65
- icon: 'circles',
66
- },
67
- {
68
- name: 'Screens',
69
- slug: '/management/screens',
70
- description: 'Check all screens registered in the system.',
71
- icon: 'monitor',
72
- },
73
- {
74
- name: 'Menus',
75
- slug: '/management/menus',
76
- description: 'Check all menus registered in the system.',
77
- icon: 'menu',
78
- },
79
- ])
80
- .returning('id')
81
- .execute();
82
-
83
- const screenIdScreen = await queryRunner.manager
84
- .createQueryBuilder()
85
- .select()
86
- .from('screens', 's')
87
- .where('slug = :slug', { slug: '/management/screens' })
88
- .execute();
89
-
90
- const screenIdRole = await queryRunner.manager
91
- .createQueryBuilder()
92
- .select()
93
- .from('screens', 's')
94
- .where('slug = :slug', { slug: '/management/roles' })
95
- .execute();
96
-
97
- const screenIdUser = await queryRunner.manager
98
- .createQueryBuilder()
99
- .select()
100
- .from('screens', 's')
101
- .where('slug = :slug', { slug: '/management/users' })
102
- .execute();
103
-
104
- const screenIdMenu = await queryRunner.manager
105
- .createQueryBuilder()
106
- .select()
107
- .from('screens', 's')
108
- .where('slug = :slug', { slug: '/management/menus' })
109
- .execute();
110
-
111
- for (const { url, screendId } of [
112
- { url: '/screens%', screendId: screenIdScreen[0].id },
113
- { url: '/roles%', screendId: screenIdRole[0].id },
114
- { url: '/users%', screendId: screenIdUser[0].id },
115
- { url: '/menus%', screendId: screenIdMenu[0].id },
116
- ]) {
117
- const routesScreens = await queryRunner.manager
118
- .createQueryBuilder()
119
- .select()
120
- .from('routes', 's')
121
- .where('s.url LIKE :url', { url })
122
- .execute();
123
-
124
- for (const route of routesScreens) {
125
- await queryRunner.manager
126
- .createQueryBuilder()
127
- .insert()
128
- .into('route_screens')
129
- .values({
130
- route_id: route.id,
131
- screen_id: screendId,
132
- })
133
- .execute();
134
- }
135
- }
136
49
  }
137
50
 
138
51
  async down(queryRunner: QueryRunner) {
139
- for (const slug of [
140
- '/management/users',
141
- '/management/roles',
142
- '/management/screens',
143
- '/management/menus',
144
- ]) {
145
- await queryRunner.manager
146
- .createQueryBuilder()
147
- .delete()
148
- .from('screens')
149
- .where('slug = :slug', { slug })
150
- .execute();
151
- }
152
52
  await queryRunner.dropTable('role_screens');
153
53
  }
154
54
  }
@@ -1,27 +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
- .select()
8
- .from('screens', 's')
9
- .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
+ );
10
32
 
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
- }
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
+ ]);
22
50
  }
23
51
 
24
52
  async down(queryRunner: QueryRunner) {
25
- await queryRunner.dropTable('role_screens');
53
+ await queryRunner.dropTable('role_users');
26
54
  }
27
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) {
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
+ }