on/off add

This commit is contained in:
2024-03-06 01:06:40 +03:00
parent c55b16d259
commit 494675c567
8 changed files with 155 additions and 54 deletions

39
library/index.js Normal file
View 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 };