ojamoto_models 1.0.7 → 1.0.8

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.
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ up: async (queryInterface, Sequelize) => {
5
+ const tableDescription = await queryInterface.describeTable("admin_users");
6
+
7
+ if (!tableDescription.country_calling_code) {
8
+ await queryInterface.addColumn("admin_users", "country_calling_code", {
9
+ type: Sequelize.STRING,
10
+ allowNull: true,
11
+ after: "phone",
12
+ });
13
+ }
14
+
15
+ await queryInterface.changeColumn("admin_users", "phone", {
16
+ type: Sequelize.STRING(10),
17
+ allowNull: false,
18
+ });
19
+ },
20
+
21
+ down: async (queryInterface) => {
22
+ await queryInterface.changeColumn("admin_users", "phone", {
23
+ type: Sequelize.STRING(20),
24
+ allowNull: false,
25
+ });
26
+
27
+ await queryInterface.removeColumn("admin_users", "country_calling_code");
28
+ },
29
+ };
@@ -71,10 +71,14 @@ module.exports = (sequelize) => {
71
71
  validate: { isEmail: true },
72
72
  },
73
73
  phone: {
74
- type: DataTypes.STRING(20),
74
+ type: DataTypes.STRING(10),
75
75
  allowNull: false,
76
76
  unique: true,
77
77
  },
78
+ country_calling_code: {
79
+ type: DataTypes.STRING(3),
80
+ allowNull: false,
81
+ },
78
82
  password_hash: {
79
83
  type: DataTypes.STRING(255),
80
84
  allowNull: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ojamoto_models",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "migrate:up": "npx sequelize-cli db:migrate",
@@ -22,6 +22,8 @@
22
22
  "homepage": "https://github.com/ojamoto/ojamoto_models#readme",
23
23
  "description": "",
24
24
  "dependencies": {
25
+ "bcrypt": "^6.0.0",
26
+ "crypto": "^1.0.1",
25
27
  "dotenv": "^17.4.2",
26
28
  "mysql2": "^3.23.2",
27
29
  "sequelize": "^6.37.8",
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+
3
+ const bcrypt = require("bcrypt");
4
+ const crypto = require("crypto");
5
+ const { ADMIN_ROLE, ADMIN_STATUS } = require("../services/constants");
6
+
7
+ module.exports = {
8
+ async up(queryInterface) {
9
+ const email = process.env.SUPER_ADMIN_EMAIL;
10
+ const tempPassword = process.env.SUPER_ADMIN_TEMP_PASSWORD;
11
+
12
+ if (!email || !tempPassword) {
13
+ throw new Error(
14
+ "SUPER_ADMIN_EMAIL and SUPER_ADMIN_TEMP_PASSWORD must be set in your environment before running this seeder",
15
+ );
16
+ }
17
+
18
+ const existing = await queryInterface.sequelize.query(
19
+ `SELECT admin_id FROM admin_users WHERE email = :email LIMIT 1`,
20
+ {
21
+ replacements: { email },
22
+ type: queryInterface.sequelize.QueryTypes.SELECT,
23
+ },
24
+ );
25
+
26
+ if (existing.length > 0) {
27
+ console.log("Super admin already exists — skipping seed");
28
+ return;
29
+ }
30
+
31
+ const password_hash = await bcrypt.hash(tempPassword, 12);
32
+
33
+ await queryInterface.bulkInsert("admin_users", [
34
+ {
35
+ uuid: crypto.randomUUID(),
36
+ first_name: process.env.SUPER_ADMIN_FIRST_NAME || "Super",
37
+ last_name: process.env.SUPER_ADMIN_LAST_NAME || "Admin",
38
+ email,
39
+ phone: process.env.SUPER_ADMIN_PHONE || "8085202397",
40
+ country_calling_code:
41
+ process.env.SUPER_ADMIN_COUNTRY_CALLING_CODE || "234",
42
+ password_hash,
43
+ must_change_password: true,
44
+ role: ADMIN_ROLE.SUPER_ADMIN,
45
+ status: ADMIN_STATUS.ACTIVE,
46
+ two_factor_enabled: true,
47
+ totp_secret: null,
48
+ created_by: null,
49
+ created_at: new Date(),
50
+ updated_at: new Date(),
51
+ },
52
+ ]);
53
+ },
54
+
55
+ async down(queryInterface) {
56
+ const email = process.env.SUPER_ADMIN_EMAIL;
57
+ if (!email) return;
58
+
59
+ await queryInterface.bulkDelete("admin_users", { email });
60
+ },
61
+ };