Files
smarthome/api/controller/device.get.controller.js
2024-03-23 14:56:45 +03:00

32 lines
851 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const configs = require("../configs");
const DeviceModel = require("../models/device.model");
const get = async (token, device_id) => {
if (token === configs.verifyToken) {
console.log(device_id);
try {
if (!device_id) {
// device_id verilmemişse bütün cihazalara ait bilgileri getir
const result = await DeviceModel.find({});
return result;
} else {
// device_id verilmişse sadece o cihaza ait bilgi getir
const result = await DeviceModel.findOne({
_id: device_id
});
if (result) {
return result;
} else {
throw new Error("Cihaz bulunamadı!");
}
}
} catch (error) {
throw new Error(error.message);
}
} else {
throw new Error("Hatalı token (set.controller)");
}
};
module.exports = { get };