newStaffLDB-API #48

Merged
fred.boniface merged 85 commits from newStaffLDB-API into main 2023-10-03 21:35:03 +01:00
Showing only changes of commit ce592d5cc1 - Show all commits

View File

@ -1,5 +1,6 @@
/* global process */ /* global process */
const log = require("../utils/logs.utils"); // Log Helper const log = require("../utils/logs.utils"); // Log Helper
const logger = require("../utils/logger.utils"); // New Logger
const dbUser = process.env.OWL_DB_USER || "owl"; const dbUser = process.env.OWL_DB_USER || "owl";
const dbPass = process.env.OWL_DB_PASS || "twittwoo"; const dbPass = process.env.OWL_DB_PASS || "twittwoo";
@ -15,17 +16,16 @@ const db = client.db(dbName);
async function query(collection, query, returnId = false) { async function query(collection, query, returnId = false) {
await client.connect(); await client.connect();
log.out(`dbAccess.query: Connecting to collection: '${collection}'`, "info"); logger.logger.debug(`dbAccess.query: Connecting to collection: '${collection}'`)
var qcoll = db.collection(collection); var qcoll = db.collection(collection);
var qcursor = qcoll.find(query); var qcursor = qcoll.find(query);
if (!returnId) { if (!returnId) {
qcursor.project({ _id: 0 }); qcursor.project({ _id: 0 });
} }
log.out(`dbAccess.query: Running Query: ${JSON.stringify(query)}`, "info"); logger.logger.debug(query, "dbAccess.query: Runnung Query")
increment(collection); increment(collection);
log.out("dbAccess.query: Query response:");
let result = await qcursor.toArray(); let result = await qcursor.toArray();
console.log(result); logger.logger.debug(result, "dbAccess.query: Response");
return result; return result;
} }
@ -56,7 +56,7 @@ async function queryAggregate(collection, pipeline) {
} }
async function increment(target) { async function increment(target) {
log.out(`dbAccess.increment: Incrementing counter for: ${target}`, "info"); logger.logger.debug(`dbAccess.increment: Incrementing counter for: ${target}`)
await client.connect(); await client.connect();
let col = db.collection("meta"); let col = db.collection("meta");
let update = {}; let update = {};