const ldb = require("../services/ldb.services");

async function get(req, res, next) {
  try {
    var id = req.params.id;
    res.json(await ldb.get(id, true));
  } catch (err) {
    console.error("Unknown Error", err.message);
    err.status = 500;
    next(err);
  }
}

async function getReasonCodeList(req, res, next) {
  try {
    res.json(await ldb.getReasonCodeList());
  } catch (err) {
    console.error("ERROR", err.message);
    err.status = 500;
    next(err);
  }
}

async function getReasonCode(req, res, next) {
  try {
    const code = req.params.code;
    res.json(await ldb.getReasonCode(code));
  } catch (err) {
    console.error("ERROR", err.message);
    err.status = 500;
    next(err);
  }
}

async function getTrainByRID(req, res, next) {
  try {
    const rid = req.params.rid;
    res.json(await ldb.getServiceByRID(rid));
  } catch (err) {
    console.error("ERROR", err);
    err.status = 500;
    next(err);
  }
}

module.exports = {
  get,
  getReasonCodeList,
  getReasonCode,
  getTrainByRID,
};
