lms-sync 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,198 @@
1
+ "use strict";
2
+
3
+ const bcrypt = require('sequelize-bcrypt')
4
+
5
+ module.exports = (sequelize, DataTypes) => {
6
+
7
+ const Users = sequelize.define('Users',{
8
+ _id: {
9
+ type: DataTypes.INTEGER,
10
+ unique: true,
11
+ allowNull: false,
12
+ autoIncrement: true,
13
+ primaryKey: true,
14
+ },
15
+ email: {
16
+ type: DataTypes.STRING,
17
+ unique: false,
18
+ allowNull: true,
19
+ autoIncrement: false,
20
+ primaryKey: false,
21
+ },
22
+ password: {
23
+ type: DataTypes.STRING,
24
+ unique: false,
25
+ allowNull: true,
26
+ autoIncrement: false,
27
+ primaryKey: false,
28
+ },
29
+ temporaryPassword: {
30
+ type: DataTypes.STRING,
31
+ unique: false,
32
+ allowNull: true,
33
+ autoIncrement: false,
34
+ primaryKey: false,
35
+ },
36
+ firstName: {
37
+ type: DataTypes.STRING,
38
+ unique: false,
39
+ allowNull: true,
40
+ autoIncrement: false,
41
+ primaryKey: false,
42
+ },
43
+ middleName: {
44
+ type: DataTypes.STRING,
45
+ unique: false,
46
+ allowNull: true,
47
+ autoIncrement: false,
48
+ primaryKey: false,
49
+ },
50
+ lastName: {
51
+ type: DataTypes.STRING,
52
+ unique: false,
53
+ allowNull: true,
54
+ autoIncrement: false,
55
+ primaryKey: false,
56
+ },
57
+ passwordResetToken: {
58
+ type: DataTypes.STRING,
59
+ unique: false,
60
+ allowNull: true,
61
+ autoIncrement: false,
62
+ primaryKey: false,
63
+ },
64
+ avatar: {
65
+ type: DataTypes.STRING,
66
+ unique: false,
67
+ allowNull: true,
68
+ autoIncrement: false,
69
+ primaryKey: false,
70
+ },
71
+ token: {
72
+ type: DataTypes.STRING,
73
+ unique: false,
74
+ allowNull: true,
75
+ autoIncrement: false,
76
+ primaryKey: false,
77
+ },
78
+ lastLogin: {
79
+ type: DataTypes.DATE,
80
+ unique: false,
81
+ allowNull: true,
82
+ autoIncrement: false,
83
+ primaryKey: false,
84
+ },
85
+ contactNo: {
86
+ type: DataTypes.STRING,
87
+ unique: false,
88
+ allowNull: true,
89
+ autoIncrement: false,
90
+ primaryKey: false,
91
+ },
92
+ invalidAttempts: {
93
+ type: DataTypes.INTEGER,
94
+ unique: false,
95
+ allowNull: true,
96
+ autoIncrement: false,
97
+ primaryKey: false,
98
+ },
99
+ iamAdmin: {
100
+ type: DataTypes.BOOLEAN,
101
+ unique: false,
102
+ allowNull: true,
103
+ autoIncrement: false,
104
+ primaryKey: false,
105
+ defaultValue: false,
106
+ },
107
+ adminScopes: {
108
+ type: DataTypes.ARRAY(DataTypes.STRING),
109
+ unique: false,
110
+ allowNull: true,
111
+ autoIncrement: false,
112
+ primaryKey: false,
113
+ defaultValue: false,
114
+ },
115
+ loggedIn: {
116
+ type: DataTypes.BOOLEAN,
117
+ unique: false,
118
+ allowNull: true,
119
+ autoIncrement: false,
120
+ primaryKey: false,
121
+ defaultValue: false,
122
+ },
123
+ active: {
124
+ type: DataTypes.BOOLEAN,
125
+ unique: false,
126
+ allowNull: true,
127
+ autoIncrement: false,
128
+ primaryKey: false,
129
+ defaultValue: true,
130
+ },
131
+ createdById: {
132
+ type: DataTypes.INTEGER,
133
+ unique: false,
134
+ allowNull: true,
135
+ autoIncrement: false,
136
+ primaryKey: false,
137
+ },
138
+ modifiedById: {
139
+ type: DataTypes.INTEGER,
140
+ unique: false,
141
+ allowNull: true,
142
+ autoIncrement: false,
143
+ primaryKey: false,
144
+ },
145
+ enable2FA: {
146
+ type: DataTypes.BOOLEAN,
147
+ unique: false,
148
+ allowNull: true,
149
+ autoIncrement: false,
150
+ primaryKey: false,
151
+ defaultValue: false,
152
+ },
153
+ secretkey2FA: {
154
+ type: DataTypes.STRING,
155
+ unique: false,
156
+ allowNull: true,
157
+ autoIncrement: false,
158
+ primaryKey: false,
159
+ defaultValue: false,
160
+ },
161
+ updatedAt: {
162
+ type: DataTypes.DATE,
163
+ unique: false,
164
+ allowNull: true,
165
+ autoIncrement: false,
166
+ primaryKey: false,
167
+ },
168
+ createdAt: {
169
+ type: DataTypes.DATE,
170
+ allowNull: true,
171
+ },
172
+ updatedAt: {
173
+ type: DataTypes.DATE,
174
+ allowNull: true,
175
+ },
176
+ },
177
+ {
178
+ // createdAt: 'createdDate',
179
+ // updatedAt: 'modifiedDate',
180
+ sequelize,
181
+ schema: "public",
182
+ modelName: "Users",
183
+ }
184
+ );
185
+
186
+ // Users.beforeCreate(async (user, options) => {
187
+ // user.createdAt = new Date();
188
+ // user.active = true;
189
+ // });
190
+
191
+ // Users.beforeSave(async (user, options) => {
192
+ // user.updatedAt = new Date();
193
+ // });
194
+
195
+ //bcrypt
196
+ bcrypt(Users, { field: "password" });
197
+ return Users;
198
+ };
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "lms-sync",
3
+ "version": "1.0.0",
4
+ "description": "Migration App for MSC LMS",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "dev": "nodemon app.js",
9
+ "start": "node app.js"
10
+ },
11
+ "keywords": [],
12
+ "author": "",
13
+ "license": "ISC",
14
+ "dependencies": {
15
+ "axios": "^1.6.5",
16
+ "axios-retry": "^4.0.0",
17
+ "bcrypt": "^5.1.1",
18
+ "bcryptjs": "^2.4.3",
19
+ "express": "^4.18.2",
20
+ "https": "^1.0.0",
21
+ "moment": "^2.30.1",
22
+ "mysql2": "^3.7.1",
23
+ "pg": "^8.11.3",
24
+ "pg-hstore": "^2.3.4",
25
+ "prompts": "^2.4.2",
26
+ "sequelize": "^6.35.2",
27
+ "sequelize-bcrypt": "^1.2.0",
28
+ "winston": "^3.11.0",
29
+ "yargs": "^17.7.2"
30
+ },
31
+ "devDependencies": {
32
+ "nodemon": "^3.0.3",
33
+ "sequelize-cli": "^6.6.2"
34
+ },
35
+ "bin": "./app.js"
36
+ }
File without changes
File without changes
@@ -0,0 +1,189 @@
1
+ // const dataBaseSequelize = require('../dbConnection/sequelizeConnection');
2
+
3
+ const db = require('../models/index');
4
+ // const Sequelize = require('sequelize')
5
+ const moment = require('moment');
6
+ const bcrypt = require('bcryptjs');
7
+ module.exports = {
8
+
9
+ // default
10
+ // async fetchSQLData(dbTable){
11
+ // try {
12
+ // let getTable = await new Promise((resolve, reject)=>{
13
+ // databaseSQL.query(`SELECT * FROM ${dbTable}`, (err, table) =>{
14
+ // if(err){
15
+ // console.error(err);
16
+ // return reject(err);
17
+ // }
18
+ // else{
19
+ // resolve(table);
20
+ // }
21
+ // });
22
+ // });
23
+
24
+ // return getTable;
25
+ // } catch (error) {
26
+ // console.error(error);
27
+ // }
28
+ // },
29
+
30
+ computeDuration(timeIn, timeOut, as = "asHours") {
31
+ let totalDuration = moment.duration(moment(timeOut, 'HH:mm:ss')
32
+ .diff(moment(timeIn ? timeIn : 0, 'HH:mm:ss')))[as]();
33
+ return totalDuration;
34
+ },
35
+
36
+ convertDateFormat(dateString) {
37
+ if(dateString == null) return null;
38
+ const [month, day, year] = dateString.split('/');
39
+ const formattedDate = `${year}-${month.padStart(2, '0')}-${day.padStart(2, '0')}` || null;
40
+ return formattedDate;
41
+ },
42
+
43
+ getCategory(category){
44
+ if(!category || category ==='') return null;
45
+ else if(category === 1) return 'REGULAR_FACULTY'
46
+ else if(category === 2) return 'NON_TEACHING_PERSONNEL'
47
+ else if(category === 3) return 'COLLEGE_LECTURER'
48
+ else if(category === 4) return 'SUPPORT_STAFF'
49
+ else return null
50
+ },
51
+
52
+ getStatusOfAppointment(status){
53
+ if(!status || status ==='') return null;
54
+ else if(status === 1) return 'PERMANENT'
55
+ else if(status === 2) return 'TEMPORARY'
56
+ else if(status === 3) return 'CASUAL'
57
+ else if(status === 4) return 'FULLTIME'
58
+ else if(status === 5) return 'PART_TIME'
59
+ else if(status === 6) return 'JOB_ORDER'
60
+ else if(status === 7) return 'SUBSTITUTE'
61
+ else if(status === 8) return 'PROBATIONARY'
62
+ else if(status === 9) return 'CONTRACTUAL'
63
+ else if (status === 10) return 'CONTRACT_OF_SERVICE'
64
+ },
65
+
66
+ getStatsAppointment(category, status){
67
+ if(!status || status ==='') return null;
68
+ else if(category === 1 && status === 1) return 'REGULAR_FACULTY_PERMANENT'
69
+ else if(category === 1 && status === 2) return 'REGULAR_FACULTY_TEMPORARY'
70
+
71
+ else if(category === 2 && status === 1) return 'NON_TEACHING_PERMANENT'
72
+ else if(category === 2 && status === 2) return 'NON_TEACHING_TEMPORARY'
73
+ else if(category === 2 && status === 3) return 'NON_TEACHING_CASUAL'
74
+ else if(category === 2 && status === 10) return 'NON_TEACHING_CO-TERMINUS'
75
+
76
+
77
+ else if(category === 3 && status === 4) return 'COLLEGE_LECTURER_FULLTIME'
78
+ else if(category === 3 && status === 5) return 'COLLEGE_LECTURER_PART_TIME'
79
+ else if(category === 3 && status === 9) return 'COLLEGE_LECTURER_ADJUNCT'
80
+
81
+ else if(category === 4 && status === 6) return 'JOB_ORDER'
82
+ },
83
+
84
+
85
+ formatDatePassword(RawDate){
86
+ if(!RawDate || RawDate =='') return null;
87
+ const date = new Date(RawDate);
88
+ const formattedDate = date.toLocaleDateString('en-US', {
89
+ month: 'numeric',
90
+ day: 'numeric',
91
+ year: 'numeric',
92
+ }).replace(/\//g, '');
93
+
94
+ return formattedDate;
95
+ },
96
+
97
+ hashPassword(password){
98
+ try {
99
+ if(!password || password =='') return null
100
+ const salt = bcrypt.genSaltSync(12);
101
+ const hash = bcrypt.hashSync(password, salt);
102
+
103
+ return `${hash}`;
104
+ } catch (error) {
105
+ console.error(error);
106
+ }
107
+ },
108
+ formatDate(date, type) {
109
+ if (!date) return date;
110
+ var dt = new Date(date);
111
+
112
+ if (!type) {
113
+ type = {
114
+ year: "numeric",
115
+ month: "long",
116
+ day: "2-digit",
117
+ };
118
+ } else if (type === "datetime") {
119
+ type = {
120
+ hour12: true,
121
+ year: "numeric",
122
+ month: "long",
123
+ day: "2-digit",
124
+ hour: "2-digit",
125
+ minute: "2-digit",
126
+ };
127
+ } else if (type === "time") {
128
+ type = {
129
+ hour12: true,
130
+ hour: "2-digit",
131
+ minute: "2-digit",
132
+ };
133
+ } else if (type === "time24") {
134
+ type = {
135
+ hour12: false,
136
+ hour: "2-digit",
137
+ minute: "2-digit",
138
+ second: "2-digit",
139
+ };
140
+ } else if (type === "YYYY-MM-DD") {
141
+ type = {
142
+ year: "numeric",
143
+ month: "2-digit",
144
+ day: "2-digit",
145
+ };
146
+ // return dt.toLocaleString('fr-CA', { year: 'numeric', month: '2-digit', day: '2-digit' });
147
+ }
148
+ type.timeZone = "Asia/Manila";
149
+ return dt.toLocaleString("en-US", type);
150
+ },
151
+ getEmployeeName(emp,isV2,isSQl) {
152
+ let fullname = "-";
153
+ if (emp) {
154
+ if (emp.lastName && emp.firstName && !isSQl) {
155
+ fullname = !isV2 ? `${emp.lastName}, ${emp.firstName || ""} ${
156
+ emp.middleName || ""
157
+ }`
158
+ : `${emp.firstName} ${emp.middleName || ""} ${
159
+ emp.lastName || ""
160
+ }`;
161
+ }
162
+ else if(isSQl){
163
+ fullname =
164
+ `${emp.last_name || ""}, ${emp.first_name || ""} ${
165
+ emp.mid_name || ""
166
+ }`
167
+ }
168
+ }
169
+ return fullname;
170
+ },
171
+
172
+ formatGovernment(data){
173
+ if(!data || data ==="") return null;
174
+ const cleanedStr = data.replace(/-/g, '');
175
+
176
+ return cleanedStr;
177
+ },
178
+
179
+ formatActualDate(data){
180
+ if (!data || data == null) return null;
181
+ const adjustedDate = moment.utc(data, 'YYYY-MM-DD')
182
+ .add(1, 'days')
183
+ .utcOffset(8)
184
+ .format('YYYY-MM-DD HH:mm:ssZ'); // Format as per requirement
185
+
186
+ return adjustedDate;
187
+ }
188
+
189
+ }
@@ -0,0 +1,33 @@
1
+ const { createLogger, transports, format } = require('winston');
2
+ const Mixins = require('./Mixins')
3
+
4
+ //just a custom message formatter
5
+ const customFormat = format.printf(({level, message, timestamp}) => {
6
+ return ` [${Mixins.formatDate(timestamp)}] ${level}: ${message} `
7
+ })
8
+
9
+ //will only filter info in the success logs
10
+ const successFilter = format((info, opts) => {
11
+ if (info.level === 'info') {
12
+ return info;
13
+ }
14
+ return false;
15
+ });
16
+
17
+ // Create a logger instance
18
+ const logger = createLogger({
19
+ level: 'info', // Set the minimum log level (e.g., 'info', 'warn', 'error', 'debug')
20
+ format: format.combine(
21
+ format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
22
+ customFormat,
23
+
24
+ ),
25
+ transports: [
26
+ new transports.Console(), // Logs to the console
27
+ new transports.File({ filename: 'recordError.log', level: 'error' }), // Logs error level logs to recordError file
28
+ // new transports.File({ filename: 'combined.log' }), // Logs all levels to another file
29
+ new transports.File({ filename: 'recordSuccess.log', level: 'info', format: format.combine(successFilter(),customFormat)}), // Logs info levels in recordSuccess file
30
+ ],
31
+ });
32
+
33
+ module.exports = logger;