scheduler-node-models 1.2.117 → 1.2.119

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.
package/config/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  export * from './logging';
2
- export * from './mariadb';
2
+ export * from './sqldb';
3
3
  export * from './mongoconnect';
4
4
  export * from './logPosting';
package/config/index.js CHANGED
@@ -15,6 +15,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./logging"), exports);
18
- __exportStar(require("./mariadb"), exports);
18
+ __exportStar(require("./sqldb"), exports);
19
19
  __exportStar(require("./mongoconnect"), exports);
20
20
  __exportStar(require("./logPosting"), exports);
package/config/logging.js CHANGED
@@ -4,7 +4,7 @@ exports.logConnection = void 0;
4
4
  exports.createLogs = createLogs;
5
5
  exports.postLogEntry = postLogEntry;
6
6
  const general_1 = require("../general");
7
- const mariadb_1 = require("./mariadb");
7
+ const sqldb_1 = require("./sqldb");
8
8
  exports.logConnection = {};
9
9
  async function createLogs(application) {
10
10
  exports.logConnection.log = new general_1.Logger(`${process.env.LOG_DIR}/${application}/process_${(new Date().toDateString())}.log`);
@@ -16,9 +16,9 @@ async function postLogEntry(application, message) {
16
16
  let conn;
17
17
  let logEntry = new general_1.LogEntry();
18
18
  try {
19
- if (mariadb_1.mdbConnection.pool) {
19
+ if (sqldb_1.mdbConnection.pool) {
20
20
  // get a connection from the db.pool
21
- conn = await mariadb_1.mdbConnection.pool.getConnection();
21
+ conn = await sqldb_1.mdbConnection.pool.getConnection();
22
22
  const entryDate = new Date();
23
23
  // execute a query for notices for the user
24
24
  const insert = `INSERT INTO logentries VALUES ( ?, ?, ?)`;
@@ -0,0 +1,5 @@
1
+ import * as mariadb from 'mariadb';
2
+ export declare const mdbConnection: {
3
+ pool?: mariadb.Pool;
4
+ };
5
+ export declare function createPool(): Promise<void>;
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.mdbConnection = void 0;
37
+ exports.createPool = createPool;
38
+ const mariadb = __importStar(require("mariadb"));
39
+ exports.mdbConnection = {};
40
+ async function createPool() {
41
+ exports.mdbConnection.pool = await mariadb.createPool({
42
+ host: process.env.MYSQL_SERVER,
43
+ port: (process.env.MYSQL_PORT) ? Number(process.env.MYSQL_PORT) : 3306,
44
+ user: process.env.MYSQL_USER,
45
+ password: process.env.MYSQL_PASSWORD,
46
+ database: 'scheduler',
47
+ connectionLimit: 5
48
+ });
49
+ console.log('Connected to mariadb');
50
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scheduler-node-models",
3
- "version": "1.2.117",
3
+ "version": "1.2.119",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "files": [
package/users/user.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { ISecurityQuestion, SecurityQuestion } from './question';
2
+ import { IPermission, Permission } from './permission';
2
3
  /**
3
4
  * The user class and interface.
4
5
  */
@@ -16,11 +17,12 @@ export interface IUser {
16
17
  firstName: string;
17
18
  middleName?: string;
18
19
  lastName: string;
19
- workgroups: string[];
20
+ workgroups?: string[];
20
21
  resettoken?: string;
21
22
  resettokenexp?: Date;
22
23
  additionalEmails?: string[];
23
24
  questions?: ISecurityQuestion[];
25
+ permissions?: IPermission[];
24
26
  }
25
27
  /**
26
28
  * This class represents a user and all the actions available to the user object.
@@ -52,6 +54,7 @@ export declare class User implements IUser {
52
54
  resettokenexp?: Date;
53
55
  additionalEmails: string[];
54
56
  questions: SecurityQuestion[];
57
+ permissions: Permission[];
55
58
  constructor(user?: IUser);
56
59
  /**
57
60
  * This function is used to sort this class' objects into an ordered list. The order
@@ -147,4 +150,12 @@ export declare class User implements IUser {
147
150
  * @returns A boolean value for whether the answers match.
148
151
  */
149
152
  checkSecurityQuestion(id: number, value: string): boolean;
153
+ /**
154
+ * This function will be used to look to ensure the user has a particular job/permission
155
+ * for an application. All checks are done with lower case strings.
156
+ * @param application The string value for the application
157
+ * @param job The string value the job and/or permission to check against.
158
+ * @returns The boolean value for the user having that permission group.
159
+ */
160
+ hasPermission(application: string, job: string): boolean;
150
161
  }
package/users/user.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.User = void 0;
4
4
  const bcrypt_ts_1 = require("bcrypt-ts");
5
5
  const question_1 = require("./question");
6
+ const permission_1 = require("./permission");
6
7
  /**
7
8
  * This class represents a user and all the actions available to the user object.
8
9
  * The main class members are:
@@ -33,6 +34,7 @@ class User {
33
34
  resettokenexp;
34
35
  additionalEmails;
35
36
  questions;
37
+ permissions;
36
38
  constructor(user) {
37
39
  this.id = (user && user.id) ? user.id : '';
38
40
  if (this.id === '') {
@@ -46,7 +48,7 @@ class User {
46
48
  this.middleName = (user) ? user.middleName : undefined;
47
49
  this.lastName = (user) ? user.lastName : '';
48
50
  this.workgroups = [];
49
- if (user) {
51
+ if (user && user.workgroups) {
50
52
  user.workgroups.forEach(wg => {
51
53
  this.workgroups.push(wg);
52
54
  });
@@ -76,6 +78,20 @@ class User {
76
78
  }));
77
79
  }
78
80
  }
81
+ this.permissions = [];
82
+ if (user && user.permissions) {
83
+ user.permissions.forEach(perm => {
84
+ this.permissions.push(new permission_1.Permission({
85
+ application: perm.application,
86
+ job: perm.job
87
+ }));
88
+ });
89
+ }
90
+ if (this.permissions.length === 0 && this.workgroups.length > 0) {
91
+ this.workgroups.forEach(wg => {
92
+ const parts = wg.split('-');
93
+ });
94
+ }
79
95
  }
80
96
  /**
81
97
  * This function is used to sort this class' objects into an ordered list. The order
@@ -300,5 +316,22 @@ class User {
300
316
  });
301
317
  return answer;
302
318
  }
319
+ /**
320
+ * This function will be used to look to ensure the user has a particular job/permission
321
+ * for an application. All checks are done with lower case strings.
322
+ * @param application The string value for the application
323
+ * @param job The string value the job and/or permission to check against.
324
+ * @returns The boolean value for the user having that permission group.
325
+ */
326
+ hasPermission(application, job) {
327
+ let answer = false;
328
+ this.permissions.forEach(perm => {
329
+ if (perm.application.toLowerCase() === application.toLowerCase()
330
+ && perm.job.toLowerCase() === job.toLowerCase()) {
331
+ answer = true;
332
+ }
333
+ });
334
+ return answer;
335
+ }
303
336
  }
304
337
  exports.User = User;