@hedhog/admin 0.0.6 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. package/dist/admin.module.d.ts.map +1 -1
  2. package/dist/admin.module.js +1 -0
  3. package/dist/admin.module.js.map +1 -1
  4. package/dist/permission/guards/permission.guard.d.ts +1 -1
  5. package/dist/permission/guards/permission.guard.d.ts.map +1 -1
  6. package/dist/permission/guards/permission.guard.js +4 -0
  7. package/dist/permission/guards/permission.guard.js.map +1 -1
  8. package/package.json +1 -1
  9. package/src/migrations/migrate-04.ts +1 -536
  10. package/src/migrations/migrate-05.ts +48 -0
  11. package/src/migrations/migrate-06.ts +71 -0
  12. package/src/migrations/migrate-07.ts +54 -0
  13. package/src/migrations/migrate-08.ts +121 -0
  14. package/src/migrations/migrate-09.ts +55 -0
  15. package/src/migrations/migrate-10.ts +69 -0
  16. package/src/migrations/migrate-11.ts +91 -0
  17. package/src/migrations/migrate-12.ts +129 -0
  18. package/dist/auth/migrations/index.d.ts +0 -6
  19. package/dist/auth/migrations/index.d.ts.map +0 -1
  20. package/dist/auth/migrations/index.js +0 -121
  21. package/dist/auth/migrations/index.js.map +0 -1
  22. package/dist/menu/migrations/index.d.ts +0 -7
  23. package/dist/menu/migrations/index.d.ts.map +0 -1
  24. package/dist/menu/migrations/index.js +0 -101
  25. package/dist/menu/migrations/index.js.map +0 -1
  26. package/dist/permission/migrations/index.d.ts +0 -6
  27. package/dist/permission/migrations/index.d.ts.map +0 -1
  28. package/dist/permission/migrations/index.js +0 -520
  29. package/dist/permission/migrations/index.js.map +0 -1
  30. package/dist/screen/migrations/index.d.ts +0 -6
  31. package/dist/screen/migrations/index.d.ts.map +0 -1
  32. package/dist/screen/migrations/index.js +0 -40
  33. package/dist/screen/migrations/index.js.map +0 -1
  34. package/dist/user/user.service.spec.d.ts +0 -2
  35. package/dist/user/user.service.spec.d.ts.map +0 -1
  36. package/dist/user/user.service.spec.js +0 -17
  37. package/dist/user/user.service.spec.js.map +0 -1
