Здравствуйте!
Пытаюсь выбрать людей из БД postgresql таким образом:
const Router = require('express')
const router = new Router()
const mainController = require('../controllers/MainController')
module.exports = function (app) {
app.get('/', (req, res) => {
let as = mainController.getAll;
// console.log(as)
res.end(as);
});
}
Код контроллера такой:
const {Worker} = require('../models/models')
class MainController {
async create(req, res, next) {
let {fio, department, position, phonenumber} = req.body
const worker = await Worker.create({fio, department, position, phonenumber})
return res.json(worker)
}
async getAll(req, res) {
let {fio, department, position, phonenumber} = req.query
let workers;
workers = await Worker.findAll()
return res.json(workers)
// const workers = await Worker.findAll()
// return res.json(workers)
}
}
module.exports = new MainController()
Но вылетает ошибка (node:54008) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'query' of undefined