40 lines
815 B
JavaScript
40 lines
815 B
JavaScript
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 };
|