import { Request, Response } from "express";
import { paginateCompanies, setCompanyBanned, updateCompany } from "../services/companies.service";

export const paginate = async (req: Request, res: Response) => {
    try {
        const result = await paginateCompanies(req.body);
        res.json(result);
    } catch (e: any) {
        console.log(e);
        const err = e.response ? e.response.data : e.message;
        res.status(500).json({ error: err });
    }
};

export const update = async (req: Request, res: Response) => {
    try {
        const result = await updateCompany(req.body);
        res.json(result);
    } catch (e: any) {
        console.log(e);
        const err = e.response ? e.response.data : e.message;
        res.status(500).json({ error: err });
    }
};

export const setBanned = async (req: Request, res: Response) => {
    try {
        const result = await setCompanyBanned(req.body);
        res.json(result);
    } catch (e: any) {
        console.log(e);
        const err = e.response ? e.response.data : e.message;
        res.status(500).json({ error: err });
    }
};
