clone:legacy
This commit is contained in:
185
src/app.module.ts
Normal file
185
src/app.module.ts
Normal file
@@ -0,0 +1,185 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { APP_INTERCEPTOR } from '@nestjs/core';
|
||||
import { LoggingInterceptor } from './logging';
|
||||
import { AppController } from './app.controller';
|
||||
import { AppService } from './app.service';
|
||||
import { UserController } from './user/user.controller';
|
||||
import { SystemController } from './system/system.controller';
|
||||
import { WalletController } from './wallet/wallet.controller';
|
||||
import { NodeController } from './node/node.controller';
|
||||
import { BoardController } from './board/board.controller';
|
||||
import { UserService } from './user/user.service';
|
||||
import { BoardService } from './board/board.service';
|
||||
import { NodeService } from './node/node.service';
|
||||
import { SystemService } from './system/system.service';
|
||||
import { WalletService } from './wallet/wallet.service';
|
||||
import { PrismaModule } from './prisma.module';
|
||||
import { FirebaseService } from './firebase/firebase.service';
|
||||
import { FirebaseController } from './firebase/firebase.controller';
|
||||
import { JwtStrategy } from './middleware/jwt.strategy';
|
||||
import { AuthService } from './auth/auth.service';
|
||||
import { JwtModule, JwtService } from '@nestjs/jwt';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { PassportModule } from '@nestjs/passport';
|
||||
import { ServeStaticModule } from '@nestjs/serve-static';
|
||||
import { join } from 'path';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import { ScheduleModule } from '@nestjs/schedule';
|
||||
import { Node2AddressModule } from './node2address/node2address.module';
|
||||
import { LockedCoinModule } from './locked-coin/locked-coin.module';
|
||||
import { TranferHistoriesModule } from './transferhistories/transferhistories.module';
|
||||
|
||||
const prisma = new PrismaClient();
|
||||
|
||||
const DEFAULT_ADMIN = {
|
||||
email: 'code@mnco.dev',
|
||||
password: 'MnCo0310!!@@',
|
||||
};
|
||||
|
||||
const authenticate = async (email: string, password: string) => {
|
||||
if (email === DEFAULT_ADMIN.email && password === DEFAULT_ADMIN.password) {
|
||||
return Promise.resolve(DEFAULT_ADMIN);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
import('@adminjs/nestjs').then(({ AdminModule }) => {
|
||||
return import('adminjs').then(async ({ AdminJS, ComponentLoader }) => {
|
||||
const componentLoader = new ComponentLoader();
|
||||
|
||||
const Components = {
|
||||
MyInput: componentLoader.add(
|
||||
'MyInput',
|
||||
'./components/DecimalComponent',
|
||||
),
|
||||
// other custom components
|
||||
};
|
||||
console.log(Components.MyInput);
|
||||
return import('@adminjs/prisma').then((AdminJSTypeORM) => {
|
||||
AdminJS.registerAdapter({
|
||||
Database: AdminJSTypeORM.Database,
|
||||
Resource: AdminJSTypeORM.Resource,
|
||||
});
|
||||
|
||||
return AdminModule.createAdminAsync({
|
||||
useFactory: () => ({
|
||||
adminJsOptions: {
|
||||
rootPath: '/admin',
|
||||
resources: [
|
||||
{
|
||||
resource: {
|
||||
model: AdminJSTypeORM.getModelByName('Node'),
|
||||
client: prisma,
|
||||
},
|
||||
options: {
|
||||
properties: {
|
||||
balance: {
|
||||
components: {
|
||||
// list: Components.MyInput,
|
||||
// show: Components.MyInput,
|
||||
},
|
||||
},
|
||||
stakedBalance: {
|
||||
components: {
|
||||
// list: Components.MyInput,
|
||||
// show: Components.MyInput,
|
||||
},
|
||||
},
|
||||
computingPower: {
|
||||
components: {
|
||||
// list: Components.MyInput,
|
||||
// show: Components.MyInput,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
resource: {
|
||||
model: AdminJSTypeORM.getModelByName('User'),
|
||||
client: prisma,
|
||||
},
|
||||
options: {},
|
||||
},
|
||||
{
|
||||
resource: {
|
||||
model: AdminJSTypeORM.getModelByName('Category'),
|
||||
client: prisma,
|
||||
},
|
||||
options: {},
|
||||
},
|
||||
{
|
||||
resource: {
|
||||
model: AdminJSTypeORM.getModelByName('LockedCoin'),
|
||||
client: prisma,
|
||||
},
|
||||
options: {},
|
||||
},
|
||||
],
|
||||
componentLoader,
|
||||
},
|
||||
auth: {
|
||||
authenticate,
|
||||
cookieName: 'adminjs',
|
||||
cookiePassword: 'secret!!',
|
||||
},
|
||||
sessionOptions: {
|
||||
resave: true,
|
||||
saveUninitialized: true,
|
||||
secret: 'secret!!',
|
||||
},
|
||||
}),
|
||||
});
|
||||
});
|
||||
});
|
||||
}),
|
||||
ScheduleModule.forRoot(),
|
||||
PrismaModule,
|
||||
ServeStaticModule.forRoot({
|
||||
rootPath: join(__dirname, '..', 'static'),
|
||||
exclude: ['/api*', '/admin*'],
|
||||
}),
|
||||
PassportModule.register({ defaultStrategy: 'jwt' }),
|
||||
ConfigModule,
|
||||
JwtModule.registerAsync({
|
||||
useFactory: async () => ({
|
||||
secretOrPrivateKey: 'MCNOWINS1010!!!!',
|
||||
secret: 'MNCOWINS1010!!!!',
|
||||
signOptions: {
|
||||
expiresIn: `${600000}s`,
|
||||
},
|
||||
}),
|
||||
}),
|
||||
Node2AddressModule,
|
||||
LockedCoinModule,
|
||||
TranferHistoriesModule,
|
||||
],
|
||||
controllers: [
|
||||
AppController,
|
||||
UserController,
|
||||
SystemController,
|
||||
WalletController,
|
||||
NodeController,
|
||||
BoardController,
|
||||
FirebaseController,
|
||||
],
|
||||
providers: [
|
||||
AppService,
|
||||
UserService,
|
||||
BoardService,
|
||||
NodeService,
|
||||
SystemService,
|
||||
WalletService,
|
||||
FirebaseService,
|
||||
AuthService,
|
||||
JwtService,
|
||||
JwtStrategy,
|
||||
{
|
||||
provide: APP_INTERCEPTOR,
|
||||
useClass: LoggingInterceptor,
|
||||
},
|
||||
],
|
||||
})
|
||||
export class AppModule {}
|
||||
Reference in New Issue
Block a user