Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
createConnection().then(async connection => {
const app = express()
const port = 3000
const options: AdminBroOptions = {
// databases: [connection],
resources: [ Car, CarDealer ]
}
const adminBro = new AdminBro(options)
const router = AdminBroExpress.buildRouter(adminBro)
app.get('/', (req, res) => res.send('Hello World!'))
app.use(adminBro.options.rootPath, router)
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
}).catch(error => console.log(error));
import "reflect-metadata";
import {createConnection} from "typeorm";
import { Car } from "./entity/Car";
import { CarDealer } from "./entity/CarDealer";
import express from 'express'
import AdminBro, { AdminBroOptions } from 'admin-bro'
import * as AdminBroExpress from 'admin-bro-expressjs'
import { Database, Resource } from "admin-bro-typeorm";
import {validate} from 'class-validator'
Resource.validate = validate
AdminBro.registerAdapter({ Database, Resource })
createConnection().then(async connection => {
const app = express()
const port = 3000
const options: AdminBroOptions = {
// databases: [connection],
resources: [ Car, CarDealer ]
}
const adminBro = new AdminBro(options)
const router = AdminBroExpress.buildRouter(adminBro)
app.get('/', (req, res) => res.send('Hello World!'))
app.use(adminBro.options.rootPath, router)
const AdminBro = require('admin-bro')
const AdminBroMongoose = require('admin-bro-mongoose')
const AdminBroSequelizejs = require('admin-bro-sequelizejs')
const sequelize = require('sequelize')
AdminBro.registerAdapter(AdminBroMongoose)
AdminBro.registerAdapter(AdminBroSequelizejs)
const SequelizeDb = require('../sequelize/models')
const menu = {
mongoose: { name: 'Mongoose Resources', icon: 'icon-mongodb' },
sequelize: { name: 'Sequelize Resources', icon: 'icon-postgres' },
customized: { name: 'Customized Resources', icon: 'fas fa-marker' }
}
const user = require('./resources/user')
const page = require('./resources/page')
const blogPost = require('./resources/blog-post')
const article = require('./resources/article')
const complicated = require('./resources/complicated')
const comment = require('./resources/comment')
// const uploads = require('./resources/uploads')
ids.forEach(networkId => {
const networkConfig = getNetworkConfig(networkId);
const sequelize = connection.getConnection(networkId);
const db = models(sequelize);
const options = getBroOptions(db, networkConfig);
const {
Users,
} = db;
AdminBro.registerAdapter(AdminBroSequelize)
const rootPath = `/${networkConfig.networkName}`;
const loginPath = `${rootPath}/admin`;
const logoutPath = `${rootPath}/admin`;
const adminBro = new AdminBro({
...options,
databases: [db],
rootPath,
loginPath,
logoutPath,
});
// Build and use a router which will handle all AdminBro routes
const router = AdminBroExpressjs.buildAuthenticatedRouter(adminBro, {
authenticate: async (email, password) => {
const user = await Users.findOne({ where: {
email: {
actions: {
detailedStats: {
actionType: 'resource',
icon: 'fas fa-signal',
label: 'Resource statistics',
component: AdminBro.require('../components/detailed-stats'),
handler: async (request, response, data) => {
return {true: 'ueas'}
},
},
dontTouchThis: {
actionType: 'record',
label: 'don\'t touch this!!!',
icon: 'fas fa-exclamation',
guard: 'You can setup guards before an action - just in case.',
component: AdminBro.require('../components/dont-touch-this-action'),
handler: async (request, response, data) => {
return {
record: data.record.toJSON()
}
}
}
}
}
// 'user-ninja'
branding: {
companyName: 'Some demo',
},
pages: {
customPage: {
label: "Custom page",
handler: async (request, response, context) => {
return {
text: 'I am fetched from the backend',
}
},
component: AdminBro.bundle('./components/some-stats'),
},
anotherPage: {
label: "TypeScript page",
component: AdminBro.bundle('./components/test-component'),
},
},
dashboard: {
handler: async (request, response, data) => {
const categories = await CategoryModel.find({}).limit(5)
return {
usersCount: await UserModel.countDocuments(),
pagesCount: await PageModel.countDocuments(),
categories: await Promise.all(categories.map(async c => {
const comments = await CommentModel.countDocuments({ category: c._id })
return {
title: c.title,
comments,
_id: c._id,
}
}))
],
version: {
admin: true,
},
branding: {
companyName: 'Some demo',
},
pages: {
customPage: {
label: "Custom page",
handler: async (request, response, context) => {
return {
text: 'I am fetched from the backend',
}
},
component: AdminBro.bundle('./components/some-stats'),
},
anotherPage: {
label: "TypeScript page",
component: AdminBro.bundle('./components/test-component'),
},
},
dashboard: {
handler: async (request, response, data) => {
const categories = await CategoryModel.find({}).limit(5)
return {
usersCount: await UserModel.countDocuments(),
pagesCount: await PageModel.countDocuments(),
categories: await Promise.all(categories.map(async c => {
const comments = await CommentModel.countDocuments({ category: c._id })
return {
title: c.title,
handler: async (request, response, data) => {
const categories = await CategoryModel.find({}).limit(5)
return {
usersCount: await UserModel.countDocuments(),
pagesCount: await PageModel.countDocuments(),
categories: await Promise.all(categories.map(async c => {
const comments = await CommentModel.countDocuments({ category: c._id })
return {
title: c.title,
comments,
_id: c._id,
}
}))
}
},
component: AdminBro.bundle('./components/dashboard'),
},
}
const AdminBro = require('admin-bro')
const { sort, timestamps } = require('./sort')
module.exports = {
name: 'Article (customize field)',
sort,
properties: {
...timestamps,
_id: { isVisible: false },
content: {
type: 'richtext',
},
published: {
label: 'Published (custom render)',
components: {
list: AdminBro.bundle('../components/article-in-list')
}
},
}
}
},
edit: { isAccessible: isAdmin },
delete: { isAccessible: isAdmin },
},
},
},
],
branding: {
logo: '/static/images/logo.svg',
companyName: 'AZTEC',
softwareBrothers: false,
},
dashboard: {
handler: async () => {
},
component: AdminBro.bundle('../components/dashboard'),
},
};
};