Skip to content

Commit

Permalink
feat: add BasePlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
dziraf committed Sep 15, 2022
1 parent 8a6ad93 commit 1a2b12f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/index.ts
Expand Up @@ -5,6 +5,7 @@ export * from './adapters'
export * from './adminjs-options.interface'
export * from './controllers'
export * from './decorators'
export * from './plugins'
export * from './services'
export * from './utils'

Expand Down
20 changes: 20 additions & 0 deletions src/plugins/base-plugin.ts
@@ -0,0 +1,20 @@
/* eslint-disable class-methods-use-this */
import { NotImplementedError } from '@adminjs/common/errors'
import AdminJS from '../adminjs'

class BasePlugin<T = Record<string, unknown>> {
protected admin: AdminJS

protected options: T

constructor(admin: AdminJS, options: T) {
this.admin = admin
this.options = options
}

public buildRoutes() {
throw new NotImplementedError('BasePlugin#buildRoutes')
}
}

export default BasePlugin
1 change: 1 addition & 0 deletions src/plugins/index.ts
@@ -0,0 +1 @@
export { default as BasePlugin } from './base-plugin'
18 changes: 9 additions & 9 deletions src/utils/router/router.ts
@@ -1,27 +1,27 @@
import ApiController from '../../controllers/api-controller'

export type AdminRoute = {
method: string;
path: string;
Controller: any;
action: string;
contentType?: string;
}

/**
* Type representing the AdminJS.Router
* @memberof Router
* @alias RouterType
*/
export type RouterType = {
assets: Array<any>;
routes: Array<{
method: string;
path: string;
Controller: any;
action: string;
contentType?: string;
}>;
routes: Array<AdminRoute>;
}

/**
* @load ./router.doc.md
* @namespace
*/
export const Router: RouterType = {
assets: [], // todo: remove assets
routes: [{
method: 'GET',
path: '/api/resources/{resourceId}/search/{query}',
Expand Down

0 comments on commit 1a2b12f

Please sign in to comment.