diff --git a/.gitignore b/.gitignore index 99a2ba8..7650795 100644 --- a/.gitignore +++ b/.gitignore @@ -17,5 +17,6 @@ package-lock.json settings.json Procfile dump.rdb - error.log - output.log \ No newline at end of file +error.log +output.log +Dockerfile \ No newline at end of file diff --git a/controller/device.get.controller.js b/controller/device.get.controller.js new file mode 100644 index 0000000..6d1ba36 --- /dev/null +++ b/controller/device.get.controller.js @@ -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 }; diff --git a/controller/device.set.controller.js b/controller/device.set.controller.js index aec8409..5e0451b 100644 --- a/controller/device.set.controller.js +++ b/controller/device.set.controller.js @@ -1,4 +1,3 @@ -const config = require("../configs"); const configs = require("../configs"); const Library = require("../library"); const DeviceModel = require("../models/device.model");