scheduler-node-models 1.3.1 → 1.3.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "scheduler-node-models",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "files": [
package/config/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export * from './logging';
2
- export * from './sqldb';
3
- export * from './mongoconnect';
4
- export * from './logPosting';
package/config/index.js DELETED
@@ -1,21 +0,0 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./logging"), exports);
18
- __exportStar(require("./sqldb"), exports);
19
- __exportStar(require("./mongoconnect"), exports);
20
- __exportStar(require("./logPosting"), exports);
21
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,4CAA0B;AAC1B,0CAAwB;AACxB,iDAA+B;AAC/B,+CAA6B"}
@@ -1 +0,0 @@
1
- export declare function postMessage(application: string, message: string): void;
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.postMessage = postMessage;
4
- function postMessage(application, message) {
5
- const postData = {
6
- application: application,
7
- message: message
8
- };
9
- if (process.env.logurl) {
10
- fetch(process.env.logurl, {
11
- method: 'POST',
12
- headers: {
13
- 'Content-Type': 'application/json'
14
- },
15
- body: JSON.stringify(postData)
16
- });
17
- }
18
- }
19
- //# sourceMappingURL=logPosting.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logPosting.js","sourceRoot":"","sources":["../../src/config/logPosting.ts"],"names":[],"mappings":";;AAAA,kCAeC;AAfD,SAAgB,WAAW,CAAC,WAAmB,EAAE,OAAe;IAC9D,MAAM,QAAQ,GAAG;QACf,WAAW,EAAE,WAAW;QACxB,OAAO,EAAE,OAAO;KACjB,CAAC;IAEF,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;QACvB,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE;YACxB,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;aACnC;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC;SAC/B,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
@@ -1,9 +0,0 @@
1
- import { LogEntry, Logger } from '../general';
2
- export declare const logConnection: {
3
- log?: Logger;
4
- employeeLog?: Logger;
5
- siteLog?: Logger;
6
- teamLog?: Logger;
7
- };
8
- export declare function createLogs(application: string): Promise<void>;
9
- export declare function postLogEntry(application: string, message: string): Promise<LogEntry>;
package/config/logging.js DELETED
@@ -1,44 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.logConnection = void 0;
4
- exports.createLogs = createLogs;
5
- exports.postLogEntry = postLogEntry;
6
- const general_1 = require("../general");
7
- const sqldb_1 = require("./sqldb");
8
- exports.logConnection = {};
9
- async function createLogs(application) {
10
- exports.logConnection.log = new general_1.Logger(`${process.env.LOG_DIR}/${application}/process_${(new Date().toDateString())}.log`);
11
- exports.logConnection.employeeLog = new general_1.Logger(`${process.env.LOG_DIR}/${application}/employee_${(new Date().toDateString())}.log`);
12
- exports.logConnection.siteLog = new general_1.Logger(`${process.env.LOG_DIR}/${application}/site_${(new Date().toDateString())}.log`);
13
- exports.logConnection.teamLog = new general_1.Logger(`${process.env.LOG_DIR}/${application}/team_${(new Date().toDateString())}.log`);
14
- }
15
- async function postLogEntry(application, message) {
16
- let conn;
17
- let logEntry = new general_1.LogEntry();
18
- try {
19
- if (sqldb_1.mdbConnection.pool) {
20
- conn = await sqldb_1.mdbConnection.pool.getConnection();
21
- const entryDate = new Date();
22
- const insert = `INSERT INTO logentries VALUES ( ?, ?, ?)`;
23
- const values = [entryDate, application, message];
24
- const query = `SELECT * FROM logentries ORDER BY application, messageid;`;
25
- await conn.query(insert, values);
26
- logEntry = new general_1.LogEntry({
27
- date: entryDate,
28
- entry: message
29
- });
30
- }
31
- else {
32
- throw new Error('No database connection');
33
- }
34
- }
35
- catch (err) {
36
- throw err;
37
- }
38
- finally {
39
- if (conn)
40
- conn.release();
41
- }
42
- return logEntry;
43
- }
44
- //# sourceMappingURL=logging.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"logging.js","sourceRoot":"","sources":["../../src/config/logging.ts"],"names":[],"mappings":";;;AAUA,gCASC;AAED,oCA4BC;AAjDD,wCAA8C;AAC9C,mCAAwC;AAE3B,QAAA,aAAa,GAKtB,EAAE,CAAA;AAEC,KAAK,UAAU,UAAU,CAAC,WAAmB;IAClD,qBAAa,CAAC,GAAG,GAAG,IAAI,gBAAM,CAC9B,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,WAAW,YAAY,CAAC,IAAI,IAAI,EAAE,CAAC,YAAY,EAAE,CAAC,MAAM,CAAC,CAAC;IACpF,qBAAa,CAAC,WAAW,GAAG,IAAI,gBAAM,CACtC,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,IAAI,WAAW,aAAa,CAAC,IAAI,IAA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I,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -1,5 +0,0 @@
1
- import * as mariadb from 'mariadb';
2
- export declare const mdbConnection: {
3
- pool?: mariadb.Pool;
4
- };
5
- export declare function createPool(): Promise<void>;
package/config/mariadb.js DELETED
@@ -1,50 +0,0 @@
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
- }
@@ -1,12 +0,0 @@
1
- import { Collection } from 'mongodb';
2
- export declare const collections: {
3
- users?: Collection;
4
- employees?: Collection;
5
- work?: Collection;
6
- notifications?: Collection;
7
- teams?: Collection;
8
- help?: Collection;
9
- missions?: Collection;
10
- outages?: Collection;
11
- };
12
- export declare function connectToDB(): Promise<void>;
@@ -1,65 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.collections = void 0;
4
- exports.connectToDB = connectToDB;
5
- const mongodb_1 = require("mongodb");
6
- exports.collections = {};
7
- async function connectToDB() {
8
- const uri = `mongodb://${process.env.MONGO_USER}:${process.env.MONGO_PASSWORD}@`
9
- + `${process.env.MONGO_SERVER}:${process.env.MONGO_PORT}?`
10
- + `${process.env.MONGO_APPEND}`;
11
- if (uri) {
12
- try {
13
- const client = new mongodb_1.MongoClient(uri);
14
- await client.connect();
15
- console.log('Connected to database');
16
- const db = client.db('scheduler');
17
- let users = client.db('authenticate').collection("users");
18
- if (!users) {
19
- users = await db.createCollection("users");
20
- }
21
- exports.collections.users = users;
22
- let employees = db.collection("employees");
23
- if (!employees) {
24
- employees = await db.createCollection("employees");
25
- }
26
- exports.collections.employees = employees;
27
- let work = db.collection('employeework');
28
- if (!work) {
29
- work = await db.createCollection("employeework");
30
- }
31
- exports.collections.work = work;
32
- let notifications = db.collection("notifications");
33
- if (!notifications) {
34
- notifications = await db.createCollection("notifications");
35
- }
36
- exports.collections.notifications = notifications;
37
- let teams = await db.collection('teams');
38
- if (!teams) {
39
- teams = await db.createCollection('teams');
40
- }
41
- exports.collections.teams = teams;
42
- let help = await db.collection('help');
43
- if (!help) {
44
- help = await db.createCollection('help');
45
- }
46
- exports.collections.help = help;
47
- const metricsDB = client.db('metrics2');
48
- let missions = metricsDB.collection('missions');
49
- if (!missions) {
50
- missions = await db.createCollection('missions');
51
- }
52
- exports.collections.missions = missions;
53
- let outages = metricsDB.collection('outages');
54
- if (!outages) {
55
- outages = await metricsDB.createCollection('outages');
56
- }
57
- exports.collections.outages = outages;
58
- console.log('Successfully connected to collections');
59
- }
60
- catch (error) {
61
- console.log(error);
62
- }
63
- }
64
- }
65
- //# sourceMappingURL=mongoconnect.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mongoconnect.js","sourceRoot":"","sources":["../../src/config/mongoconnect.ts"],"names":[],"mappings":";;;AAaA,kCA2DC;AAxED,qCAAsD;AAEzC,QAAA,WAAW,GASpB,EAAE,CAAA;AAEC,KAAK,UAAU,WAAW;IAC/B,MAAM,GAAG,GAAG,aAAa,OAAO,CAAC,GAAG,CAAC,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC,cAAc,GAAG;UAC5E,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,OAAO,CAAC,GAAG,CAAC,UAAU,GAAG;UACxD,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,EAAE,CAAC;IAClC,IAAI,GAAG,EAAE,CAAC;QACR,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,IAAI,qBAAW,CAAC,GAAG,CAAC,CAAC;YACpC,MAAM,MAAM,CAAC,OAAO,EAAE,CAAC;YACvB,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;YAErC,MAAM,EAAE,GAAO,MAAM,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC;YACtC,IAAI,KAAK,GAAe,MAAM,CAAC,EAAE,CAAC,cAAc,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;YACtE,IAAI,CAAC,KAAK,EAAE,CAAC;gBACX,KAAK,GAAG,MAAM,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC;YAC7C,CAAC;YACD,mBAAW,CAAC,KAAK,GAAG,KAAK,CAAC;YAC1B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e,SAAS,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;YAC5D,IAAI,CAAC,QAAQ,EAAE,CAAC;gBACd,QAAQ,GAAG,MAAM,EAAE,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC;YACnD,CAAC;YACD,mBAAW,CAAC,QAAQ,GAAG,QAAQ,CAAC;YAChC,IAAI,OAAO,GAAe,SAAS,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;YAC1D,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,OAAO,GAAG,MAAM,SAAS,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;YACxD,CAAC;YACD,mBAAW,CAAC,OAAO,GAAG,OAAO,CAAC;YAC9B,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;QACvD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;AACH,CAAC"}
package/config/sqldb.d.ts DELETED
@@ -1,5 +0,0 @@
1
- import * as mariadb from 'mariadb';
2
- export declare const mdbConnection: {
3
- pool?: mariadb.Pool;
4
- };
5
- export declare function createPool(): Promise<void>;
package/config/sqldb.js DELETED
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mdbConnection = void 0;
4
- exports.createPool = createPool;
5
- const mariadb = require("mariadb");
6
- exports.mdbConnection = {};
7
- async function createPool() {
8
- exports.mdbConnection.pool = await mariadb.createPool({
9
- host: process.env.MYSQL_SERVER,
10
- port: (process.env.MYSQL_PORT) ? Number(process.env.MYSQL_PORT) : 3306,
11
- user: process.env.MYSQL_USER,
12
- password: process.env.MYSQL_PASSWORD,
13
- database: 'scheduler',
14
- connectionLimit: 5
15
- });
16
- console.log('Connected to mariadb');
17
- }
18
- //# sourceMappingURL=sqldb.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sqldb.js","sourceRoot":"","sources":["../../src/config/sqldb.ts"],"names":[],"mappings":";;;AAMA,gCAUC;AAhBD,mCAAmC;AAEtB,QAAA,aAAa,GAEtB,EAAE,CAAC;AAEA,KAAK,UAAU,UAAU;IAC9B,qBAAa,CAAC,IAAI,GAAG,MAAM,OAAO,CAAC,UAAU,CAAC;QAC5C,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,YAAY;QAC9B,IAAI,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI;QACtE,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,UAAU;QAC5B,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc;QACpC,QAAQ,EAAE,WAAW;QACrB,eAAe,EAAE,CAAC;KACnB,CAAC,CAAC;IACH,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,CAAC;AACtC,CAAC"}
@@ -1,7 +0,0 @@
1
- import { InitialResponse } from "../scheduler/web";
2
- export declare class BuildInitial {
3
- private employeeID;
4
- private initialData;
5
- constructor(empID?: string);
6
- build(): Promise<InitialResponse>;
7
- }
@@ -1,189 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BuildInitial = void 0;
4
- const config_1 = require("../config");
5
- const mongodb_1 = require("mongodb");
6
- const employees_1 = require("../scheduler/employees");
7
- const users_1 = require("../users");
8
- const teams_1 = require("../scheduler/teams");
9
- const sites_1 = require("../scheduler/sites");
10
- class BuildInitial {
11
- employeeID;
12
- initialData;
13
- constructor(empID) {
14
- this.employeeID = (empID) ? empID : '';
15
- this.initialData = {};
16
- }
17
- async build() {
18
- let conn;
19
- try {
20
- if (this.employeeID === '') {
21
- throw new Error("Employee not assigned");
22
- }
23
- if (config_1.collections.employees) {
24
- const query = { _id: new mongodb_1.ObjectId(this.employeeID) };
25
- const iEmp = await config_1.collections.employees.findOne(query);
26
- if (iEmp) {
27
- this.initialData.employee = new employees_1.Employee(iEmp);
28
- if (config_1.collections.users) {
29
- const iUser = await config_1.collections.users.findOne(query);
30
- if (iUser) {
31
- this.initialData.employee.user = new users_1.User(iUser);
32
- }
33
- else {
34
- throw new Error('User not found');
35
- }
36
- }
37
- else {
38
- throw new Error('User collection unavailable');
39
- }
40
- }
41
- else {
42
- throw new Error('Employee not found');
43
- }
44
- }
45
- else {
46
- throw new Error('Employee collection unavailable');
47
- }
48
- const now = new Date();
49
- const start = new Date(Date.UTC(now.getFullYear() - 1, 0, 1));
50
- const end = new Date(Date.UTC(now.getFullYear() + 1, 0, 1));
51
- if (this.initialData.employee) {
52
- if (config_1.collections.teams) {
53
- const query = { _id: new mongodb_1.ObjectId(this.initialData.employee.team) };
54
- const iTeam = await config_1.collections.teams.findOne(query);
55
- if (iTeam) {
56
- this.initialData.team = new teams_1.Team(iTeam);
57
- const employeeIDList = [];
58
- const empTeamQuery = { team: new mongodb_1.ObjectId(this.initialData.employee.team) };
59
- if (config_1.collections.employees) {
60
- const empCursor = config_1.collections.employees.find(empTeamQuery);
61
- const empArray = await empCursor.toArray();
62
- const empPromises = empArray.map(async (iEmp) => {
63
- const emp = new employees_1.Employee(iEmp);
64
- if (emp.isActiveBetween(start, end)) {
65
- this.initialData.team?.sites.forEach((site, s) => {
66
- if (site.id.toLowerCase() === emp.site.toLowerCase()) {
67
- if (!site.employees) {
68
- site.employees = [];
69
- }
70
- if (site.employees) {
71
- site.employees.push(new employees_1.Employee(emp));
72
- }
73
- if (this.initialData.team) {
74
- this.initialData.team.sites[s] = site;
75
- }
76
- }
77
- });
78
- employeeIDList.push(emp.id);
79
- }
80
- });
81
- await Promise.allSettled(empPromises);
82
- }
83
- if (employeeIDList.length > 0) {
84
- if (config_1.mdbConnection.pool) {
85
- conn = await config_1.mdbConnection.pool.getConnection();
86
- const sql = 'SELECT * FROM employeeWork WHERE employeeID IN (?) and '
87
- + "dateworked >= ? and dateworked < ? ORDER BY employeeID, dateworked, "
88
- + "chargenumber, extension, paycode;";
89
- const listVals = [employeeIDList, start, end];
90
- const results = await conn.query(sql, listVals);
91
- const workPromises = results.map(async (row) => {
92
- if (this.initialData.team) {
93
- let found = false;
94
- this.initialData.team.sites.forEach((site, s) => {
95
- if (!found) {
96
- if (site.employees) {
97
- site.employees.forEach((emp, e) => {
98
- if (!found) {
99
- if (emp.id && emp.id === row.employeeID) {
100
- found = true;
101
- if (!emp.work) {
102
- emp.work = [];
103
- }
104
- if (emp.work) {
105
- emp.work.push(new employees_1.Work({
106
- dateworked: new Date(row.dateworked),
107
- chargenumber: row.chargenumber,
108
- extension: row.extension,
109
- paycode: Number(row.paycode),
110
- modtime: (row.modtime === '1' || row.modtime === 1),
111
- hours: Number(row.hours)
112
- }));
113
- }
114
- if (site.employees) {
115
- site.employees[e] = emp;
116
- }
117
- }
118
- }
119
- });
120
- if (found && this.initialData.team) {
121
- this.initialData.team.sites[s] = site;
122
- }
123
- }
124
- }
125
- });
126
- }
127
- });
128
- await Promise.allSettled(workPromises);
129
- }
130
- }
131
- }
132
- else {
133
- throw new Error('Employee Team not found');
134
- }
135
- }
136
- else {
137
- throw new Error('Team collection unavailable');
138
- }
139
- }
140
- else {
141
- throw new Error('No initial employee to pull team');
142
- }
143
- if (this.initialData.team) {
144
- let found = false;
145
- this.initialData.team.sites.forEach(site => {
146
- if (!found && this.initialData.employee) {
147
- const tUser = new users_1.User(this.initialData.employee.user);
148
- if (site.id.toLowerCase() === this.initialData.employee?.site.toLowerCase()) {
149
- this.initialData.site = new sites_1.Site(site);
150
- if (site.employees) {
151
- site.employees.forEach(emp => {
152
- if (!found && this.initialData.employee
153
- && emp.id === this.initialData.employee.id) {
154
- this.initialData.employee = new employees_1.Employee(emp);
155
- this.initialData.employee.user = tUser;
156
- found = true;
157
- }
158
- });
159
- }
160
- }
161
- }
162
- });
163
- }
164
- if (!this.initialData.questions) {
165
- this.initialData.questions = [];
166
- const sql = "SELECT * FROM questions ORDER BY id;";
167
- const results = await conn?.query(sql);
168
- results.forEach((row) => {
169
- if (this.initialData.questions) {
170
- this.initialData.questions.push(new users_1.SecurityQuestion({
171
- id: Number(row.id),
172
- question: row.question
173
- }));
174
- }
175
- });
176
- }
177
- }
178
- catch (err) {
179
- console.log(err);
180
- }
181
- finally {
182
- if (conn)
183
- conn.release();
184
- }
185
- return this.initialData;
186
- }
187
- }
188
- exports.BuildInitial = BuildInitial;
189
- //# sourceMappingURL=buildInitial.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"buildInitial.js","sourceRoot":"","sources":["../../src/services/buildInitial.ts"],"names":[],"mappings":";;;AAEA,sCAAuD;AACvD,qCAAmC;AACnC,sDAAmE;AACnE,oCAAyD;AACzD,8CAAiD;AACjD,8CAA0C;AAG1C,MAAa,YAAY;IACf,UAAU,CAAS;IACnB,WAAW,CAAkB;IAErC,YAAY,KAAc;QACxB,IAAI,CAAC,UAAU,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;QACvC,IAAI,CAAC,WAAW,GAAG,EAAG,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,KAAK;QACT,IAAI,IAAgC,CAAC;QACrC,IAAI,CAAC;YACH,IAAI,IAAI,CAAC,UAAU,KAAK,EAAE,EAAE,CAAC;gBAC3B,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;YAC3C,CAAC;YAED,IAAI,oBAAW,CAAC,SAAS,EAAE,CAAC;gBAC1B,MAAM,KAAK,GAAG,EAAE,GAAG,EAAE,IAAI,kBAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,EAAC,CAAC;gBACpD,MAAM,IAAI,GAAG,MAAM,oBAAW,CAAC,SAAS,CAAC,OAAO,CAAY,KAAK,CAAC,CAAC;gBACnE,IAAI,IAAI,EAAE,CAAC;oBACT,IAAI,CAAC,WAAW,CAAC,QAAQ,GAAG,IAAI,oBAAQ,CAAC,IAAI,CAAC,CA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4BACL,CAAC;wBACH,CAAC;oBACH,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;YAGD,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC;gBAChC,IAAI,CAAC,WAAW,CAAC,SAAS,GAAG,EAAE,CAAC;gBAChC,MAAM,GAAG,GAAG,sCAAsC,CAAC;gBACnD,MAAM,OAAO,GAAG,MAAM,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;gBACvC,OAAO,CAAC,OAAO,CAAC,CAAC,GAAQ,EAAE,EAAE;oBAC3B,IAAI,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC;wBAC/B,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,wBAAgB,CAAC;4BACnD,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;4BAClB,QAAQ,EAAE,GAAG,CAAC,QAAQ;yBACvB,CAAC,CAAC,CAAC;oBACN,CAAC;gBACH,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACnB,CAAC;gBAAS,CAAC;YACT,IAAI,IAAI;gBAAE,IAAI,CAAC,OAAO,EAAE,CAAC;QAC3B,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;CACF;AA5LD,oCA4LC"}
@@ -1 +0,0 @@
1
- export * from './buildInitial';
package/services/index.js DELETED
@@ -1,18 +0,0 @@
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./buildInitial"), exports);
18
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/services/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA+B"}