32 lines
851 B
JavaScript
32 lines
851 B
JavaScript
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 };
|