import BaseController from "../../common/base/base_controller";

const facade = require('../models/lossRate');

class LossController extends BaseController {
  async getLossList(req, res) {
    try {
      const { libID } = req.body;
      const data = await facade.getLossList(libID);
      res.json({ error: 0, message: 'getLossList success', data });
    } catch (err) {
      console.log(err);
      res.json({ error: 1, message: err.toString() });
    }
  }

  async saveLossList(req, res) {
    try {
      const data = await facade.save(JSON.parse(req.body.data));
      res.json({ error: 0, message: 'saveLossList success', data });
    } catch (err) {
      console.log(err);
      res.json({ error: 1, message: err.toString() });
    }
  }

  async getItemsBySerialNos(req, res) {
    try {
      const { libID, serialNos } = JSON.parse(req.body.data);
      const data = await facade.getItemsBySerialNos(libID, serialNos);
      res.json({ error: 0, message: 'getItemsBySerialNos success', data });
    } catch (err) {
      console.log(err);
      res.json({ error: 1, message: err.toString() });
    }
  }
}

module.exports = {
  lossController: new LossController()
};