import ParamsService from "../service/params-service.js";
import ApiResult from "../config/api.js";
const ParamsControl = {
  list: async (req, res) => {
    try {
      ParamsService.list(req.body).then(data => {
        res.send(new ApiResult().success(data))
      }).catch((e) => {
        res.send(new ApiResult().error(null, e))
      })
    } catch (e) {
      res.send(new ApiResult().error(e))
    }
  },
  page: async (req, res) => {
    try {
      ParamsService.page(req.body).then(data => {
        res.send(new ApiResult().success(data))
      }).catch((e) => {
        res.send(new ApiResult().error(null, e))
      })
    } catch (e) {
      res.send(new ApiResult().error(e))
    }
  },
  info: async (req, res) => {
    try {
      ParamsService.info(req.params.id).then(data => {
        res.send(new ApiResult().success(data))
      }).catch((e) => {
        res.send(new ApiResult().error(null, e))
      })
    } catch (e) {
      res.send(new ApiResult().error(e))
    }
  },
  add: async (req, res) => {
    try {
      ParamsService.add(req.body).then(data => {
        res.send(new ApiResult().success(data))
      }).catch((e) => {
        res.send(new ApiResult().error(null, e))
      })
    } catch (e) {
      res.send(new ApiResult().error(e))
    }
  },
  edit: async (req, res) => {
    try {
      ParamsService.edit(req.body).then(data => {
        res.send(new ApiResult().success(data))
      }).catch((e) => {
        res.send(new ApiResult().error(null, e))
      })
    } catch (e) {
      res.send(new ApiResult().error(e))
    }
  },
  del: async (req, res) => {
    try {
      ParamsService.del(req.params?.ids?.split(',')).then(data => {
        res.send(new ApiResult().success(data))
      }).catch((e) => {
        res.send(new ApiResult().error(null, e))
      })
    } catch (e) {
      res.send(new ApiResult().error(e))
    }
  },
}
export default ParamsControl