@hedhog/admin 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/src/migrations/migrate-07.ts +10 -74
- package/src/migrations/migrate-08.ts +70 -18
- package/src/migrations/migrate-09.ts +36 -72
- package/src/migrations/migrate-10.ts +61 -121
- package/src/migrations/migrate-11.ts +50 -13
- package/src/migrations/migrate-12.ts +107 -33
package/package.json
CHANGED
@@ -10,19 +10,19 @@ export class Migrate implements MigrationInterface {
|
|
10
10
|
async up(queryRunner: QueryRunner) {
|
11
11
|
await queryRunner.createTable(
|
12
12
|
new Table({
|
13
|
-
name: '
|
13
|
+
name: 'route_screens',
|
14
14
|
columns: [
|
15
15
|
{
|
16
|
-
name: '
|
16
|
+
name: 'route_id',
|
17
17
|
type: 'int',
|
18
|
-
isPrimary: true,
|
19
18
|
unsigned: true,
|
19
|
+
isPrimary: true,
|
20
20
|
},
|
21
21
|
{
|
22
22
|
name: 'screen_id',
|
23
23
|
type: 'int',
|
24
|
-
isPrimary: true,
|
25
24
|
unsigned: true,
|
25
|
+
isPrimary: true,
|
26
26
|
},
|
27
27
|
timestampColumn(),
|
28
28
|
timestampColumn('updated_at'),
|
@@ -30,89 +30,25 @@ export class Migrate implements MigrationInterface {
|
|
30
30
|
}),
|
31
31
|
);
|
32
32
|
|
33
|
-
await queryRunner.createForeignKeys('
|
33
|
+
await queryRunner.createForeignKeys('route_screens', [
|
34
34
|
new TableForeignKey({
|
35
|
-
columnNames: ['
|
35
|
+
columnNames: ['route_id'],
|
36
36
|
referencedColumnNames: ['id'],
|
37
|
-
referencedTableName: '
|
37
|
+
referencedTableName: 'routes',
|
38
38
|
onDelete: 'CASCADE',
|
39
|
-
name: '
|
39
|
+
name: 'fk_route_screens_routes',
|
40
40
|
}),
|
41
41
|
new TableForeignKey({
|
42
42
|
columnNames: ['screen_id'],
|
43
43
|
referencedColumnNames: ['id'],
|
44
44
|
referencedTableName: 'screens',
|
45
45
|
onDelete: 'CASCADE',
|
46
|
-
name: '
|
46
|
+
name: 'fk_route_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
|
-
const screenIdRole = await queryRunner.manager
|
57
|
-
.createQueryBuilder()
|
58
|
-
.select()
|
59
|
-
.from('screens', 's')
|
60
|
-
.where('slug = :slug', { slug: '/management/roles' })
|
61
|
-
.execute();
|
62
|
-
const screenIdUser = await queryRunner.manager
|
63
|
-
.createQueryBuilder()
|
64
|
-
.select()
|
65
|
-
.from('screens', 's')
|
66
|
-
.where('slug = :slug', { slug: '/management/users' })
|
67
|
-
.execute();
|
68
|
-
const screenIdMenu = await queryRunner.manager
|
69
|
-
.createQueryBuilder()
|
70
|
-
.select()
|
71
|
-
.from('screens', 's')
|
72
|
-
.where('slug = :slug', { slug: '/management/menus' })
|
73
|
-
.execute();
|
74
|
-
|
75
|
-
for (const { url, screendId } of [
|
76
|
-
{ url: '/screens%', screendId: screenIdScreen[0].id },
|
77
|
-
{ url: '/roles%', screendId: screenIdRole[0].id },
|
78
|
-
{ url: '/users%', screendId: screenIdUser[0].id },
|
79
|
-
{ url: '/menus%', screendId: screenIdMenu[0].id },
|
80
|
-
]) {
|
81
|
-
const routesScreens = await queryRunner.manager
|
82
|
-
.createQueryBuilder()
|
83
|
-
.select()
|
84
|
-
.from('routes', 's')
|
85
|
-
.where('s.url LIKE :url', { url })
|
86
|
-
.execute();
|
87
|
-
|
88
|
-
for (const route of routesScreens) {
|
89
|
-
await queryRunner.manager
|
90
|
-
.createQueryBuilder()
|
91
|
-
.insert()
|
92
|
-
.into('route_screens')
|
93
|
-
.values({
|
94
|
-
route_id: route.id,
|
95
|
-
screen_id: screendId,
|
96
|
-
})
|
97
|
-
.execute();
|
98
|
-
}
|
99
|
-
}
|
100
49
|
}
|
101
50
|
|
102
51
|
async down(queryRunner: QueryRunner) {
|
103
|
-
|
104
|
-
'/management/users',
|
105
|
-
'/management/roles',
|
106
|
-
'/management/screens',
|
107
|
-
'/management/menus',
|
108
|
-
]) {
|
109
|
-
await queryRunner.manager
|
110
|
-
.createQueryBuilder()
|
111
|
-
.delete()
|
112
|
-
.from('screens')
|
113
|
-
.where('slug = :slug', { slug })
|
114
|
-
.execute();
|
115
|
-
}
|
116
|
-
await queryRunner.dropTable('role_screens');
|
52
|
+
await queryRunner.dropTable('route_screens');
|
117
53
|
}
|
118
54
|
}
|
@@ -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: '
|
13
|
+
name: 'role_screens',
|
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: '
|
22
|
+
name: 'screen_id',
|
23
23
|
type: 'int',
|
24
24
|
isPrimary: true,
|
25
25
|
unsigned: true,
|
@@ -30,40 +30,92 @@ export class Migrate implements MigrationInterface {
|
|
30
30
|
}),
|
31
31
|
);
|
32
32
|
|
33
|
-
await queryRunner.createForeignKeys('
|
33
|
+
await queryRunner.createForeignKeys('role_screens', [
|
34
34
|
new TableForeignKey({
|
35
35
|
columnNames: ['role_id'],
|
36
36
|
referencedColumnNames: ['id'],
|
37
37
|
referencedTableName: 'roles',
|
38
38
|
onDelete: 'CASCADE',
|
39
|
-
name: '
|
39
|
+
name: 'fk_role_screens_roles',
|
40
40
|
}),
|
41
|
-
|
42
41
|
new TableForeignKey({
|
43
|
-
columnNames: ['
|
42
|
+
columnNames: ['screen_id'],
|
44
43
|
referencedColumnNames: ['id'],
|
45
|
-
referencedTableName: '
|
44
|
+
referencedTableName: 'screens',
|
46
45
|
onDelete: 'CASCADE',
|
47
|
-
name: '
|
46
|
+
name: 'fk_role_screens_screens',
|
48
47
|
}),
|
49
48
|
]);
|
50
49
|
|
51
|
-
const
|
52
|
-
|
53
|
-
|
54
|
-
|
50
|
+
const screenIdScreen = await queryRunner.manager
|
51
|
+
.createQueryBuilder()
|
52
|
+
.select()
|
53
|
+
.from('screens', 's')
|
54
|
+
.where('slug = :slug', { slug: '/management/screens' })
|
55
|
+
.execute();
|
55
56
|
|
56
|
-
|
57
|
-
|
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
|
58
85
|
.createQueryBuilder()
|
59
|
-
.
|
60
|
-
.
|
61
|
-
.
|
86
|
+
.select()
|
87
|
+
.from('routes', 's')
|
88
|
+
.where('s.url LIKE :url', { url })
|
62
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
|
+
}
|
63
102
|
}
|
64
103
|
}
|
65
104
|
|
66
105
|
async down(queryRunner: QueryRunner) {
|
67
|
-
|
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
|
+
await queryRunner.dropTable('role_screens');
|
68
120
|
}
|
69
121
|
}
|
@@ -1,91 +1,55 @@
|
|
1
|
-
import {
|
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.
|
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 screens = await queryRunner.manager
|
51
6
|
.createQueryBuilder()
|
52
|
-
.
|
53
|
-
.
|
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')
|
54
36
|
.execute();
|
55
37
|
|
56
|
-
for (const
|
38
|
+
for (const screen of screens.raw) {
|
57
39
|
await queryRunner.manager
|
58
40
|
.createQueryBuilder()
|
59
41
|
.insert()
|
60
|
-
.into('
|
42
|
+
.into('role_screens')
|
61
43
|
.values({
|
62
44
|
role_id: 1,
|
63
|
-
|
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,
|
45
|
+
screen_id: screen.id,
|
83
46
|
})
|
84
47
|
.execute();
|
85
48
|
}
|
86
49
|
}
|
87
50
|
|
88
51
|
async down(queryRunner: QueryRunner) {
|
89
|
-
await queryRunner.dropTable('
|
52
|
+
await queryRunner.dropTable('screens');
|
53
|
+
await queryRunner.dropTable('role_screens');
|
90
54
|
}
|
91
55
|
}
|
@@ -1,129 +1,69 @@
|
|
1
|
-
import {
|
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
|
-
await queryRunner.
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
])
|
123
|
-
.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
|
+
);
|
32
|
+
|
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
|
+
]);
|
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
|
+
}
|
124
64
|
}
|
125
65
|
|
126
66
|
async down(queryRunner: QueryRunner) {
|
127
|
-
await queryRunner.dropTable('
|
67
|
+
await queryRunner.dropTable('role_users');
|
128
68
|
}
|
129
69
|
}
|
@@ -10,19 +10,19 @@ export class Migrate implements MigrationInterface {
|
|
10
10
|
async up(queryRunner: QueryRunner) {
|
11
11
|
await queryRunner.createTable(
|
12
12
|
new Table({
|
13
|
-
name: '
|
13
|
+
name: 'role_routes',
|
14
14
|
columns: [
|
15
15
|
{
|
16
|
-
name: '
|
16
|
+
name: 'role_id',
|
17
17
|
type: 'int',
|
18
|
-
unsigned: true,
|
19
18
|
isPrimary: true,
|
19
|
+
unsigned: true,
|
20
20
|
},
|
21
21
|
{
|
22
|
-
name: '
|
22
|
+
name: 'route_id',
|
23
23
|
type: 'int',
|
24
|
-
unsigned: true,
|
25
24
|
isPrimary: true,
|
25
|
+
unsigned: true,
|
26
26
|
},
|
27
27
|
timestampColumn(),
|
28
28
|
timestampColumn('updated_at'),
|
@@ -30,25 +30,62 @@ export class Migrate implements MigrationInterface {
|
|
30
30
|
}),
|
31
31
|
);
|
32
32
|
|
33
|
-
await queryRunner.createForeignKeys('
|
33
|
+
await queryRunner.createForeignKeys('role_routes', [
|
34
34
|
new TableForeignKey({
|
35
|
-
columnNames: ['
|
35
|
+
columnNames: ['role_id'],
|
36
36
|
referencedColumnNames: ['id'],
|
37
|
-
referencedTableName: '
|
37
|
+
referencedTableName: 'roles',
|
38
38
|
onDelete: 'CASCADE',
|
39
|
-
name: '
|
39
|
+
name: 'fk_role_routes_roles',
|
40
40
|
}),
|
41
41
|
new TableForeignKey({
|
42
|
-
columnNames: ['
|
42
|
+
columnNames: ['route_id'],
|
43
43
|
referencedColumnNames: ['id'],
|
44
|
-
referencedTableName: '
|
44
|
+
referencedTableName: 'routes',
|
45
45
|
onDelete: 'CASCADE',
|
46
|
-
name: '
|
46
|
+
name: 'fk_role_routes_routes',
|
47
47
|
}),
|
48
48
|
]);
|
49
|
+
|
50
|
+
const routes = await queryRunner.manager
|
51
|
+
.createQueryBuilder()
|
52
|
+
.select()
|
53
|
+
.from('routes', 'r')
|
54
|
+
.execute();
|
55
|
+
|
56
|
+
for (const route of routes) {
|
57
|
+
await queryRunner.manager
|
58
|
+
.createQueryBuilder()
|
59
|
+
.insert()
|
60
|
+
.into('role_routes')
|
61
|
+
.values({
|
62
|
+
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();
|
85
|
+
}
|
49
86
|
}
|
50
87
|
|
51
88
|
async down(queryRunner: QueryRunner) {
|
52
|
-
await queryRunner.dropTable('
|
89
|
+
await queryRunner.dropTable('role_routes');
|
53
90
|
}
|
54
91
|
}
|
@@ -2,54 +2,128 @@ import { MigrationInterface, QueryRunner } from 'typeorm';
|
|
2
2
|
|
3
3
|
export class Migrate implements MigrationInterface {
|
4
4
|
async up(queryRunner: QueryRunner) {
|
5
|
-
|
5
|
+
await queryRunner.manager
|
6
6
|
.createQueryBuilder()
|
7
7
|
.insert()
|
8
|
-
.into('
|
8
|
+
.into('routes', ['url', 'method'])
|
9
9
|
.values([
|
10
10
|
{
|
11
|
-
|
12
|
-
|
13
|
-
description: 'Check all users registered in the system.',
|
14
|
-
icon: 'users',
|
11
|
+
url: '/auth/verify',
|
12
|
+
method: 'GET',
|
15
13
|
},
|
16
14
|
{
|
17
|
-
|
18
|
-
|
19
|
-
description: 'Check all roles registered in the system.',
|
20
|
-
icon: 'circles',
|
15
|
+
url: '/menus',
|
16
|
+
method: 'GET',
|
21
17
|
},
|
22
18
|
{
|
23
|
-
|
24
|
-
|
25
|
-
description: 'Check all screens registered in the system.',
|
26
|
-
icon: 'monitor',
|
19
|
+
url: '/menus/system',
|
20
|
+
method: 'GET',
|
27
21
|
},
|
28
22
|
{
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
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',
|
33
121
|
},
|
34
122
|
])
|
35
|
-
.returning('id')
|
36
123
|
.execute();
|
37
|
-
|
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
|
-
}
|
49
124
|
}
|
50
125
|
|
51
126
|
async down(queryRunner: QueryRunner) {
|
52
|
-
await queryRunner.dropTable('
|
53
|
-
await queryRunner.dropTable('role_screens');
|
127
|
+
await queryRunner.dropTable('routes');
|
54
128
|
}
|
55
129
|
}
|