El repositorio admin-bro-nestjs contiene un ejemplo completo con un ejemplo con mongoose. Pero necesito usarlo con typeorm y postgres.
Traté de adaptar este ejemplo para typeorm:
// main.ts import AdminBro from 'admin-bro'; import { Database, Resource } from '@admin-bro/typeorm'; import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; AdminBro.registerAdapter({ Database, Resource }); const bootstrap = async () => { const app = await NestFactory.create(AppModule); await app.listen(3000); } bootstrap();y
// app.module.ts import { Module } from '@nestjs/common'; import { AdminModule } from '@admin-bro/nestjs'; import { TypeOrmModule, getRepositoryToken } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; import { AppController } from './app.controller'; import { AppService } from './app.service'; import { UserEntity } from './user/user.entity'; @Module({ imports: [ TypeOrmModule.forRoot({ type: 'postgres', host: 'localhost', port: 5432, username: 'postgres', password: 'password', database: 'database_test', entities: [UserEntity], synchronize: true, logging: false, }), AdminModule.createAdminAsync({ imports: [ TypeOrmModule.forFeature([UserEntity]), ], inject: [ getRepositoryToken(UserEntity), ], useFactory: (userRepository: Repository<UserEntity>) => ({ adminBroOptions: { rootPath: '/admin', resources: [ { resource: userRepository }, ], }, auth: { authenticate: async (email, password) => Promise.resolve({ email: 'test' }), cookieName: 'test', cookiePassword: 'testPass', }, }), }), ], controllers: [AppController], providers: [AppService], }) export class AppModule { }Pero al iniciar la aplicación me sale el siguiente error:
NoResourceAdapterError: There are no adapters supporting one of the resource you provided¿Alguien tiene alguna experiencia juntando todas estas bibliotecas?
También obtuve NoResourceAdapterError: There are no adapters supporting one of the resource you provided cuando intenté integrar AdminBro con NestJS/Express/TypeORM (aunque estoy usando MySQL en lugar de Postgres). La solución publicada en el problema de Github de admin-bro-nestjs que vincula a esta pregunta no me ayudó.
La causa de NoResourceAdapterError para mí simplemente fue que UserEntity no extendió BaseEntity . NestJS/TypeORM parece funcionar bien sin extender BaseEntity pero aparentemente es necesario para AdminBro. Puede verlo utilizado en los ejemplos de la documentación del adaptador AdminBro TypeORM .
Aquí hay un ejemplo que funciona para mí.
// user.entity import { Entity, BaseEntity, Column, PrimaryGeneratedColumn } from 'typeorm'; @Entity() export class UserEntity extends BaseEntity{ @PrimaryGeneratedColumn() id: number; @Column() name: string; } // app.module.ts import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; import { AdminModule } from '@admin-bro/nestjs'; import { Database, Resource } from '@admin-bro/typeorm'; import AdminBro from 'admin-bro' AdminBro.registerAdapter({ Database, Resource }); @Module({ imports: [ TypeOrmModule.forRoot({ // ... }), AdminModule.createAdmin({ adminBroOptions: { resources: [UserEntity], rootPath: '/admin', }, }) ], // ... })