import config from '../config.js';

const requireUsername = async (req, res, next) => {
    const { username } = req.body;

    if (!username) return res.status(400).send("Username is required");
    next();
};

const requirePassword = async (req, res, next) => {
    const { password } = req.body;

    if (!password) return res.status(400).send("Password is required");
    next();
};

const requireInviteToken = async (req, res, next) => {
    const { inviteToken } = req.body;

    if (!inviteToken && config.require_token) return res.status(400).send("Invite token is required");
    next();
};

const requireFile = async (req, res, next) => {
    if (!req.file) return res.status(400).send("Please, select a file!");
    next();
}

export default {requireUsername, requirePassword, requireInviteToken, requireFile};