/**
 * ==================================================
 * Device Controller
 * ==================================================
 */

const DeviceService =
require("../services/device.service");

exports.dashboard = async (req,res)=>{

    try{

        const statistics =
        await DeviceService.getDashboard();

        res.json({

            success:true,

            statistics

        });

    }

    catch(err){

        console.error(err);

        res.status(500).json({

            success:false,

            message:err.message

        });

    }

};

exports.devices = async (req,res)=>{

    try{

        const devices =
        await DeviceService.getDevices();

        res.json({

            success:true,

            devices

        });

    }

    catch(err){

        res.status(500).json({

            success:false,

            message:err.message

        });

    }

};

exports.device = async (req,res)=>{

    try{

        const device =
        await DeviceService.getDevice(

            req.params.id

        );

        res.json({

            success:true,

            device

        });

    }

    catch(err){

        res.status(500).json({

            success:false,

            message:err.message

        });

    }

};