dip-dobit-shared-model 1.0.3 → 1.0.5
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/index.js +3 -0
- package/migrations/20251211103900-create-table-PortalUser.js +55 -0
- package/models/index.js +63 -39
- package/models/portalUser.js +63 -0
- package/package.json +1 -1
package/index.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { STATUS_ID } = require("../service/constants");
|
|
4
|
+
|
|
5
|
+
module.exports = {
|
|
6
|
+
async up(queryInterface, Sequelize) {
|
|
7
|
+
await queryInterface.createTable("PortalUsers", {
|
|
8
|
+
portalUserId: {
|
|
9
|
+
type: Sequelize.INTEGER.UNSIGNED,
|
|
10
|
+
primaryKey: true,
|
|
11
|
+
autoIncrement: true,
|
|
12
|
+
allowNull: false,
|
|
13
|
+
},
|
|
14
|
+
firstName: {
|
|
15
|
+
type: Sequelize.STRING,
|
|
16
|
+
allowNull: false,
|
|
17
|
+
},
|
|
18
|
+
lastName: {
|
|
19
|
+
type: Sequelize.STRING,
|
|
20
|
+
allowNull: false,
|
|
21
|
+
},
|
|
22
|
+
email: {
|
|
23
|
+
type: Sequelize.STRING,
|
|
24
|
+
allowNull: false,
|
|
25
|
+
unique: true,
|
|
26
|
+
},
|
|
27
|
+
username: {
|
|
28
|
+
type: Sequelize.STRING,
|
|
29
|
+
allowNull: false,
|
|
30
|
+
unique: true,
|
|
31
|
+
},
|
|
32
|
+
phoneNumber: {
|
|
33
|
+
type: Sequelize.STRING,
|
|
34
|
+
allowNull: true,
|
|
35
|
+
},
|
|
36
|
+
statusId: {
|
|
37
|
+
type: Sequelize.INTEGER.UNSIGNED,
|
|
38
|
+
allowNull: false,
|
|
39
|
+
defaultValue: STATUS_ID.ACTIVE,
|
|
40
|
+
},
|
|
41
|
+
createdAt: {
|
|
42
|
+
allowNull: false,
|
|
43
|
+
type: Sequelize.DATE,
|
|
44
|
+
},
|
|
45
|
+
updatedAt: {
|
|
46
|
+
allowNull: false,
|
|
47
|
+
type: Sequelize.DATE,
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
async down(queryInterface, Sequelize) {
|
|
53
|
+
await queryInterface.dropTable("PortalUsers");
|
|
54
|
+
},
|
|
55
|
+
};
|
package/models/index.js
CHANGED
|
@@ -1,47 +1,71 @@
|
|
|
1
|
+
// "use strict";
|
|
2
|
+
|
|
3
|
+
// const fs = require("fs");
|
|
4
|
+
// const path = require("path");
|
|
5
|
+
// const Sequelize = require("sequelize");
|
|
6
|
+
// const process = require("process");
|
|
7
|
+
// const basename = path.basename(__filename);
|
|
8
|
+
// const env = process.env.NODE_ENV || "development";
|
|
9
|
+
// const config = require(__dirname + "/../config/config.js")[env];
|
|
10
|
+
// const db = {};
|
|
11
|
+
|
|
12
|
+
// let sequelize;
|
|
13
|
+
// if (config.use_env_variable) {
|
|
14
|
+
// sequelize = new Sequelize(process.env[config.use_env_variable], config);
|
|
15
|
+
// } else {
|
|
16
|
+
// sequelize = new Sequelize(
|
|
17
|
+
// config.database,
|
|
18
|
+
// config.username,
|
|
19
|
+
// config.password,
|
|
20
|
+
// config
|
|
21
|
+
// );
|
|
22
|
+
// }
|
|
23
|
+
|
|
24
|
+
// fs.readdirSync(__dirname)
|
|
25
|
+
// .filter((file) => {
|
|
26
|
+
// return (
|
|
27
|
+
// file.indexOf(".") !== 0 && file !== basename && file.slice(-3) === ".js"
|
|
28
|
+
// );
|
|
29
|
+
// })
|
|
30
|
+
// .forEach((file) => {
|
|
31
|
+
// const model = require(path.join(__dirname, file))(
|
|
32
|
+
// sequelize,
|
|
33
|
+
// Sequelize.DataTypes
|
|
34
|
+
// );
|
|
35
|
+
// db[model.name] = model;
|
|
36
|
+
// });
|
|
37
|
+
|
|
38
|
+
// Object.keys(db).forEach((modelName) => {
|
|
39
|
+
// if (db[modelName].associate) {
|
|
40
|
+
// db[modelName].associate(db);
|
|
41
|
+
// }
|
|
42
|
+
// });
|
|
43
|
+
|
|
44
|
+
// db.sequelize = sequelize;
|
|
45
|
+
// db.Sequelize = Sequelize;
|
|
46
|
+
|
|
47
|
+
// module.exports = db;
|
|
48
|
+
|
|
1
49
|
"use strict";
|
|
2
50
|
|
|
3
51
|
const fs = require("fs");
|
|
4
52
|
const path = require("path");
|
|
5
|
-
const Sequelize = require("sequelize");
|
|
6
|
-
const process = require("process");
|
|
7
53
|
const basename = path.basename(__filename);
|
|
8
|
-
const env = process.env.NODE_ENV || "development";
|
|
9
|
-
const config = require(__dirname + "/../config/config.js")[env];
|
|
10
|
-
const db = {};
|
|
11
|
-
|
|
12
|
-
let sequelize;
|
|
13
|
-
if (config.use_env_variable) {
|
|
14
|
-
sequelize = new Sequelize(process.env[config.use_env_variable], config);
|
|
15
|
-
} else {
|
|
16
|
-
sequelize = new Sequelize(
|
|
17
|
-
config.database,
|
|
18
|
-
config.username,
|
|
19
|
-
config.password,
|
|
20
|
-
config
|
|
21
|
-
);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
fs.readdirSync(__dirname)
|
|
25
|
-
.filter((file) => {
|
|
26
|
-
return (
|
|
27
|
-
file.indexOf(".") !== 0 && file !== basename && file.slice(-3) === ".js"
|
|
28
|
-
);
|
|
29
|
-
})
|
|
30
|
-
.forEach((file) => {
|
|
31
|
-
const model = require(path.join(__dirname, file))(
|
|
32
|
-
sequelize,
|
|
33
|
-
Sequelize.DataTypes
|
|
34
|
-
);
|
|
35
|
-
db[model.name] = model;
|
|
36
|
-
});
|
|
37
54
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
db[modelName].associate(db);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
55
|
+
module.exports = (sequelize) => {
|
|
56
|
+
const db = {};
|
|
43
57
|
|
|
44
|
-
|
|
45
|
-
|
|
58
|
+
fs.readdirSync(__dirname)
|
|
59
|
+
.filter((file) => file !== basename && file.endsWith(".js"))
|
|
60
|
+
.forEach((file) => {
|
|
61
|
+
const model = require(path.join(__dirname, file))(sequelize);
|
|
62
|
+
db[model.name] = model;
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
// Setup associations
|
|
66
|
+
Object.keys(db).forEach((name) => {
|
|
67
|
+
if (db[name].associate) db[name].associate(db);
|
|
68
|
+
});
|
|
46
69
|
|
|
47
|
-
|
|
70
|
+
return db;
|
|
71
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
const { Model, DataTypes } = require("sequelize");
|
|
4
|
+
const { STATUS_ID } = require("../service/constants");
|
|
5
|
+
|
|
6
|
+
module.exports = (sequelize) => {
|
|
7
|
+
class PortalUser extends Model {
|
|
8
|
+
static associate(models) {
|
|
9
|
+
// define association here
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
PortalUser.init(
|
|
14
|
+
{
|
|
15
|
+
portalUserId: {
|
|
16
|
+
type: DataTypes.INTEGER.UNSIGNED,
|
|
17
|
+
primaryKey: true,
|
|
18
|
+
autoIncrement: true,
|
|
19
|
+
allowNull: false,
|
|
20
|
+
},
|
|
21
|
+
firstName: {
|
|
22
|
+
type: DataTypes.STRING,
|
|
23
|
+
allowNull: false,
|
|
24
|
+
},
|
|
25
|
+
lastName: {
|
|
26
|
+
type: DataTypes.STRING,
|
|
27
|
+
allowNull: false,
|
|
28
|
+
},
|
|
29
|
+
email: {
|
|
30
|
+
type: DataTypes.STRING,
|
|
31
|
+
allowNull: false,
|
|
32
|
+
unique: true,
|
|
33
|
+
validate: {
|
|
34
|
+
isEmail: true,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
username: {
|
|
38
|
+
type: DataTypes.STRING,
|
|
39
|
+
allowNull: false,
|
|
40
|
+
unique: true,
|
|
41
|
+
},
|
|
42
|
+
phoneNumber: {
|
|
43
|
+
type: DataTypes.STRING,
|
|
44
|
+
allowNull: true,
|
|
45
|
+
},
|
|
46
|
+
statusId: {
|
|
47
|
+
type: DataTypes.INTEGER.UNSIGNED,
|
|
48
|
+
allowNull: false,
|
|
49
|
+
defaultValue: STATUS_ID.ACTIVE,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
{
|
|
54
|
+
sequelize,
|
|
55
|
+
modelName: "PortalUser",
|
|
56
|
+
tableName: "PortalUsers",
|
|
57
|
+
timestamps: true,
|
|
58
|
+
underscored: true,
|
|
59
|
+
}
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
return PortalUser;
|
|
63
|
+
};
|