import { Category, sequelize } from './model';

async function list(req) {
  try {
    await sequelize.authenticate();

    const categories = await Category.findAll();

    return { status: 'OK', categories };
  } catch (error) {
    console.error(error);
  }
}

export default async function handler(req, res) {
  try {
    let result = await list(req);

    return res.status(200).send(result);
  } catch (err) {
    console.log(err);
    res.status(200).send({ status: 'error', message: 'list error' });
  }
}
