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

Error: Resource: "logs" does not have an id property #22

Open
sjorobekov opened this issue Jun 21, 2024 · 1 comment
Open

Error: Resource: "logs" does not have an id property #22

sjorobekov opened this issue Jun 21, 2024 · 1 comment

Comments

@sjorobekov
Copy link

sjorobekov commented Jun 21, 2024

// log.resource.ts

import { LucidResource } from '@adminjs/adonis'
import Log from '#models/log'
import { createLoggerResource } from '@adminjs/logger';
import componentLoader from '../../app/admin/component_loader.js'

export default createLoggerResource({
  componentLoader,
  resource: new LucidResource(Log, 'postgres'),
})
// adminjs.ts

import { AdminJSProviderConfig } from '@adminjs/adonis'
import componentLoader from '../app/admin/component_loader.js'
import authProvider from '../app/admin/auth.js'
import { createOrganizationResource } from '#config/resources/organization.resource'
import { createAdminResource } from '#config/resources/admin.resource'
import { createUserResource } from '#config/resources/user.resource'
import LogResource from '#config/resources/log.resource'

const adminjsConfig: AdminJSProviderConfig = {
  adapter: {
    enabled: true,
  },
  adminjs: {
    branding: {
      companyName: 'AdminJS',
      theme: {},
    },
    rootPath: '/admin/',
    loginPath: '/admin/login',
    logoutPath: '/admin/logout',
    componentLoader,
    resources: [
      createOrganizationResource(),
      createUserResource(),
      LogResource,
    ],
    settings: {
      defaultPerPage: 10,
    },
  },
  auth: {
    enabled: true,
    provider: authProvider,
    middlewares: [],
  },
  middlewares: [],
}

export default adminjsConfig

Getting following error:

{
    "message": "Resource: \"logs\" does not have an id property",
    "name": "Error",
    "status": 500,
    "frames": [
        {
            "file": "/projects/gmail/node_modules/adminjs/lib/backend/adapters/record/base-record.js",
            "filePath": "/projects/gmail/node_modules/adminjs/lib/backend/adapters/record/base-record.js",
            "line": 213,
            "callee": "BaseRecord.id",
            "calleeShort": "id",
            "column": 13,
            "context": {
                "start": 208,
                "pre": "   * @return {string | number} id of the Record\n   */\n  id() {\n    const idProperty = this.resource.properties().find(p => p.isId());\n    if (!idProperty) {",
                "line": "      throw new Error(`Resource: \"${this.resource.id()}\" does not have an id property`);",
                "post": "    }\n    return this.params[idProperty.name()];\n  }\n\n  /**"
            },
            "isModule": false,
            "isNative": false,
            "isApp": false
        },
        {
            "file": "/projects/gmail/node_modules/adminjs/lib/backend/adapters/record/base-record.js",
            "filePath": "/projects/gmail/node_modules/adminjs/lib/backend/adapters/record/base-record.js",
            "line": 289,
            "callee": "BaseRecord.toJSON",
            "calleeShort": "toJSON",
            "column": 16,
            "context": {
                "start": 284,
                "pre": "    return {\n      params: this.params,\n      populated,\n      baseError: this.baseError,\n      errors: this.errors,",
                "line": "      id: this.id(),",
                "post": "      title: this.resource.decorate().titleOf(this),\n      recordActions: this.resource.decorate().recordActions(this, currentAdmin).map(recordAction => recordAction.toJSON(currentAdmin)),\n      bulkActions: this.resource.decorate().bulkActions(this, currentAdmin).map(recordAction => recordAction.toJSON(currentAdmin))\n    };\n  }"
            },
            "isModule": false,
            "isNative": false,
            "isApp": false
        },
        {
            "file": "/projects/gmail/node_modules/adminjs/lib/backend/actions/list/list-action.js",
            "filePath": "/projects/gmail/node_modules/adminjs/lib/backend/actions/list/list-action.js",
            "line": 84,
            "callee": "",
            "calleeShort": "",
            "column": 44,
            "context": {
                "start": 79,
                "pre": "        perPage,\n        page,\n        direction: sort?.direction,\n        sortBy: sort?.sortBy\n      },",
                "line": "      records: populatedRecords.map(r => r.toJSON(currentAdmin))",
                "post": "    };\n  }\n};\nexport default ListAction;\n"
            },
            "isModule": false,
            "isNative": false,
            "isApp": false
        },
        {
            "file": "/projects/gmail/node_modules/adminjs/lib/backend/actions/list/list-action.js",
            "filePath": "/projects/gmail/node_modules/adminjs/lib/backend/actions/list/list-action.js",
            "line": 84,
            "callee": "Object.handler",
            "calleeShort": "handler",
            "column": 33,
            "context": {
                "start": 79,
                "pre": "        perPage,\n        page,\n        direction: sort?.direction,\n        sortBy: sort?.sortBy\n      },",
                "line": "      records: populatedRecords.map(r => r.toJSON(currentAdmin))",
                "post": "    };\n  }\n};\nexport default ListAction;\n"
            },
            "isModule": false,
            "isNative": false,
            "isApp": false
        },
        {
            "file": "node:internal/process/task_queues",
            "filePath": "node:internal/process/task_queues",
            "line": 95,
            "callee": "process.processTicksAndRejections",
            "calleeShort": "processTicksAndRejections",
            "column": 5,
            "context": {},
            "isModule": false,
            "isNative": false,
            "isApp": false
        },
        {
            "file": "/projects/gmail/node_modules/adminjs/lib/backend/decorators/action/action-decorator.js",
            "filePath": "/projects/gmail/node_modules/adminjs/lib/backend/decorators/action/action-decorator.js",
            "line": 56,
            "callee": "async ActionDecorator.handler",
            "calleeShort": "handler",
            "column": 19,
            "context": {
                "start": 51,
                "pre": "   */\n  async handler(request, response, context) {\n    try {\n      const modifiedRequest = await this.invokeBeforeHook(request, context);\n      this.canInvokeAction(context);",
                "line": "      const res = await this.invokeHandler(modifiedRequest, response, context);",
                "post": "      return this.invokeAfterHook(res, modifiedRequest, context);\n    } catch (error) {\n      return actionErrorHandler(error, context);\n    }\n  }"
            },
            "isModule": false,
            "isNative": false,
            "isApp": false
        },
        {
            "file": "node_modules/@adminjs/adonis/src/plugin/router.ts",
            "filePath": "/projects/gmail/node_modules/@adminjs/adonis/src/plugin/router.ts",
            "line": 130,
            "callee": "Object.handler",
            "calleeShort": "handler",
            "column": 28,
            "context": {},
            "isModule": true,
            "isNative": false,
            "isApp": false
        },
        {
            "file": "node_modules/@adonisjs/session/src/session_middleware.ts",
            "filePath": "/projects/gmail/node_modules/@adonisjs/session/src/session_middleware.ts",
            "line": 81,
            "callee": "SessionMiddleware.handle",
            "calleeShort": "handle",
            "column": 22,
            "context": {},
            "isModule": true,
            "isNative": false,
            "isApp": false
        }
    ]
}
@maksympryhoda
Copy link

docs does not work
i can't setup the example and it doesnt work out of box

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