scheduler-node-models 1.2.116 → 1.2.117

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { Logger } from '../general';
1
+ import { LogEntry, Logger } from '../general';
2
2
  export declare const logConnection: {
3
3
  log?: Logger;
4
4
  employeeLog?: Logger;
@@ -6,3 +6,4 @@ export declare const logConnection: {
6
6
  teamLog?: Logger;
7
7
  };
8
8
  export declare function createLogs(application: string): Promise<void>;
9
+ export declare function postLogEntry(application: string, message: string): Promise<LogEntry>;
package/config/logging.js CHANGED
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.logConnection = void 0;
4
4
  exports.createLogs = createLogs;
5
+ exports.postLogEntry = postLogEntry;
5
6
  const general_1 = require("../general");
7
+ const mariadb_1 = require("./mariadb");
6
8
  exports.logConnection = {};
7
9
  async function createLogs(application) {
8
10
  exports.logConnection.log = new general_1.Logger(`${process.env.LOG_DIR}/${application}/process_${(new Date().toDateString())}.log`);
@@ -10,3 +12,34 @@ async function createLogs(application) {
10
12
  exports.logConnection.siteLog = new general_1.Logger(`${process.env.LOG_DIR}/${application}/site_${(new Date().toDateString())}.log`);
11
13
  exports.logConnection.teamLog = new general_1.Logger(`${process.env.LOG_DIR}/${application}/team_${(new Date().toDateString())}.log`);
12
14
  }
15
+ async function postLogEntry(application, message) {
16
+ let conn;
17
+ let logEntry = new general_1.LogEntry();
18
+ try {
19
+ if (mariadb_1.mdbConnection.pool) {
20
+ // get a connection from the db.pool
21
+ conn = await mariadb_1.mdbConnection.pool.getConnection();
22
+ const entryDate = new Date();
23
+ // execute a query for notices for the user
24
+ const insert = `INSERT INTO logentries VALUES ( ?, ?, ?)`;
25
+ const values = [entryDate, application, message];
26
+ const query = `SELECT * FROM logentries ORDER BY application, messageid;`;
27
+ await conn.query(insert, values);
28
+ logEntry = new general_1.LogEntry({
29
+ date: entryDate,
30
+ entry: message
31
+ });
32
+ }
33
+ else {
34
+ throw new Error('No database connection');
35
+ }
36
+ }
37
+ catch (err) {
38
+ throw err;
39
+ }
40
+ finally {
41
+ if (conn)
42
+ conn.release();
43
+ }
44
+ return logEntry;
45
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scheduler-node-models",
3
- "version": "1.2.116",
3
+ "version": "1.2.117",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "files": [