const services = require('../services')

const { status } = services

const postSetStatus = async (req, res, next) => {
  try {
    var code = 500;

    if (req.body.status) {
      const values = { inputsAlerts: req.body.status.inputsAlerts || [], msn: req.body.msn, id: req.params.id }
      code = await status.createAlerts(values)
      
    } else if (req.body.radioProducts) {
      for (const product of req.body.radioProducts) {
        const values = { inputsAlerts: product.inputsAlerts || [], msn: product.msn, id: req.params.id }
        code = await status.createAlerts(values)
      }
    }
    res.send(code)
  } catch (e) {
    res.sendStatus(500)
  }
}

module.exports = {
  postSetStatus,
}