vr-models 1.0.50 → 1.0.52

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.
@@ -79,19 +79,19 @@ class Ban extends vr_migrations_1.Model {
79
79
  this.belongsTo(models.User, {
80
80
  foreignKey: "userId",
81
81
  as: "user",
82
- onDelete: "CASCADE",
82
+ onDelete: "SET NULL", // ← This is SET NULL, not CASCADE
83
83
  onUpdate: "CASCADE",
84
84
  });
85
85
  this.belongsTo(models.User, {
86
86
  foreignKey: "adminId",
87
87
  as: "admin",
88
- onDelete: "CASCADE",
88
+ onDelete: "SET NULL", // ← This is SET NULL, not CASCADE
89
89
  onUpdate: "CASCADE",
90
90
  });
91
91
  this.belongsTo(models.User, {
92
92
  foreignKey: "revokedBy",
93
93
  as: "revokingAdmin",
94
- onDelete: "CASCADE",
94
+ onDelete: "SET NULL", // ← This is SET NULL, not CASCADE
95
95
  onUpdate: "CASCADE",
96
96
  });
97
97
  }
@@ -88,7 +88,7 @@ class DevicePaymentPlan extends vr_migrations_1.Model {
88
88
  this.hasMany(models.Installment, {
89
89
  foreignKey: "devicePaymentPlanId",
90
90
  as: "installments",
91
- onDelete: "CASCADE",
91
+ onDelete: "SET NULL", // ← This is SET NULL, not CASCADE
92
92
  onUpdate: "CASCADE",
93
93
  });
94
94
  }
