Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ export class Menu {
component: string;
@Column()
path: string;
@Column()
locale: string;
}
23 changes: 19 additions & 4 deletions packages/toolkits/pro/template/server/nestJs/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import { existsSync, writeFileSync } from 'fs';
import { UserService } from './user/user.service';
import { RoleService } from './role/role.service';
import { PermissionService } from './permission/permission.service';
import { MenuService } from "./menu/menu.service";
import { Permission } from '@app/models';
import { MenuModule } from './menu/menu.module';
import { ConfigModule, ConfigService } from '@nestjs/config';
import {menuData} from "./menu/init/menuData";

@Module({
imports: [
Expand Down Expand Up @@ -44,20 +46,21 @@ export class AppModule implements OnModuleInit {
constructor(
private user: UserService,
private role: RoleService,
private permission: PermissionService
private permission: PermissionService,
private menu: MenuService,
) {}
async onModuleInit() {
const ROOT = __dirname;
const LOCK_FILE = join(ROOT, 'lock');
if (existsSync(LOCK_FILE)) {
return;
}
// TODO: menu
// TODO: permission
const modules = ['user', 'permission', 'role', 'menu'];
const actions = ['add', 'remove', 'update', 'query'];
const tasks = [];
let permission;
let isInit = true;
const isInit = true;
try {
permission = await this.permission.create(
{
Expand Down Expand Up @@ -85,6 +88,17 @@ export class AppModule implements OnModuleInit {
);
}
}
// TODO Menu
try {
for (const item of menuData){
await this.menu.createMenu(item, isInit)
}
}catch (e){
const err = e as HttpException;
Logger.error(err.message);
Logger.error(`Please clear the database and try again`);
process.exit(-1);
}
const status = Promise.allSettled(tasks);
const statusData = await status;
const hasFail = statusData.some((data) => data.status === 'rejected');
Expand All @@ -98,11 +112,12 @@ export class AppModule implements OnModuleInit {
Logger.error('Please clear the database and try again');
process.exit(-1);
}
const menuId = this.menu.getMenuAllId()
const role = await this.role.create(
{
name: 'admin',
permissionIds: [permission.id],
menuIds: [],
menuIds: await menuId,
},
isInit
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export class CreateMenuDto {
component: string;
@IsNotEmpty()
icon: string;
@IsNotEmpty()
locale: string;

parentId: number | null;
}
Loading