mirror of
https://github.com/openmhz/trunk-server.git
synced 2026-11-12 08:47:40 -05:00
switched everything over to Mongoose
This commit is contained in:
@@ -1,16 +1,12 @@
|
||||
|
||||
const { ObjectId } = require('mongodb');
|
||||
var db = require('../db');
|
||||
var mongoose = require("mongoose");
|
||||
var { callModel: Call } = require("../models/call");
|
||||
var Star = require("../models/star");
|
||||
const Group = require("../models/group");
|
||||
|
||||
var defaultNumResults = 50;
|
||||
|
||||
|
||||
var channels = {};
|
||||
|
||||
|
||||
async function get_calls(query, numResults, res) {
|
||||
|
||||
var calls = [];
|
||||
@@ -27,12 +23,9 @@ async function get_calls(query, numResults, res) {
|
||||
url: true
|
||||
};
|
||||
|
||||
const transCollection = db.get().collection('calls');
|
||||
const sort = { length: -1 };
|
||||
try {
|
||||
let cursor = transCollection.find(query.filter, fields).sort(sort).limit(numResults);
|
||||
await cursor.forEach(function (item) {
|
||||
|
||||
for await (const item of Call.find(query.filter, fields).sort(sort).limit(numResults)) {
|
||||
call = {
|
||||
_id: item._id.toHexString(),
|
||||
talkgroupNum: item.talkgroupNum,
|
||||
@@ -45,8 +38,7 @@ async function get_calls(query, numResults, res) {
|
||||
len: Math.round(item.len)
|
||||
};
|
||||
calls.push(call);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
res.contentType('json');
|
||||
res.send(JSON.stringify({
|
||||
@@ -105,13 +97,10 @@ async function build_filter(filter_type, code, start_time, direction, shortName,
|
||||
|
||||
if (filter_type) {
|
||||
if ((filter_type == "group") && code && (code.indexOf(',') == -1)) {
|
||||
const groupCollection = db.get().collection("groups");
|
||||
|
||||
|
||||
|
||||
const group = await groupCollection.findOne({
|
||||
'shortName': shortName,
|
||||
'_id': ObjectId.createFromHexString(code)
|
||||
});
|
||||
const group = await Group.findOne({ 'shortName': shortName, '_id': ObjectId.createFromHexString(code)}).exec();
|
||||
if (!group) {
|
||||
console.warn("[" + shortName + "] Error - build_filter() group is null " + err);
|
||||
res.contentType('json');
|
||||
@@ -173,8 +162,8 @@ exports.get_card = async function (req, res) {
|
||||
}));
|
||||
return;
|
||||
}
|
||||
const transCollection = db.get().collection('calls');
|
||||
const item = await transCollection.findOne({ '_id': o_id });
|
||||
|
||||
const item = await Call.findById(o_id).exec();
|
||||
|
||||
//console.log(util.inspect(item));
|
||||
if (item) {
|
||||
@@ -297,8 +286,7 @@ exports.get_call = async function (req, res) {
|
||||
}));
|
||||
return;
|
||||
}
|
||||
const transCollection = db.get().collection('calls');
|
||||
const item = await transCollection.findOne({ '_id': o_id });
|
||||
const item = await Call.findById(o_id).exec();
|
||||
|
||||
if (item) {
|
||||
var call = package_call(item);
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
var db = require('../db');
|
||||
const Group = require("../models/group");
|
||||
|
||||
exports.get_groups = async function (req, res) {
|
||||
|
||||
const grp_coll = db.get().collection('groups');
|
||||
const cursor = grp_coll.find({ 'shortName': req.params.shortName.toLowerCase() });
|
||||
const grp_results = await cursor.toArray();
|
||||
const grp_results = await Group.find({ shortName: req.params.shortName.toLowerCase()}).sort("position").exec();
|
||||
|
||||
res.contentType('json');
|
||||
res.send(JSON.stringify(grp_results));
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
var db = require('../db');
|
||||
const Talkgroup = require("../models/talkgroup");
|
||||
|
||||
exports.get_talkgroups = async function (req, res) {
|
||||
const tg_coll = db.get().collection('talkgroups');
|
||||
const cursor = tg_coll.find({ 'shortName': req.params.shortName.toLowerCase() })
|
||||
const tg_results = await cursor.toArray();
|
||||
const tg_results = await Talkgroup.find({ 'shortName': req.params.shortName.toLowerCase()})
|
||||
var talkgroups = {};
|
||||
for (var tg in tg_results) {
|
||||
talkgroups[tg_results[tg].num] = tg_results[tg];
|
||||
|
||||
Reference in New Issue
Block a user