bug fix
This commit is contained in:
31
controller/device.get.controller.js
Normal file
31
controller/device.get.controller.js
Normal file
@@ -0,0 +1,31 @@
|
||||
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 };
|
||||
Reference in New Issue
Block a user