ojamoto_models 1.0.5 → 1.0.6

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,21 @@
1
+ "use strict";
2
+
3
+ const { WALLET_TRANSACTION_STATUS } = require("../services/constants");
4
+
5
+ module.exports = {
6
+ async up(queryInterface, Sequelize) {
7
+ await queryInterface.changeColumn("wallet_transactions", "status", {
8
+ type: Sequelize.ENUM(...Object.values(WALLET_TRANSACTION_STATUS)),
9
+ allowNull: false,
10
+ defaultValue: WALLET_TRANSACTION_STATUS.PENDING,
11
+ });
12
+ },
13
+
14
+ async down(queryInterface, Sequelize) {
15
+ await queryInterface.changeColumn("wallet_transactions", "status", {
16
+ type: Sequelize.ENUM("PENDING", "SUCCESS", "FAILED"),
17
+ allowNull: false,
18
+ defaultValue: "PENDING",
19
+ });
20
+ },
21
+ };
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ module.exports = {
4
+ async up(queryInterface, Sequelize) {
5
+ await queryInterface.createTable("product_availability_reminders", {
6
+ product_availability_reminder_id: {
7
+ type: Sequelize.INTEGER,
8
+ primaryKey: true,
9
+ autoIncrement: true,
10
+ allowNull: false,
11
+ },
12
+ product_id: {
13
+ type: Sequelize.INTEGER,
14
+ allowNull: false,
15
+ references: { model: "products", key: "product_id" },
16
+ onDelete: "CASCADE",
17
+ onUpdate: "CASCADE",
18
+ },
19
+ email: {
20
+ type: Sequelize.STRING(255),
21
+ allowNull: false,
22
+ },
23
+ notified_at: {
24
+ type: Sequelize.DATE,
25
+ allowNull: true,
26
+ },
27
+ created_at: {
28
+ type: Sequelize.DATE,
29
+ allowNull: false,
30
+ },
31
+ });
32
+
33
+ await queryInterface.addIndex("product_availability_reminders", [
34
+ "product_id",
35
+ ]);
36
+ await queryInterface.addIndex("product_availability_reminders", [
37
+ "product_id",
38
+ "notified_at",
39
+ ]);
40
+ // One reminder per email per product — no duplicate sign-ups
41
+ await queryInterface.addIndex(
42
+ "product_availability_reminders",
43
+ ["product_id", "email"],
44
+ {
45
+ unique: true,
46
+ name: "product_availability_reminders_product_email_unique",
47
+ },
48
+ );
49
+ },
50
+
51
+ async down(queryInterface) {
52
+ await queryInterface.dropTable("product_availability_reminders");
53
+ },
54
+ };
package/models/Product.js CHANGED
@@ -25,6 +25,11 @@ module.exports = (sequelize) => {
25
25
  foreignKey: "product_id",
26
26
  as: "wishlistedBy",
27
27
  });
28
+
29
+ Product.hasMany(models.ProductAvailabilityReminder, {
30
+ foreignKey: "product_id",
31
+ as: "availabilityReminders",
32
+ });
28
33
  }
29
34
  }
30
35
 
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+
3
+ const { Model, DataTypes } = require("sequelize");
4
+
5
+ module.exports = (sequelize) => {
6
+ class ProductAvailabilityReminder extends Model {
7
+ static associate(models) {
8
+ ProductAvailabilityReminder.belongsTo(models.Product, {
9
+ foreignKey: "product_id",
10
+ as: "product",
11
+ });
12
+ }
13
+ }
14
+
15
+ ProductAvailabilityReminder.init(
16
+ {
17
+ product_availability_reminder_id: {
18
+ type: DataTypes.INTEGER,
19
+ primaryKey: true,
20
+ autoIncrement: true,
21
+ },
22
+ product_id: {
23
+ type: DataTypes.INTEGER,
24
+ allowNull: false,
25
+ references: { model: "products", key: "product_id" },
26
+ onDelete: "CASCADE",
27
+ },
28
+ email: {
29
+ type: DataTypes.STRING(255),
30
+ allowNull: false,
31
+ validate: { isEmail: true },
32
+ },
33
+ notified_at: {
34
+ type: DataTypes.DATE,
35
+ allowNull: true,
36
+ comment:
37
+ "Set once the restock email has been sent — prevents duplicate notifications",
38
+ },
39
+ },
40
+ {
41
+ sequelize,
42
+ modelName: "ProductAvailabilityReminder",
43
+ tableName: "product_availability_reminders",
44
+ timestamps: true,
45
+ createdAt: "created_at",
46
+ updatedAt: false,
47
+ },
48
+ );
49
+
50
+ ProductAvailabilityReminder.removeAttribute("id");
51
+ return ProductAvailabilityReminder;
52
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ojamoto_models",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "migrate:up": "npx sequelize-cli db:migrate",
@@ -105,6 +105,7 @@ module.exports = {
105
105
  PENDING: "PENDING",
106
106
  SUCCESS: "SUCCESS",
107
107
  FAILED: "FAILED",
108
+ EXPIRED: "EXPIRED",
108
109
  },
109
110
 
110
111
  // - escrows.status ───────────────────────────────────────────────────────