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

async function update(req) {
  try {
    await sequelize.authenticate();
    let { name, description, cid, pid, price } = req.body;

    let category = await Product.update({ name, description, cid: cid, price }, { where: { pid } });

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

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

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