@@ -0,0 +1,71 @@
1
+ import { timestampColumn } from '@hedhog/utils';
2
+ import {
3
+ MigrationInterface,
4
+ QueryRunner,
5
+ Table,
6
+ TableForeignKey,
7
+ } from 'typeorm';
8
+
9
+ export class Migrate implements MigrationInterface {
10
+ async up(queryRunner: QueryRunner) {
11
+ await queryRunner.createTable(
12
+ new Table({
13
+ name: 'role_menus',
14
+ columns: [
15
+ {
16
+ name: 'role_id',
17
+ type: 'int',
18
+ isPrimary: true,
19
+ unsigned: true,
20
+ },
21
+ {
22
+ name: 'menu_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_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',
47
+ }),
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
+ }
67
+
68
+ async down(queryRunner: QueryRunner) {
69
+ await queryRunner.dropTable('role_menus');
70
+ }
71
+ }
@@ -0,0 +1,54 @@
1
+ import { timestampColumn } from '@hedhog/utils';
2
+ import {
3
+ MigrationInterface,
4
+ QueryRunner,
5
+ Table,
6
+ TableForeignKey,
7
+ } from 'typeorm';
8
+
9
+ export class Migrate implements MigrationInterface {
10
+ async up(queryRunner: QueryRunner) {
11
+ await queryRunner.createTable(
12
+ new Table({
13
+ name: 'route_screens',
14
+ columns: [
15
+ {
16
+ name: 'route_id',
17
+ type: 'int',
18
+ unsigned: true,
19
+ isPrimary: true,
20
+ },
21
+ {
22
+ name: 'screen_id',
23
+ type: 'int',
24
+ unsigned: true,
25
+ isPrimary: true,
26
+ },
27
+ timestampColumn(),
28
+ timestampColumn('updated_at'),
29
+ ],
30
+ }),
31
+ );
32
+
33
+ await queryRunner.createForeignKeys('route_screens', [
34
+ new TableForeignKey({
35
+ columnNames: ['route_id'],
36
+ referencedColumnNames: ['id'],
37
+ referencedTableName: 'routes',
38
+ onDelete: 'CASCADE',
39
+ name: 'fk_route_screens_routes',
40
+ }),
41
+ new TableForeignKey({
42
+ columnNames: ['screen_id'],
43
+ referencedColumnNames: ['id'],
44
+ referencedTableName: 'screens',
45
+ onDelete: 'CASCADE',
46
+ name: 'fk_route_screens_screens',
47
+ }),
48
+ ]);
49
+ }
50
+
51
+ async down(queryRunner: QueryRunner) {
52
+ await queryRunner.dropTable('route_screens');
53
+ }
54
+ }
@@ -0,0 +1,121 @@
1
+ import { timestampColumn } from '@hedhog/utils';
2
+ import {
3
+ MigrationInterface,
4
+ QueryRunner,
5
+ Table,
6
+ TableForeignKey,
7
+ } from 'typeorm';
8
+
9
+ export class Migrate implements MigrationInterface {
10
+ async up(queryRunner: QueryRunner) {
11
+ await queryRunner.createTable(
12
+ new Table({
13
+ name: 'role_screens',
14
+ columns: [
15
+ {
16
+ name: 'role_id',
17
+ type: 'int',
18
+ isPrimary: true,
19
+ unsigned: true,
20
+ },
21
+ {
22
+ name: 'screen_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_screens', [
34
+ new TableForeignKey({
35
+ columnNames: ['role_id'],
36
+ referencedColumnNames: ['id'],
37
+ referencedTableName: 'roles',
38
+ onDelete: 'CASCADE',
39
+ name: 'fk_role_screens_roles',
40
+ }),
41
+ new TableForeignKey({
42
+ columnNames: ['screen_id'],
43
+ referencedColumnNames: ['id'],
44
+ referencedTableName: 'screens',
45
+ onDelete: 'CASCADE',
46
+ name: 'fk_role_screens_screens',
47
+ }),
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
+ }
104
+
105
+ 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
+ await queryRunner.dropTable('role_screens');
120
+ }
121
+ }
@@ -0,0 +1,55 @@
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
+ .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();
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
+ }
50
+
51
+ async down(queryRunner: QueryRunner) {
52
+ await queryRunner.dropTable('screens');
53
+ await queryRunner.dropTable('role_screens');
54
+ }
55
+ }
@@ -0,0 +1,69 @@
1
+ import { timestampColumn } from '@hedhog/utils';
2
+ import {
3
+ MigrationInterface,
4
+ QueryRunner,
5
+ Table,
6
+ TableForeignKey,
7
+ } from 'typeorm';
8
+
9
+ export class Migrate implements MigrationInterface {
10
+ async up(queryRunner: QueryRunner) {
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
+ }
64
+ }
65
+
66
+ async down(queryRunner: QueryRunner) {
67
+ await queryRunner.dropTable('role_users');
68
+ }
69
+ }
@@ -0,0 +1,91 @@
1
+ import { timestampColumn } from '@hedhog/utils';
2
+ import {
3
+ MigrationInterface,
4
+ QueryRunner,
5
+ Table,
6
+ TableForeignKey,
7
+ } from 'typeorm';
8
+
9
+ export class Migrate implements MigrationInterface {
10
+ 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
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
+ }
86
+ }
87
+
88
+ async down(queryRunner: QueryRunner) {
89
+ await queryRunner.dropTable('role_routes');
90
+ }
91
+ }
@@ -0,0 +1,129 @@
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('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
+ ])
123
+ .execute();
124
+ }
125
+
126
+ async down(queryRunner: QueryRunner) {
127
+ await queryRunner.dropTable('routes');
128
+ }
129
+ }
@@ -1,6 +0,0 @@
1
- import { MigrationInterface, QueryRunner } from 'typeorm';
2
- export declare class Migrate implements MigrationInterface {
3
- up(queryRunner: QueryRunner): Promise<void>;
4
- down(queryRunner: QueryRunner): Promise<void>;
5
- }
6
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/auth/migrations/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,WAAW,EAGZ,MAAM,SAAS,CAAC;AAIjB,qBAAa,OAAQ,YAAW,kBAAkB;IAC1C,EAAE,CAAC,WAAW,EAAE,WAAW;IA4F3B,IAAI,CAAC,WAAW,EAAE,WAAW;CAIpC"}