on/off add
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const configs = require("../configs");
|
||||
const DeviceModel = require("../models/device.model");
|
||||
const Library = require("../library");
|
||||
|
||||
const set = async (
|
||||
const logSave = async (
|
||||
token,
|
||||
device_id,
|
||||
remote_name,
|
||||
@@ -10,38 +10,20 @@ const set = async (
|
||||
) => {
|
||||
if (token === configs.verifyToken) {
|
||||
try {
|
||||
// Önce kaydı bulalım
|
||||
const filter = {
|
||||
_id: device_id
|
||||
};
|
||||
const result = await Library.saveDeviceLog(
|
||||
device_id,
|
||||
remote_name,
|
||||
remote_type,
|
||||
operating_type
|
||||
);
|
||||
|
||||
const update = {
|
||||
$push: {
|
||||
device_log: {
|
||||
remote_name,
|
||||
remote_type,
|
||||
operating_type,
|
||||
log_time: Date.now()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const result = await DeviceModel.updateOne(filter, update);
|
||||
|
||||
if (result.nModified === 0) {
|
||||
throw new Error("Güncellenmek istenen kayıt bulunamadı");
|
||||
}
|
||||
|
||||
return "Log Kaydedildi!";
|
||||
return result;
|
||||
} catch (error) {
|
||||
// if (error.code === 11000) {
|
||||
// throw new Error("Zaten kaydedilmiş");
|
||||
// }
|
||||
throw new Error("Mongodb'ye kaydedilirken hata oluştu");
|
||||
throw new Error("Mongodb'ye kaydedilirken hata oluştu (log.controller)");
|
||||
}
|
||||
} else {
|
||||
throw new Error("Hatalı token");
|
||||
throw new Error("Hatalı token (log.controller)");
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { set };
|
||||
module.exports = { logSave };
|
||||
|
||||
Reference in New Issue
Block a user