48 lines
1020 B
JavaScript
48 lines
1020 B
JavaScript
const configs = require("../configs");
|
||
const DeviceModel = require("../models/device.model");
|
||
|
||
const set = async (
|
||
token,
|
||
device_id,
|
||
remote_name,
|
||
remote_type,
|
||
operating_type
|
||
) => {
|
||
if (token === configs.verifyToken) {
|
||
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ı");
|
||
}
|
||
|
||
return "Log Kaydedildi!";
|
||
} catch (error) {
|
||
// if (error.code === 11000) {
|
||
// throw new Error("Zaten kaydedilmiş");
|
||
// }
|
||
throw new Error("Mongodb'ye kaydedilirken hata oluştu");
|
||
}
|
||
} else {
|
||
throw new Error("Hatalı token");
|
||
}
|
||
};
|
||
|
||
module.exports = { set };
|