A
A
alex kapustsin2018-11-28 10:56:55
JavaScript
alex kapustsin, 2018-11-28 10:56:55

How to properly export a function (errors in eslint)?

There is a page.js controller

import Page from '../models/page';

export async function Create(req, res, next) {
    const pageData = req.body;
    const userId = req.user._id;

    pageData.userId = userId;

    try {
        var page = await Page.create(pageData);
    } catch ({
        message
    }) {
        return next({
            status: 400,
            message
        });
    }
    
    res.json(page);
}

export async function GetAll(req, res, next) {
    res.json('getAll');
}

eslint swears at function declaration
[eslint] Expected a function expression. [func-style]
Tell me how to export this kind of functions?
The second question: Is it right to create controllers for models (post, page, user) or is it better to use methods in models like UserSchema.methods.comparePasswords

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Michael, 2018-11-28
@holysheepcoder

module.exports = {
   GetAll,
   Create
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question