Calling to model from ace command with error

Arise error “Class constructor Transaction cannot be invoked without ‘new’” with following code in ace command

'use strict'

const { Command } = require('@adonisjs/ace')
const Transaction = use('App/Models/Transaction')

class ParseTx extends Command {
  static get signature () {
    return 'parse:tx'
  }

  static get description () {
    return 'Tell something helpful about this command'
  }

  async handle (args, options) {
    this.info('Dummy implementation for parse:tx command')
    await Transaction().find(1)
  }
}

module.exports = ParseTx

Transaction.js

'use strict'

/** @type {typeof import('@adonisjs/lucid/src/Lucid/Model')} */
const Model = use('Model')

class Transaction extends Model {
  static boot() {
    super.boot()

    /**
     * A hook to calculate token balance
     *
     * Look at `app/Models/Hooks/Transaction.js` file
     */
    this.addHook('afterCreate', 'Transaction.calculateTokenBalance')
  }

}

module.exports = Transaction

node version is v10.15.3

package.json

"dependencies": {
    "@adonisjs/ace": "^4.0.7",
    "@adonisjs/auth": "^3.0.7",
    "@adonisjs/bodyparser": "^1.0.8",
    "@adonisjs/cors": "^1.0.2",
    "@adonisjs/fold": "^4.0.5",
    "@adonisjs/framework": "^4.0.27",
    "@adonisjs/ignitor": "^2.0.8",
    "@adonisjs/lucid": "^4.0.22",
    "@adonisjs/session": "^1.0.23",
    "@adonisjs/shield": "^1.0.4",
    "@adonisjs/validator": "^5.0.6",
    "@adonisjs/websocket": "^1.0.11",
    "@adonisjs/websocket-client": "^1.0.9",
    "@nuxtjs/auth": "^4.5.3",
    "@nuxtjs/axios": "^5.4.1",
    "@nuxtjs/dotenv": "^1.3.0",
    "bootstrap": "^4.3.1",
    "bootstrap-vue": "^2.0.0-rc.11",
    "bp-vuejs-dropdown": "^2.1.1",
    "cross-env": "^5.2.0",
    "desandro-matches-selector": "^2.0.2",
    "ev-emitter": "^1.1.1",
    "fizzy-ui-utils": "^2.0.7",
    "flickity": "^2.2.0",
    "get-size": "^2.0.3",
    "gsap": "^2.1.2",
    "imagesloaded": "^4.1.4",
    "jquery": "^3.4.1",
    "lodash": "^4.17.11",
    "nuxt": "^2.4.0",
    "pg": "^7.10.0",
    "popper": "^1.0.1",
    "ssr-window": "^1.0.1",
    "tap-listener": "^2.0.0",
    "unidragger": "^2.3.0",
    "unipointer": "^2.3.0",
    "vue-clickaway": "^2.2.2",
    "web3": "^1.0.0-beta.55"
  },

What im doing wrong?

1 Like

@RFContracts Hi!

You have a typo in your code, it’s not Transaction().find but Transaction.find

Ohhh, work is hard at night(( THX!

1 Like

No problem, you can mark this solved.