scheduler-node-models 1.2.116 → 1.2.118
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/logging.d.ts +2 -1
- package/config/logging.js +33 -0
- package/package.json +1 -1
- package/users/user.d.ts +12 -1
- package/users/user.js +34 -1
package/config/logging.d.ts
CHANGED
|
@@ -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
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
|
|
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;
|