vr-models 1.0.51 → 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.
@@ -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: "SET NULL", // ← This is SET NULL, not 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;
@@ -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,12 +119,6 @@ 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: "SET NULL", // ← This is SET NULL, not CASCADE
126
- onUpdate: "CASCADE",
127
- });
128
122
  this.hasMany(models.Payment, {
129
123
  foreignKey: "userId",
130
124
  as: "payments",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vr-models",
3
- "version": "1.0.51",
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",