Files
smarthome/api/library/index.js
2024-03-23 14:56:45 +03:00

40 lines
825 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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: new Date(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 };