Cipher-Zero/backend/mongo-db/active-account-dao.js
2024-07-19 22:15:24 +03:00

37 lines
1.3 KiB
JavaScript

//------------------------------------------------------------------------------
// DAO for active account history
// Require index: `db.activeAct.createIndex({timestamp:-1})`
//------------------------------------------------------------------------------
module.exports = class ActiveAccountDAO {
constructor(execDir, client) {
this.client = client;
this.collection = 'activeAct';
}
insert(data, callback) {
this.client.insert(this.collection, data, callback);
}
getLatestRecords(limitNumber = 1, callback) {
const sortObject = { timestamp: -1 };
this.client.getTopRecords(this.collection, {}, sortObject, limitNumber, function (error, recordList) {
var activeActList = []
if (!recordList || recordList.length === 0) {
callback(Error('NO_RECORD'));
return;
}
for (var i = 0; i < recordList.length; i++) {
let activeAct = {};
activeAct.amount = recordList[i].amount;
activeAct.timestamp = recordList[i].timestamp;
activeActList.push(activeAct)
}
callback(error, activeActList)
})
}
getInfoListByTime(start, end, callback) {
const queryObject = { timestamp: { $gte: start, $lte: end } };
this.client.getRecords(this.collection, queryObject, {}, 0, 0, callback);
}
}