on/off add
This commit is contained in:
39
library/index.js
Normal file
39
library/index.js
Normal file
@@ -0,0 +1,39 @@
|
||||
const configs = require("../configs");
|
||||
const DeviceModel = require("../models/device.model");
|
||||
|
||||
const saveDeviceLog = async (
|
||||
device_id,
|
||||
remote_name,
|
||||
remote_type,
|
||||
operating_type
|
||||
) => {
|
||||
try {
|
||||
// Önce kaydı bulalım
|
||||
const filter = {
|
||||
_id: device_id
|
||||
};
|
||||
|
||||
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ı (library)");
|
||||
}
|
||||
|
||||
return "Log Kaydedildi!";
|
||||
} catch (error) {
|
||||
throw new Error("Mongodb'ye kaydedilirken hata oluştu (library)");
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = { saveDeviceLog };
|
||||
Reference in New Issue
Block a user