dip-dobit-shared-model 1.0.5 → 1.0.7

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.
@@ -38,6 +38,22 @@ module.exports = {
38
38
  allowNull: false,
39
39
  defaultValue: STATUS_ID.ACTIVE,
40
40
  },
41
+ createdBy: {
42
+ type: Sequelize.INTEGER.UNSIGNED,
43
+ allowNull: true,
44
+ references: {
45
+ model: "PortalUsers",
46
+ key: "portalUserId",
47
+ },
48
+ },
49
+ updatedBy: {
50
+ type: Sequelize.INTEGER.UNSIGNED,
51
+ allowNull: true,
52
+ references: {
53
+ model: "PortalUsers",
54
+ key: "portalUserId",
55
+ },
56
+ },
41
57
  createdAt: {
42
58
  allowNull: false,
43
59
  type: Sequelize.DATE,
@@ -46,6 +62,10 @@ module.exports = {
46
62
  allowNull: false,
47
63
  type: Sequelize.DATE,
48
64
  },
65
+ deletedAt: {
66
+ type: Sequelize.DATE,
67
+ allowNull: true,
68
+ },
49
69
  });
50
70
  },
51
71
 
@@ -4,7 +4,7 @@ const { STATUS_ID } = require("../service/constants");
4
4
 
5
5
  module.exports = {
6
6
  async up(queryInterface, Sequelize) {
7
- await queryInterface.createTable("dobitUsers", {
7
+ await queryInterface.createTable("DobitUsers", {
8
8
  dobitUserId: {
9
9
  type: Sequelize.INTEGER.UNSIGNED,
10
10
  primaryKey: true,
@@ -48,6 +48,22 @@ module.exports = {
48
48
  allowNull: false,
49
49
  defaultValue: STATUS_ID.ACTIVE,
50
50
  },
51
+ userCreatedby: {
52
+ type: Sequelize.INTEGER.UNSIGNED,
53
+ allowNull: true,
54
+ references: {
55
+ model: "PortalUsers",
56
+ key: "portalUserId",
57
+ },
58
+ },
59
+ userUpdatedby: {
60
+ type: Sequelize.INTEGER.UNSIGNED,
61
+ allowNull: true,
62
+ references: {
63
+ model: "PortalUsers",
64
+ key: "portalUserId",
65
+ },
66
+ },
51
67
  createdAt: {
52
68
  allowNull: false,
53
69
  type: Sequelize.DATE,
@@ -64,6 +80,6 @@ module.exports = {
64
80
  },
65
81
 
66
82
  async down(queryInterface, Sequelize) {
67
- await queryInterface.dropTable("dobitUsers");
83
+ await queryInterface.dropTable("DobitUsers");
68
84
  },
69
85
  };
@@ -4,13 +4,21 @@ const { Model, DataTypes } = require("sequelize");
4
4
  const { STATUS_ID } = require("../service/constants");
5
5
 
6
6
  module.exports = (sequelize) => {
7
- class DobitUser extends Model {
7
+ class DobitUsers extends Model {
8
8
  static associate(models) {
9
9
  // define association here
10
+ DobitUsers.belongsTo(models.PortalUsers, {
11
+ as: "createdBy",
12
+ foreignKey: "userCreatedby",
13
+ });
14
+ DobitUsers.belongsTo(models.PortalUsers, {
15
+ as: "updatedBy",
16
+ foreignKey: "userUpdatedby",
17
+ });
10
18
  }
11
19
  }
12
20
 
13
- DobitUser.init(
21
+ DobitUsers.init(
14
22
  {
15
23
  dobitUserId: {
16
24
  type: DataTypes.INTEGER.UNSIGNED,
@@ -58,18 +66,34 @@ module.exports = (sequelize) => {
58
66
  allowNull: false,
59
67
  defaultValue: STATUS_ID.ACTIVE,
60
68
  },
69
+ userCreatedby: {
70
+ type: DataTypes.INTEGER.UNSIGNED,
71
+ allowNull: true,
72
+ references: {
73
+ model: "PortalUser",
74
+ key: "portalUserId",
75
+ },
76
+ },
77
+ userUpdatedby: {
78
+ type: DataTypes.INTEGER.UNSIGNED,
79
+ allowNull: true,
80
+ references: {
81
+ model: "PortalUser",
82
+ key: "portalUserId",
83
+ },
84
+ },
61
85
  },
62
86
  {
63
87
  sequelize,
64
- modelName: "DobitUser",
65
- tableName: "dobitUsers",
88
+ modelName: "DobitUsers",
89
+ tableName: "DobitUsers",
66
90
  timestamps: true,
67
91
  paranoid: true,
68
- }
92
+ },
69
93
  );
70
94
 
71
- DobitUser.removeAttribute("id");
72
- return DobitUser;
95
+ DobitUsers.removeAttribute("id");
96
+ return DobitUsers;
73
97
  };
74
98
 
75
99
  // firstName, lastName, email, username, phoneNumber, password, nin
package/models/index.js CHANGED
@@ -1,51 +1,3 @@
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
-
49
1
  "use strict";
50
2
 
51
3
  const fs = require("fs");
@@ -4,13 +4,23 @@ const { Model, DataTypes } = require("sequelize");
4
4
  const { STATUS_ID } = require("../service/constants");
5
5
 
6
6
  module.exports = (sequelize) => {
7
- class PortalUser extends Model {
7
+ class PortalUsers extends Model {
8
8
  static associate(models) {
9
9
  // define association here
10
+ PortalUsers.belongsTo(models.PortalUsers, {
11
+ foreignKey: "createdBy",
12
+ as: "creator",
13
+ allowNull: true,
14
+ });
15
+ PortalUsers.belongsTo(models.PortalUsers, {
16
+ foreignKey: "updatedBy",
17
+ as: "editor",
18
+ allowNull: true,
19
+ });
10
20
  }
11
21
  }
12
22
 
13
- PortalUser.init(
23
+ PortalUsers.init(
14
24
  {
15
25
  portalUserId: {
16
26
  type: DataTypes.INTEGER.UNSIGNED,
@@ -48,16 +58,24 @@ module.exports = (sequelize) => {
48
58
  allowNull: false,
49
59
  defaultValue: STATUS_ID.ACTIVE,
50
60
  },
61
+ createdBy: {
62
+ type: DataTypes.INTEGER.UNSIGNED,
63
+ allowNull: true,
64
+ },
65
+ updatedBy: {
66
+ type: DataTypes.INTEGER.UNSIGNED,
67
+ allowNull: true,
68
+ },
51
69
  },
52
-
53
70
  {
54
71
  sequelize,
55
- modelName: "PortalUser",
72
+ modelName: "PortalUsers",
56
73
  tableName: "PortalUsers",
57
74
  timestamps: true,
58
- underscored: true,
59
- }
75
+ paranoid: true,
76
+ },
60
77
  );
61
78
 
62
- return PortalUser;
79
+ PortalUsers.removeAttribute("id");
80
+ return PortalUsers;
63
81
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dip-dobit-shared-model",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "main": "models/index.js",
5
5
  "scripts": {
6
6
  "migrate:up": "npx sequelize-cli db:migrate",