vr-models 1.0.36 → 1.0.38
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.
|
@@ -49,5 +49,13 @@ export declare class Device extends Model<InferAttributes<Device>, InferCreation
|
|
|
49
49
|
canBeActivated(): boolean;
|
|
50
50
|
isAssigned(): boolean;
|
|
51
51
|
getPaymentPlan(): Promise<DevicePaymentPlan | null>;
|
|
52
|
+
/**
|
|
53
|
+
* Check if device can be unlocked by user
|
|
54
|
+
*/
|
|
55
|
+
canBeUnlocked(userId: string): Promise<{
|
|
56
|
+
canUnlock: boolean;
|
|
57
|
+
reason?: string;
|
|
58
|
+
details?: any;
|
|
59
|
+
}>;
|
|
52
60
|
}
|
|
53
61
|
export type DeviceModel = typeof Device;
|
|
@@ -117,5 +117,69 @@ class Device extends vr_migrations_1.Model {
|
|
|
117
117
|
.DevicePaymentPlan;
|
|
118
118
|
return await DevicePaymentPlan.findByPk(this.devicePaymentPlanId);
|
|
119
119
|
}
|
|
120
|
+
// Add to device.models.ts
|
|
121
|
+
/**
|
|
122
|
+
* Check if device can be unlocked by user
|
|
123
|
+
*/
|
|
124
|
+
async canBeUnlocked(userId) {
|
|
125
|
+
// Check if permanently unlocked
|
|
126
|
+
if (this.isPermanentlyUnlocked) {
|
|
127
|
+
return { canUnlock: false, reason: "Device is permanently unlocked" };
|
|
128
|
+
}
|
|
129
|
+
// Check if disabled
|
|
130
|
+
if (this.status === "disabled") {
|
|
131
|
+
return { canUnlock: false, reason: "Device is disabled" };
|
|
132
|
+
}
|
|
133
|
+
// Check if already unlocked
|
|
134
|
+
if (this.status === "unlocked") {
|
|
135
|
+
return { canUnlock: false, reason: "Device is already unlocked" };
|
|
136
|
+
}
|
|
137
|
+
// Check if has payment plan
|
|
138
|
+
if (!this.devicePaymentPlanId) {
|
|
139
|
+
return {
|
|
140
|
+
canUnlock: false,
|
|
141
|
+
reason: "Device is not associated with a payment plan",
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
// Get payment plan
|
|
145
|
+
const paymentPlan = await this.getPaymentPlan();
|
|
146
|
+
if (!paymentPlan) {
|
|
147
|
+
return { canUnlock: false, reason: "Payment plan not found" };
|
|
148
|
+
}
|
|
149
|
+
// Check ownership
|
|
150
|
+
if (paymentPlan.userId !== userId) {
|
|
151
|
+
return { canUnlock: false, reason: "Device does not belong to you" };
|
|
152
|
+
}
|
|
153
|
+
// Check payment plan status
|
|
154
|
+
if (paymentPlan.status !== "ACTIVE") {
|
|
155
|
+
let reason = "Payment plan is not active";
|
|
156
|
+
if (paymentPlan.status === "DEFAULTED")
|
|
157
|
+
reason = "Payment plan is defaulted";
|
|
158
|
+
if (paymentPlan.status === "CANCELLED")
|
|
159
|
+
reason = "Payment plan is cancelled";
|
|
160
|
+
return { canUnlock: false, reason };
|
|
161
|
+
}
|
|
162
|
+
// Check for overdue installments
|
|
163
|
+
const Installment = this.constructor.sequelize.models.Installment;
|
|
164
|
+
const overdueInstallments = await Installment.findAll({
|
|
165
|
+
where: {
|
|
166
|
+
devicePaymentPlanId: this.devicePaymentPlanId,
|
|
167
|
+
status: "OVERDUE",
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
if (overdueInstallments.length > 0) {
|
|
171
|
+
const totalOverdue = overdueInstallments.reduce((sum, inst) => sum + inst.amount, 0);
|
|
172
|
+
return {
|
|
173
|
+
canUnlock: false,
|
|
174
|
+
reason: `You have ${overdueInstallments.length} overdue installment(s)`,
|
|
175
|
+
details: {
|
|
176
|
+
overdueCount: overdueInstallments.length,
|
|
177
|
+
totalOverdueAmount: totalOverdue,
|
|
178
|
+
overdueInstallments,
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
return { canUnlock: true };
|
|
183
|
+
}
|
|
120
184
|
}
|
|
121
185
|
exports.Device = Device;
|
package/dist/models/index.d.ts
CHANGED
|
@@ -11,4 +11,5 @@ export * from "./transaction.models";
|
|
|
11
11
|
export * from "./installment.models";
|
|
12
12
|
export * from "./ban.models";
|
|
13
13
|
export * from "./suspension.models";
|
|
14
|
-
export
|
|
14
|
+
export * from "./appSpecs.models";
|
|
15
|
+
export type { UserModel, TransactionModel, SecurityClearanceModel, ProductModel, PricingModel, PaymentModel, IdempotencyRecordModel, EventLogModel, DevicePaymentPlanModel, DeviceModel, InstallmentModel, BanModel, SuspensionModel, AppSpecsModel, } from "./types";
|
package/dist/models/index.js
CHANGED
|
@@ -27,3 +27,4 @@ __exportStar(require("./transaction.models"), exports);
|
|
|
27
27
|
__exportStar(require("./installment.models"), exports);
|
|
28
28
|
__exportStar(require("./ban.models"), exports);
|
|
29
29
|
__exportStar(require("./suspension.models"), exports);
|
|
30
|
+
__exportStar(require("./appSpecs.models"), exports);
|
package/dist/models/types.d.ts
CHANGED
|
@@ -11,3 +11,4 @@ export type { DeviceModel } from "./device.models";
|
|
|
11
11
|
export type { InstallmentModel } from "./installment.models";
|
|
12
12
|
export type { BanModel } from "./ban.models";
|
|
13
13
|
export type { SuspensionModel } from "./suspension.models";
|
|
14
|
+
export type { AppSpecsModel } from "./appSpecs.models";
|