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

async function count(req) {
  try {
    let { pid } = req.query;
    console.log(pid);

    await sequelize.authenticate();

    const item = await Item.findOne({ where: { pid } });

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

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

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