Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres example app #44

Open
namgk opened this issue Aug 1, 2022 · 1 comment
Open

Postgres example app #44

namgk opened this issue Aug 1, 2022 · 1 comment

Comments

@namgk
Copy link

namgk commented Aug 1, 2022

Is there any example app that works with postgres db?

thanks

@mikhin
Copy link

mikhin commented Mar 19, 2024

import { Module } from '@nestjs/common';
import { AdminModule } from '@adminjs/nestjs';
import { ConfigModule } from '@nestjs/config';
import { Database, Resource, getModelByName } from '@adminjs/prisma';
import AdminJS from 'adminjs';
import { PrismaService } from 'nestjs-prisma';

import { AppController } from './app.controller.js';
import { AppService } from './app.service.js';
import provider from './admin/auth-provider.js';

AdminJS.registerAdapter({ Database, Resource });

@Module({
  imports: [
    ConfigModule.forRoot({
      envFilePath: '.env',
    }),
    AdminModule.createAdminAsync({
      useFactory: () => {
        const prisma = new PrismaService();

        return {
          auth: {
            provider,
            cookiePassword: process.env.COOKIE_SECRET,
            cookieName: 'adminjs',
          },
          sessionOptions: {
            resave: true,
            saveUninitialized: true,
            secret: process.env.COOKIE_SECRET,
          },
          adminJsOptions: {
            rootPath: '/admins',
            resources: [
              { resource: { model: getModelByName('User'), client: prisma }, options: {} },
              { resource: { model: getModelByName('Dog'), client: prisma }, options: {} },
              { resource: { model: getModelByName('Hotel'), client: prisma }, options: {} },
              { resource: { model: getModelByName('Service'), client: prisma }, options: {} },
              { resource: { model: getModelByName('Booking'), client: prisma }, options: {} },
              { resource: { model: getModelByName('Payment'), client: prisma }, options: {} },
              { resource: { model: getModelByName('Review'), client: prisma }, options: {} },
            ],
          },
        };
      },
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants