@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.
- package/dist/admin.module.d.ts.map +1 -1
- package/dist/admin.module.js +1 -0
- package/dist/admin.module.js.map +1 -1
- package/dist/permission/guards/permission.guard.d.ts +1 -1
- package/dist/permission/guards/permission.guard.d.ts.map +1 -1
- package/dist/permission/guards/permission.guard.js +4 -0
- package/dist/permission/guards/permission.guard.js.map +1 -1
- package/package.json +1 -1
- package/src/migrations/migrate-04.ts +1 -536
- package/src/migrations/migrate-05.ts +48 -0
- package/src/migrations/migrate-06.ts +71 -0
- package/src/migrations/migrate-07.ts +54 -0
- package/src/migrations/migrate-08.ts +121 -0
- package/src/migrations/migrate-09.ts +55 -0
- package/src/migrations/migrate-10.ts +69 -0
- package/src/migrations/migrate-11.ts +91 -0
- package/src/migrations/migrate-12.ts +129 -0
- package/dist/auth/migrations/index.d.ts +0 -6
- package/dist/auth/migrations/index.d.ts.map +0 -1
- package/dist/auth/migrations/index.js +0 -121
- package/dist/auth/migrations/index.js.map +0 -1
- package/dist/menu/migrations/index.d.ts +0 -7
- package/dist/menu/migrations/index.d.ts.map +0 -1
- package/dist/menu/migrations/index.js +0 -101
- package/dist/menu/migrations/index.js.map +0 -1
- package/dist/permission/migrations/index.d.ts +0 -6
- package/dist/permission/migrations/index.d.ts.map +0 -1
- package/dist/permission/migrations/index.js +0 -520
- package/dist/permission/migrations/index.js.map +0 -1
- package/dist/screen/migrations/index.d.ts +0 -6
- package/dist/screen/migrations/index.d.ts.map +0 -1
- package/dist/screen/migrations/index.js +0 -40
- package/dist/screen/migrations/index.js.map +0 -1
- package/dist/user/user.service.spec.d.ts +0 -2
- package/dist/user/user.service.spec.d.ts.map +0 -1
- package/dist/user/user.service.spec.js +0 -17
- package/dist/user/user.service.spec.js.map +0 -1
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"admin.module.d.ts","sourceRoot":"","sources":["../src/admin.module.ts"],"names":[],"mappings":"AASA,
|
1
|
+
{"version":3,"file":"admin.module.d.ts","sourceRoot":"","sources":["../src/admin.module.ts"],"names":[],"mappings":"AASA,qBAYa,WAAW;CAAG"}
|
package/dist/admin.module.js
CHANGED
@@ -29,6 +29,7 @@ exports.AdminModule = AdminModule = __decorate([
|
|
29
29
|
(0, common_1.forwardRef)(() => screen_module_1.ScreenModule),
|
30
30
|
(0, common_1.forwardRef)(() => user_module_1.UserModule),
|
31
31
|
],
|
32
|
+
exports: [user_module_1.UserModule, auth_module_1.AuthModule, permission_module_1.PermissionModule, menu_module_1.MenuModule, screen_module_1.ScreenModule],
|
32
33
|
})
|
33
34
|
], AdminModule);
|
34
35
|
//# sourceMappingURL=admin.module.js.map
|
package/dist/admin.module.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"admin.module.js","sourceRoot":"","sources":["../src/admin.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA8C;AAC9C,mDAAsD;AACtD,2CAAoD;AACpD,oDAAgD;AAChD,oDAAgD;AAChD,sEAAkE;AAClE,0DAAsD;AACtD,oDAAgD;
|
1
|
+
{"version":3,"file":"admin.module.js","sourceRoot":"","sources":["../src/admin.module.ts"],"names":[],"mappings":";;;;;;;;;AAAA,2CAA8C;AAC9C,mDAAsD;AACtD,2CAAoD;AACpD,oDAAgD;AAChD,oDAAgD;AAChD,sEAAkE;AAClE,0DAAsD;AACtD,oDAAgD;AAczC,IAAM,WAAW,GAAjB,MAAM,WAAW;CAAG,CAAA;AAAd,kCAAW;sBAAX,WAAW;IAZvB,IAAA,eAAM,EAAC;QACN,OAAO,EAAE;YACP,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,wBAAU,CAAC;YAC5B,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,wBAAU,CAAC;YAC5B,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,6BAAgB,CAAC;YAClC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,oCAAgB,CAAC;YAClC,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,qBAAY,CAAC;YAC9B,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,4BAAY,CAAC;YAC9B,IAAA,mBAAU,EAAC,GAAG,EAAE,CAAC,wBAAU,CAAC;SAC7B;QACD,OAAO,EAAE,CAAC,wBAAU,EAAE,wBAAU,EAAE,oCAAgB,EAAE,wBAAU,EAAE,4BAAY,CAAC;KAC9E,CAAC;GACW,WAAW,CAAG"}
|
@@ -3,7 +3,7 @@ import { Reflector } from '@nestjs/core';
|
|
3
3
|
import { PrismaService } from '@hedhog/prisma';
|
4
4
|
export declare class PermissionGuard implements CanActivate {
|
5
5
|
private reflector;
|
6
|
-
private prisma;
|
6
|
+
private readonly prisma;
|
7
7
|
constructor(reflector: Reflector, prisma: PrismaService);
|
8
8
|
canActivate(context: ExecutionContext): Promise<boolean>;
|
9
9
|
private extractTokenFromHeader;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"permission.guard.d.ts","sourceRoot":"","sources":["../../../src/permission/guards/permission.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,gBAAgB,
|
1
|
+
{"version":3,"file":"permission.guard.d.ts","sourceRoot":"","sources":["../../../src/permission/guards/permission.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,gBAAgB,EAMjB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE/C,qBACa,eAAgB,YAAW,WAAW;IAE/C,OAAO,CAAC,SAAS;IAEjB,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAFf,SAAS,EAAE,SAAS,EAEX,MAAM,EAAE,aAAa;IAGlC,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;IAgF9D,OAAO,CAAC,sBAAsB;CAI/B"}
|
@@ -8,6 +8,9 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
10
10
|
};
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
13
|
+
};
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
12
15
|
exports.PermissionGuard = void 0;
|
13
16
|
const common_1 = require("@nestjs/common");
|
@@ -93,6 +96,7 @@ let PermissionGuard = class PermissionGuard {
|
|
93
96
|
exports.PermissionGuard = PermissionGuard;
|
94
97
|
exports.PermissionGuard = PermissionGuard = __decorate([
|
95
98
|
(0, common_1.Injectable)(),
|
99
|
+
__param(1, (0, common_1.Inject)((0, common_1.forwardRef)(() => prisma_1.PrismaService))),
|
96
100
|
__metadata("design:paramtypes", [core_1.Reflector,
|
97
101
|
prisma_1.PrismaService])
|
98
102
|
], PermissionGuard);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"permission.guard.js","sourceRoot":"","sources":["../../../src/permission/guards/permission.guard.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"permission.guard.js","sourceRoot":"","sources":["../../../src/permission/guards/permission.guard.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,2CAQwB;AAExB,uCAAyC;AACzC,wDAA2D;AAC3D,6EAAqE;AACrE,2CAA+C;AAGxC,IAAM,eAAe,GAArB,MAAM,eAAe;IAC1B,YACU,SAAoB,EAEX,MAAqB;QAF9B,cAAS,GAAT,SAAS,CAAW;QAEX,WAAM,GAAN,MAAM,CAAe;IACrC,CAAC;IAEJ,KAAK,CAAC,WAAW,CAAC,OAAyB;;QACzC,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC,iBAAiB,CACrD,sCAAe,EACf,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,OAAO,CAAC,QAAQ,EAAE,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}
|
package/package.json
CHANGED
@@ -1,12 +1,6 @@
|
|
1
1
|
import { idColumn, timestampColumn } from '@hedhog/utils';
|
2
2
|
|
3
|
-
import {
|
4
|
-
MigrationInterface,
|
5
|
-
QueryRunner,
|
6
|
-
Table,
|
7
|
-
TableForeignKey,
|
8
|
-
TableUnique,
|
9
|
-
} from 'typeorm';
|
3
|
+
import { MigrationInterface, QueryRunner, Table, TableUnique } from 'typeorm';
|
10
4
|
|
11
5
|
export class Migrate implements MigrationInterface {
|
12
6
|
async up(queryRunner: QueryRunner) {
|
@@ -37,537 +31,8 @@ export class Migrate implements MigrationInterface {
|
|
37
31
|
name: 'unique_routes',
|
38
32
|
}),
|
39
33
|
);
|
40
|
-
|
41
|
-
await queryRunner.createTable(
|
42
|
-
new Table({
|
43
|
-
name: 'roles',
|
44
|
-
columns: [
|
45
|
-
idColumn(),
|
46
|
-
{
|
47
|
-
name: 'name',
|
48
|
-
type: 'varchar',
|
49
|
-
isNullable: false,
|
50
|
-
},
|
51
|
-
{
|
52
|
-
name: 'description',
|
53
|
-
type: 'varchar',
|
54
|
-
},
|
55
|
-
timestampColumn(),
|
56
|
-
timestampColumn('updated_at'),
|
57
|
-
],
|
58
|
-
}),
|
59
|
-
);
|
60
|
-
|
61
|
-
await queryRunner.createTable(
|
62
|
-
new Table({
|
63
|
-
name: 'role_menus',
|
64
|
-
columns: [
|
65
|
-
{
|
66
|
-
name: 'role_id',
|
67
|
-
type: 'int',
|
68
|
-
isPrimary: true,
|
69
|
-
unsigned: true,
|
70
|
-
},
|
71
|
-
{
|
72
|
-
name: 'menu_id',
|
73
|
-
type: 'int',
|
74
|
-
isPrimary: true,
|
75
|
-
unsigned: true,
|
76
|
-
},
|
77
|
-
timestampColumn(),
|
78
|
-
timestampColumn('updated_at'),
|
79
|
-
],
|
80
|
-
}),
|
81
|
-
);
|
82
|
-
|
83
|
-
await queryRunner.createForeignKeys('role_menus', [
|
84
|
-
new TableForeignKey({
|
85
|
-
columnNames: ['role_id'],
|
86
|
-
referencedColumnNames: ['id'],
|
87
|
-
referencedTableName: 'roles',
|
88
|
-
onDelete: 'CASCADE',
|
89
|
-
name: 'fk_role_menus_roles',
|
90
|
-
}),
|
91
|
-
new TableForeignKey({
|
92
|
-
columnNames: ['menu_id'],
|
93
|
-
referencedColumnNames: ['id'],
|
94
|
-
referencedTableName: 'menus',
|
95
|
-
onDelete: 'CASCADE',
|
96
|
-
name: 'fk_role_menus_menus',
|
97
|
-
}),
|
98
|
-
]);
|
99
|
-
|
100
|
-
await queryRunner.createTable(
|
101
|
-
new Table({
|
102
|
-
name: 'role_screens',
|
103
|
-
columns: [
|
104
|
-
{
|
105
|
-
name: 'role_id',
|
106
|
-
type: 'int',
|
107
|
-
isPrimary: true,
|
108
|
-
unsigned: true,
|
109
|
-
},
|
110
|
-
{
|
111
|
-
name: 'screen_id',
|
112
|
-
type: 'int',
|
113
|
-
isPrimary: true,
|
114
|
-
unsigned: true,
|
115
|
-
},
|
116
|
-
timestampColumn(),
|
117
|
-
timestampColumn('updated_at'),
|
118
|
-
],
|
119
|
-
}),
|
120
|
-
);
|
121
|
-
|
122
|
-
await queryRunner.createForeignKeys('role_screens', [
|
123
|
-
new TableForeignKey({
|
124
|
-
columnNames: ['role_id'],
|
125
|
-
referencedColumnNames: ['id'],
|
126
|
-
referencedTableName: 'roles',
|
127
|
-
onDelete: 'CASCADE',
|
128
|
-
name: 'fk_role_screens_roles',
|
129
|
-
}),
|
130
|
-
new TableForeignKey({
|
131
|
-
columnNames: ['screen_id'],
|
132
|
-
referencedColumnNames: ['id'],
|
133
|
-
referencedTableName: 'screens',
|
134
|
-
onDelete: 'CASCADE',
|
135
|
-
name: 'fk_role_screens_screens',
|
136
|
-
}),
|
137
|
-
]);
|
138
|
-
|
139
|
-
await queryRunner.createTable(
|
140
|
-
new Table({
|
141
|
-
name: 'role_users',
|
142
|
-
columns: [
|
143
|
-
{
|
144
|
-
name: 'role_id',
|
145
|
-
type: 'int',
|
146
|
-
isPrimary: true,
|
147
|
-
unsigned: true,
|
148
|
-
},
|
149
|
-
{
|
150
|
-
name: 'user_id',
|
151
|
-
type: 'int',
|
152
|
-
isPrimary: true,
|
153
|
-
unsigned: true,
|
154
|
-
},
|
155
|
-
timestampColumn(),
|
156
|
-
timestampColumn('updated_at'),
|
157
|
-
],
|
158
|
-
}),
|
159
|
-
);
|
160
|
-
|
161
|
-
await queryRunner.createForeignKeys('role_users', [
|
162
|
-
new TableForeignKey({
|
163
|
-
columnNames: ['role_id'],
|
164
|
-
referencedColumnNames: ['id'],
|
165
|
-
referencedTableName: 'roles',
|
166
|
-
onDelete: 'CASCADE',
|
167
|
-
name: 'fk_role_users_roles',
|
168
|
-
}),
|
169
|
-
|
170
|
-
new TableForeignKey({
|
171
|
-
columnNames: ['user_id'],
|
172
|
-
referencedColumnNames: ['id'],
|
173
|
-
referencedTableName: 'users',
|
174
|
-
onDelete: 'CASCADE',
|
175
|
-
name: 'fk_role_users_users',
|
176
|
-
}),
|
177
|
-
]);
|
178
|
-
|
179
|
-
await queryRunner.createTable(
|
180
|
-
new Table({
|
181
|
-
name: 'role_routes',
|
182
|
-
columns: [
|
183
|
-
{
|
184
|
-
name: 'role_id',
|
185
|
-
type: 'int',
|
186
|
-
isPrimary: true,
|
187
|
-
unsigned: true,
|
188
|
-
},
|
189
|
-
{
|
190
|
-
name: 'route_id',
|
191
|
-
type: 'int',
|
192
|
-
isPrimary: true,
|
193
|
-
unsigned: true,
|
194
|
-
},
|
195
|
-
timestampColumn(),
|
196
|
-
timestampColumn('updated_at'),
|
197
|
-
],
|
198
|
-
}),
|
199
|
-
);
|
200
|
-
|
201
|
-
await queryRunner.createForeignKeys('role_routes', [
|
202
|
-
new TableForeignKey({
|
203
|
-
columnNames: ['role_id'],
|
204
|
-
referencedColumnNames: ['id'],
|
205
|
-
referencedTableName: 'roles',
|
206
|
-
onDelete: 'CASCADE',
|
207
|
-
name: 'fk_role_routes_roles',
|
208
|
-
}),
|
209
|
-
new TableForeignKey({
|
210
|
-
columnNames: ['route_id'],
|
211
|
-
referencedColumnNames: ['id'],
|
212
|
-
referencedTableName: 'routes',
|
213
|
-
onDelete: 'CASCADE',
|
214
|
-
name: 'fk_role_routes_routes',
|
215
|
-
}),
|
216
|
-
]);
|
217
|
-
|
218
|
-
await queryRunner.manager
|
219
|
-
.createQueryBuilder()
|
220
|
-
.insert()
|
221
|
-
.into('routes', ['url', 'method'])
|
222
|
-
.values([
|
223
|
-
{
|
224
|
-
url: '/auth/verify',
|
225
|
-
method: 'GET',
|
226
|
-
},
|
227
|
-
{
|
228
|
-
url: '/menus',
|
229
|
-
method: 'GET',
|
230
|
-
},
|
231
|
-
{
|
232
|
-
url: '/menus/system',
|
233
|
-
method: 'GET',
|
234
|
-
},
|
235
|
-
{
|
236
|
-
url: '/menus/:menuId',
|
237
|
-
method: 'GET',
|
238
|
-
},
|
239
|
-
{
|
240
|
-
url: '/menus',
|
241
|
-
method: 'POST',
|
242
|
-
},
|
243
|
-
{
|
244
|
-
url: '/menus/:menuId',
|
245
|
-
method: 'PATCH',
|
246
|
-
},
|
247
|
-
{
|
248
|
-
url: '/menus',
|
249
|
-
method: 'DELETE',
|
250
|
-
},
|
251
|
-
{
|
252
|
-
url: '/menus/order',
|
253
|
-
method: 'PATCH',
|
254
|
-
},
|
255
|
-
{
|
256
|
-
url: '/permissions',
|
257
|
-
method: 'GET',
|
258
|
-
},
|
259
|
-
{
|
260
|
-
url: '/permissions/:permissionId',
|
261
|
-
method: 'GET',
|
262
|
-
},
|
263
|
-
{
|
264
|
-
url: '/permissions',
|
265
|
-
method: 'POST',
|
266
|
-
},
|
267
|
-
{
|
268
|
-
url: '/permissions/:permissionId',
|
269
|
-
method: 'PATCH',
|
270
|
-
},
|
271
|
-
{
|
272
|
-
url: '/permissions',
|
273
|
-
method: 'DELETE',
|
274
|
-
},
|
275
|
-
{
|
276
|
-
url: '/screens',
|
277
|
-
method: 'GET',
|
278
|
-
},
|
279
|
-
{
|
280
|
-
url: '/screens/:screenId',
|
281
|
-
method: 'GET',
|
282
|
-
},
|
283
|
-
{
|
284
|
-
url: '/screens',
|
285
|
-
method: 'POST',
|
286
|
-
},
|
287
|
-
{
|
288
|
-
url: '/screens/:screenId',
|
289
|
-
method: 'PATCH',
|
290
|
-
},
|
291
|
-
{
|
292
|
-
url: '/screens',
|
293
|
-
method: 'DELETE',
|
294
|
-
},
|
295
|
-
{
|
296
|
-
url: '/settings',
|
297
|
-
method: 'GET',
|
298
|
-
},
|
299
|
-
{
|
300
|
-
url: '/settings/:settingId',
|
301
|
-
method: 'GET',
|
302
|
-
},
|
303
|
-
{
|
304
|
-
url: '/settings',
|
305
|
-
method: 'POST',
|
306
|
-
},
|
307
|
-
{
|
308
|
-
url: '/settings/:settingId',
|
309
|
-
method: 'PATCH',
|
310
|
-
},
|
311
|
-
{
|
312
|
-
url: '/settings',
|
313
|
-
method: 'DELETE',
|
314
|
-
},
|
315
|
-
{
|
316
|
-
url: '/users',
|
317
|
-
method: 'GET',
|
318
|
-
},
|
319
|
-
{
|
320
|
-
url: '/users/:userId',
|
321
|
-
method: 'GET',
|
322
|
-
},
|
323
|
-
{
|
324
|
-
url: '/users',
|
325
|
-
method: 'POST',
|
326
|
-
},
|
327
|
-
{
|
328
|
-
url: '/users/:userId',
|
329
|
-
method: 'PATCH',
|
330
|
-
},
|
331
|
-
{
|
332
|
-
url: '/users',
|
333
|
-
method: 'DELETE',
|
334
|
-
},
|
335
|
-
])
|
336
|
-
.execute();
|
337
|
-
|
338
|
-
await queryRunner.manager
|
339
|
-
.createQueryBuilder()
|
340
|
-
.insert()
|
341
|
-
.into('roles', ['id', 'name', 'description'])
|
342
|
-
.values([
|
343
|
-
{
|
344
|
-
id: 1,
|
345
|
-
name: 'Administrator',
|
346
|
-
description: 'System administrator',
|
347
|
-
},
|
348
|
-
{
|
349
|
-
id: 2,
|
350
|
-
name: 'Screen Manager',
|
351
|
-
description: 'Screen manager',
|
352
|
-
},
|
353
|
-
])
|
354
|
-
.execute();
|
355
|
-
|
356
|
-
const routes = await queryRunner.manager
|
357
|
-
.createQueryBuilder()
|
358
|
-
.select()
|
359
|
-
.from('routes', 'r')
|
360
|
-
.execute();
|
361
|
-
|
362
|
-
for (const route of routes) {
|
363
|
-
await queryRunner.manager
|
364
|
-
.createQueryBuilder()
|
365
|
-
.insert()
|
366
|
-
.into('role_routes')
|
367
|
-
.values({
|
368
|
-
role_id: 1,
|
369
|
-
route_id: route.id,
|
370
|
-
})
|
371
|
-
.execute();
|
372
|
-
}
|
373
|
-
|
374
|
-
const menus = await queryRunner.manager
|
375
|
-
.createQueryBuilder()
|
376
|
-
.select()
|
377
|
-
.from('menus', 'm')
|
378
|
-
.execute();
|
379
|
-
|
380
|
-
for (const menu of menus) {
|
381
|
-
await queryRunner.manager
|
382
|
-
.createQueryBuilder()
|
383
|
-
.insert()
|
384
|
-
.into('role_menus')
|
385
|
-
.values({
|
386
|
-
role_id: 1,
|
387
|
-
menu_id: menu.id,
|
388
|
-
});
|
389
|
-
}
|
390
|
-
|
391
|
-
const routesScreens = await queryRunner.manager
|
392
|
-
.createQueryBuilder()
|
393
|
-
.select()
|
394
|
-
.from('routes', 's')
|
395
|
-
.where('s.url LIKE :url', { url: '/screens%' })
|
396
|
-
.execute();
|
397
|
-
|
398
|
-
for (const route of routesScreens) {
|
399
|
-
await queryRunner.manager
|
400
|
-
.createQueryBuilder()
|
401
|
-
.insert()
|
402
|
-
.into('role_routes')
|
403
|
-
.values({
|
404
|
-
role_id: 2,
|
405
|
-
route_id: route.id,
|
406
|
-
})
|
407
|
-
.execute();
|
408
|
-
}
|
409
|
-
|
410
|
-
await queryRunner.createTable(
|
411
|
-
new Table({
|
412
|
-
name: 'route_screens',
|
413
|
-
columns: [
|
414
|
-
{
|
415
|
-
name: 'route_id',
|
416
|
-
type: 'int',
|
417
|
-
unsigned: true,
|
418
|
-
isPrimary: true,
|
419
|
-
},
|
420
|
-
{
|
421
|
-
name: 'screen_id',
|
422
|
-
type: 'int',
|
423
|
-
unsigned: true,
|
424
|
-
isPrimary: true,
|
425
|
-
},
|
426
|
-
timestampColumn(),
|
427
|
-
timestampColumn('updated_at'),
|
428
|
-
],
|
429
|
-
}),
|
430
|
-
);
|
431
|
-
|
432
|
-
await queryRunner.createForeignKeys('route_screens', [
|
433
|
-
new TableForeignKey({
|
434
|
-
columnNames: ['route_id'],
|
435
|
-
referencedColumnNames: ['id'],
|
436
|
-
referencedTableName: 'routes',
|
437
|
-
onDelete: 'CASCADE',
|
438
|
-
name: 'fk_route_screens_routes',
|
439
|
-
}),
|
440
|
-
new TableForeignKey({
|
441
|
-
columnNames: ['screen_id'],
|
442
|
-
referencedColumnNames: ['id'],
|
443
|
-
referencedTableName: 'screens',
|
444
|
-
onDelete: 'CASCADE',
|
445
|
-
name: 'fk_route_screens_screens',
|
446
|
-
}),
|
447
|
-
]);
|
448
|
-
|
449
|
-
const screens = await queryRunner.manager
|
450
|
-
.createQueryBuilder()
|
451
|
-
.insert()
|
452
|
-
.into('screens', ['name', 'slug', 'description', 'icon'])
|
453
|
-
.values([
|
454
|
-
{
|
455
|
-
name: 'Users',
|
456
|
-
slug: '/management/users',
|
457
|
-
description: 'Check all users registered in the system.',
|
458
|
-
icon: 'users',
|
459
|
-
},
|
460
|
-
{
|
461
|
-
name: 'Roles',
|
462
|
-
slug: '/management/roles',
|
463
|
-
description: 'Check all roles registered in the system.',
|
464
|
-
icon: 'circles',
|
465
|
-
},
|
466
|
-
{
|
467
|
-
name: 'Screens',
|
468
|
-
slug: '/management/screens',
|
469
|
-
description: 'Check all screens registered in the system.',
|
470
|
-
icon: 'monitor',
|
471
|
-
},
|
472
|
-
{
|
473
|
-
name: 'Menus',
|
474
|
-
slug: '/management/menus',
|
475
|
-
description: 'Check all menus registered in the system.',
|
476
|
-
icon: 'menu',
|
477
|
-
},
|
478
|
-
])
|
479
|
-
.returning('id')
|
480
|
-
.execute();
|
481
|
-
|
482
|
-
for (const screen of screens.raw) {
|
483
|
-
await queryRunner.manager
|
484
|
-
.createQueryBuilder()
|
485
|
-
.insert()
|
486
|
-
.into('role_screens')
|
487
|
-
.values({
|
488
|
-
role_id: 1,
|
489
|
-
screen_id: screen.id,
|
490
|
-
})
|
491
|
-
.execute();
|
492
|
-
}
|
493
|
-
|
494
|
-
const screenIdScreen = await queryRunner.manager
|
495
|
-
.createQueryBuilder()
|
496
|
-
.select()
|
497
|
-
.from('screens', 's')
|
498
|
-
.where('slug = :slug', { slug: '/management/screens' })
|
499
|
-
.execute();
|
500
|
-
const screenIdRole = await queryRunner.manager
|
501
|
-
.createQueryBuilder()
|
502
|
-
.select()
|
503
|
-
.from('screens', 's')
|
504
|
-
.where('slug = :slug', { slug: '/management/roles' })
|
505
|
-
.execute();
|
506
|
-
const screenIdUser = await queryRunner.manager
|
507
|
-
.createQueryBuilder()
|
508
|
-
.select()
|
509
|
-
.from('screens', 's')
|
510
|
-
.where('slug = :slug', { slug: '/management/users' })
|
511
|
-
.execute();
|
512
|
-
const screenIdMenu = await queryRunner.manager
|
513
|
-
.createQueryBuilder()
|
514
|
-
.select()
|
515
|
-
.from('screens', 's')
|
516
|
-
.where('slug = :slug', { slug: '/management/menus' })
|
517
|
-
.execute();
|
518
|
-
|
519
|
-
for (const { url, screendId } of [
|
520
|
-
{ url: '/screens%', screendId: screenIdScreen[0].id },
|
521
|
-
{ url: '/roles%', screendId: screenIdRole[0].id },
|
522
|
-
{ url: '/users%', screendId: screenIdUser[0].id },
|
523
|
-
{ url: '/menus%', screendId: screenIdMenu[0].id },
|
524
|
-
]) {
|
525
|
-
const routesScreens = await queryRunner.manager
|
526
|
-
.createQueryBuilder()
|
527
|
-
.select()
|
528
|
-
.from('routes', 's')
|
529
|
-
.where('s.url LIKE :url', { url })
|
530
|
-
.execute();
|
531
|
-
|
532
|
-
for (const route of routesScreens) {
|
533
|
-
console.log({
|
534
|
-
route_id: route.id,
|
535
|
-
screen_id: screendId,
|
536
|
-
});
|
537
|
-
|
538
|
-
await queryRunner.manager
|
539
|
-
.createQueryBuilder()
|
540
|
-
.insert()
|
541
|
-
.into('route_screens')
|
542
|
-
.values({
|
543
|
-
route_id: route.id,
|
544
|
-
screen_id: screendId,
|
545
|
-
})
|
546
|
-
.execute();
|
547
|
-
}
|
548
|
-
}
|
549
34
|
}
|
550
35
|
async down(queryRunner: QueryRunner) {
|
551
|
-
for (const slug of [
|
552
|
-
'/management/users',
|
553
|
-
'/management/roles',
|
554
|
-
'/management/screens',
|
555
|
-
'/management/menus',
|
556
|
-
]) {
|
557
|
-
await queryRunner.manager
|
558
|
-
.createQueryBuilder()
|
559
|
-
.delete()
|
560
|
-
.from('screens')
|
561
|
-
.where('slug = :slug', { slug })
|
562
|
-
.execute();
|
563
|
-
}
|
564
|
-
|
565
|
-
await queryRunner.dropTable('role_routes');
|
566
|
-
await queryRunner.dropTable('role_screens');
|
567
|
-
await queryRunner.dropTable('role_users');
|
568
|
-
await queryRunner.dropTable('role_menus');
|
569
|
-
await queryRunner.dropTable('roles');
|
570
|
-
await queryRunner.dropTable('route_screens');
|
571
36
|
await queryRunner.dropTable('routes');
|
572
37
|
}
|
573
38
|
}
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import { idColumn, timestampColumn } from '@hedhog/utils';
|
2
|
+
import { MigrationInterface, QueryRunner, Table } from 'typeorm';
|
3
|
+
|
4
|
+
export class Migrate implements MigrationInterface {
|
5
|
+
async up(queryRunner: QueryRunner) {
|
6
|
+
await queryRunner.createTable(
|
7
|
+
new Table({
|
8
|
+
name: 'roles',
|
9
|
+
columns: [
|
10
|
+
idColumn(),
|
11
|
+
{
|
12
|
+
name: 'name',
|
13
|
+
type: 'varchar',
|
14
|
+
isNullable: false,
|
15
|
+
},
|
16
|
+
{
|
17
|
+
name: 'description',
|
18
|
+
type: 'varchar',
|
19
|
+
},
|
20
|
+
timestampColumn(),
|
21
|
+
timestampColumn('updated_at'),
|
22
|
+
],
|
23
|
+
}),
|
24
|
+
);
|
25
|
+
|
26
|
+
await queryRunner.manager
|
27
|
+
.createQueryBuilder()
|
28
|
+
.insert()
|
29
|
+
.into('roles', ['id', 'name', 'description'])
|
30
|
+
.values([
|
31
|
+
{
|
32
|
+
id: 1,
|
33
|
+
name: 'Administrator',
|
34
|
+
description: 'System administrator',
|
35
|
+
},
|
36
|
+
{
|
37
|
+
id: 2,
|
38
|
+
name: 'Screen Manager',
|
39
|
+
description: 'Screen manager',
|
40
|
+
},
|
41
|
+
])
|
42
|
+
.execute();
|
43
|
+
}
|
44
|
+
|
45
|
+
async down(queryRunner: QueryRunner) {
|
46
|
+
await queryRunner.dropTable('roles');
|
47
|
+
}
|
48
|
+
}
|