@@ -106,7 +106,7 @@ class Installment extends vr_migrations_1.Model {
106
106
  this.belongsTo(models.DevicePaymentPlan, {
107
107
  foreignKey: "devicePaymentPlanId",
108
108
  as: "paymentPlan",
109
- onDelete: "CASCADE",
109
+ onDelete: "SET NULL", // ← This is SET NULL, not CASCADE
110
110
  onUpdate: "CASCADE",
111
111
  });
112
112
  this.belongsTo(models.Payment, {
@@ -16,17 +16,21 @@ export interface PricingAttributes {
16
16
  installmentCount: number | null;
17
17
  gracePeriodDays: number;
18
18
  autoLockOnMiss: boolean;
19
+ minOrderQuantity: number;
20
+ maxOrderQuantity: number;
19
21
  isActive: boolean;
20
22
  createdAt: Date;
21
23
  updatedAt: Date;
22
24
  product?: Product;
23
25
  }
24
- export interface PricingCreationAttributes extends Omit<PricingAttributes, "id" | "createdAt" | "updatedAt" | "isActive" | "downPayment" | "gracePeriodDays" | "autoLockOnMiss"> {
26
+ export interface PricingCreationAttributes extends Omit<PricingAttributes, "id" | "createdAt" | "updatedAt" | "isActive" | "downPayment" | "gracePeriodDays" | "autoLockOnMiss" | "minOrderQuantity" | "maxOrderQuantity"> {
25
27
  id?: string;
26
28
  isActive?: boolean;
27
29
  downPayment?: number;
28
30
  gracePeriodDays?: number;
29
31
  autoLockOnMiss?: boolean;
32
+ minOrderQuantity?: number;
33
+ maxOrderQuantity?: number;
30
34
  }
31
35
  export declare class Pricing extends Model<InferAttributes<Pricing>, InferCreationAttributes<Pricing>> implements PricingAttributes {
32
36
  id: CreationOptional<string>;
@@ -40,6 +44,8 @@ export declare class Pricing extends Model<InferAttributes<Pricing>, InferCreati
40
44
  installmentCount: CreationOptional<number | null>;
41
45
  gracePeriodDays: CreationOptional<number>;
42
46
  autoLockOnMiss: CreationOptional<boolean>;
47
+ minOrderQuantity: CreationOptional<number>;
48
+ maxOrderQuantity: CreationOptional<number>;
43
49
  isActive: CreationOptional<boolean>;
44
50
  readonly createdAt: CreationOptional<Date>;
45
51
  readonly updatedAt: CreationOptional<Date>;
@@ -52,5 +58,6 @@ export declare class Pricing extends Model<InferAttributes<Pricing>, InferCreati
52
58
  getInstallmentCount(): number | null;
53
59
  calculateRemainingAmount(paidAmount: number): number;
54
60
  calculateNextDueDate(fromDate?: Date): Date | null;
61
+ isValidOrderQuantity(quantity: number): boolean;
55
62
  }
56
63
  export type PricingModel = typeof Pricing;
@@ -24,7 +24,7 @@ class Pricing extends vr_migrations_1.Model {
24
24
  totalAmount: {
25
25
  type: vr_migrations_1.DataTypes.DECIMAL(10, 2),
26
26
  allowNull: false,
27
- field: "total_amount", // Maps to database column
27
+ field: "total_amount",
28
28
  },
29
29
  downPayment: {
30
30
  type: vr_migrations_1.DataTypes.DECIMAL(10, 2),
@@ -53,6 +53,22 @@ class Pricing extends vr_migrations_1.Model {
53
53
  allowNull: false,
54
54
  defaultValue: true,
55
55
  },
56
+ minOrderQuantity: {
57
+ type: vr_migrations_1.DataTypes.INTEGER,
58
+ allowNull: false,
59
+ defaultValue: 1,
60
+ validate: {
61
+ min: 1,
62
+ },
63
+ },
64
+ maxOrderQuantity: {
65
+ type: vr_migrations_1.DataTypes.INTEGER,
66
+ allowNull: false,
67
+ defaultValue: 1,
68
+ validate: {
69
+ min: 1,
70
+ },
71
+ },
56
72
  isActive: {
57
73
  type: vr_migrations_1.DataTypes.BOOLEAN,
58
74
  allowNull: false,
@@ -72,7 +88,7 @@ class Pricing extends vr_migrations_1.Model {
72
88
  this.belongsTo(models.Product, {
73
89
  foreignKey: "productId",
74
90
  as: "product",
75
- onDelete: "CASCADE",
91
+ onDelete: "SET NULL",
76
92
  onUpdate: "CASCADE",
77
93
  });
78
94
  }
@@ -96,7 +112,6 @@ class Pricing extends vr_migrations_1.Model {
96
112
  calculateRemainingAmount(paidAmount) {
97
113
  return Math.max(0, this.totalAmount - paidAmount);
98
114
  }
99
- // Helper to calculate next due date based on frequency
100
115
  calculateNextDueDate(fromDate = new Date()) {
101
116
  if (!this.installmentFrequency)
102
117
  return null;
@@ -114,5 +129,9 @@ class Pricing extends vr_migrations_1.Model {
114
129
  }
115
130
  return nextDate;
116
131
  }
132
+ // Helper method to validate order quantity
133
+ isValidOrderQuantity(quantity) {
134
+ return (quantity >= this.minOrderQuantity && quantity <= this.maxOrderQuantity);
135
+ }
117
136
  }
118
137
  exports.Pricing = Pricing;
@@ -34,7 +34,7 @@ class Product extends vr_migrations_1.Model {
34
34
  this.hasMany(models.Pricing, {
35
35
  foreignKey: "productId",
36
36
  as: "pricings",
37
- onDelete: "CASCADE",
37
+ onDelete: "SET NULL", // ← This is SET NULL, not CASCADE
38
38
  onUpdate: "CASCADE",
39
39
  });
40
40
  this.hasMany(models.Device, {
@@ -85,19 +85,19 @@ class Suspension extends vr_migrations_1.Model {
85
85
  this.belongsTo(models.User, {
86
86
  foreignKey: "userId",
87
87
  as: "user",
88
- onDelete: "CASCADE",
88
+ onDelete: "SET NULL", // ← This is SET NULL, not CASCADE
89
89
  onUpdate: "CASCADE",
90
90
  });
91
91
  this.belongsTo(models.User, {
92
92
  foreignKey: "adminId",
93
93
  as: "admin",
94
- onDelete: "CASCADE",
94
+ onDelete: "SET NULL", // ← This is SET NULL, not CASCADE
95
95
  onUpdate: "CASCADE",
96
96
  });
97
97
  this.belongsTo(models.User, {
98
98
  foreignKey: "revokedBy",
99
99
  as: "revokingAdmin",
100
- onDelete: "CASCADE",
100
+ onDelete: "SET NULL", // ← This is SET NULL, not CASCADE
101
101
  onUpdate: "CASCADE",
102
102
  });
103
103
  }
@@ -42,7 +42,7 @@ class Transaction extends vr_migrations_1.Model {
42
42
  this.belongsTo(models.Payment, {
43
43
  foreignKey: "paymentId",
44
44
  as: "payment",
45
- onDelete: "CASCADE",
45
+ onDelete: "SET NULL", // ← This is SET NULL, not CASCADE
46
46
  onUpdate: "CASCADE",
47
47
  });
48
48
  this.belongsTo(models.User, {
@@ -1,5 +1,4 @@
1
1
  import { Model, InferAttributes, InferCreationAttributes, CreationOptional, NonAttribute, ModelStatic } from "vr-migrations";
2
- import type { Device } from "./device.models";
3
2
  import type { Payment } from "./payment.models";
4
3
  import type { SecurityClearance } from "./securityClearance.models";
5
4
  import type { PhoneContact } from "./phoneContact.models";
@@ -30,7 +29,6 @@ export interface UserAttributes {
30
29
  tokenVersion: number;
31
30
  deletion: DeletionStatus;
32
31
  createdAt: Date;
33
- devices?: Device[];
34
32
  payments?: Payment[];
35
33
  securityClearance?: SecurityClearance;
36
34
  primaryPhone?: PhoneContact;
@@ -65,7 +63,6 @@ export declare class User extends Model<InferAttributes<User>, InferCreationAttr
65
63
  tokenVersion: CreationOptional<number>;
66
64
  deletion: CreationOptional<DeletionStatus>;
67
65
  readonly createdAt: CreationOptional<Date>;
68
- devices?: NonAttribute<Device[]>;
69
66
  payments?: NonAttribute<Payment[]>;
70
67
  securityClearance?: NonAttribute<SecurityClearance>;
71
68
  primaryPhone?: NonAttribute<PhoneContact>;
@@ -119,28 +119,22 @@ class User extends vr_migrations_1.Model {
119
119
  onDelete: "SET NULL",
120
120
  onUpdate: "CASCADE",
121
121
  });
122
- this.hasMany(models.Device, {
123
- foreignKey: "userId",
124
- as: "devices",
125
- onDelete: "CASCADE",
126
- onUpdate: "CASCADE",
127
- });
128
122
  this.hasMany(models.Payment, {
129
123
  foreignKey: "userId",
130
124
  as: "payments",
131
- onDelete: "CASCADE",
125
+ onDelete: "SET NULL", // ← This is SET NULL, not CASCADE
132
126
  onUpdate: "CASCADE",
133
127
  });
134
128
  this.hasMany(models.Suspension, {
135
129
  foreignKey: "userId",
136
130
  as: "suspensions",
137
- onDelete: "CASCADE",
131
+ onDelete: "SET NULL", // ← This is SET NULL, not CASCADE
138
132
  onUpdate: "CASCADE",
139
133
  });
140
134
  this.hasMany(models.Ban, {
141
135
  foreignKey: "userId",
142
136
  as: "bans",
143
- onDelete: "CASCADE",
137
+ onDelete: "SET NULL", // ← This is SET NULL, not CASCADE
144
138
  onUpdate: "CASCADE",
145
139
  });
146
140
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vr-models",
3
- "version": "1.0.50",
3
+ "version": "1.0.52",
4
4
  "description": "Shared database models package for VR applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",