vr-models 1.0.8 → 1.0.10
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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Model, InferAttributes, InferCreationAttributes, CreationOptional, NonAttribute, ModelStatic } from "vr-migrations";
|
|
2
2
|
import type { User } from "./user.models";
|
|
3
|
-
export declare const EVENT_ACTIONS: readonly ["USER_READ", "USER_UPDATED", "USERS_LISTED", "ADMIN_FORGOT_PASSWORD", "ADMIN_LOGGED_IN", "ADMIN_LOGGED_OUT", "PASSENGER_ACCOUNT_DEACTIVATED", "PASSENGER_ACCOUNT_DELETED", "AGENT_CREATED_RIDER", "AGENT_UPDATED_RIDER", "ADMIN_CREATED_USER", "ADMIN_UPDATED_USER", "SUPER_ADMIN_PASSWORD_CHANGED", "SUPER_ADMIN_CHANGED_USER_ACCOUNT_STATUS", "SUPER_ADMIN_UPDATED_USER", "SUPER_ADMIN_CREATED_USER", "PRODUCT_CREATED", "PRODUCT_READ", "PRODUCT_UPDATED", "PRODUCT_DELETED", "PRODUCTS_LISTED", "DEVICE_ASSIGNED", "DEVICE_READ", "DEVICE_UPDATED", "DEVICES_LISTED", "DEVICE_REPOSSESSED", "DEVICE_PAYMENT_PLAN_CREATED", "DEVICE_PAYMENT_PLAN_READ", "DEVICE_PAYMENT_PLAN_UPDATED", "DEVICE_PAYMENT_DEFAULT_MARKED", "PAYMENT_CREATED", "PAYMENT_READ", "PAYMENTS_LISTED", "TRANSACTION_READ", "TRANSACTIONS_LISTED", "EVENT_LOG_READ", "EVENT_LOGS_LISTED", "SECURITY_CLEARANCE_MANAGED", "DEVICE_LOCK_OVERRIDDEN"];
|
|
3
|
+
export declare const EVENT_ACTIONS: readonly ["USER_READ", "USER_CREATED", "USER_UPDATED", "USER_DELETED", "USER_SUSPENDED", "USER_BANNED", "USERS_LISTED", "ADMIN_FORGOT_PASSWORD", "ADMIN_LOGGED_IN", "ADMIN_LOGGED_OUT", "PASSENGER_ACCOUNT_DEACTIVATED", "PASSENGER_ACCOUNT_DELETED", "AGENT_CREATED_RIDER", "AGENT_UPDATED_RIDER", "ADMIN_CREATED_USER", "ADMIN_UPDATED_USER", "SUPER_ADMIN_PASSWORD_CHANGED", "SUPER_ADMIN_CHANGED_USER_ACCOUNT_STATUS", "SUPER_ADMIN_UPDATED_USER", "SUPER_ADMIN_CREATED_USER", "PRODUCT_CREATED", "PRODUCT_READ", "PRODUCT_UPDATED", "PRODUCT_DELETED", "PRODUCTS_LISTED", "DEVICE_ASSIGNED", "DEVICE_READ", "DEVICE_UPDATED", "DEVICES_LISTED", "DEVICE_REPOSSESSED", "DEVICE_PAYMENT_PLAN_CREATED", "DEVICE_PAYMENT_PLAN_READ", "DEVICE_PAYMENT_PLAN_UPDATED", "DEVICE_PAYMENT_DEFAULT_MARKED", "PAYMENT_CREATED", "PAYMENT_READ", "PAYMENTS_LISTED", "TRANSACTION_READ", "TRANSACTIONS_LISTED", "EVENT_LOG_READ", "EVENT_LOGS_LISTED", "SECURITY_CLEARANCE_MANAGED", "DEVICE_LOCK_OVERRIDDEN"];
|
|
4
4
|
export type EventAction = (typeof EVENT_ACTIONS)[number];
|
|
5
5
|
export type EventActorType = "USER" | "SYSTEM";
|
|
6
6
|
export interface EventLogAttributes {
|
|
@@ -5,7 +5,11 @@ const vr_migrations_1 = require("vr-migrations");
|
|
|
5
5
|
// Constants
|
|
6
6
|
exports.EVENT_ACTIONS = [
|
|
7
7
|
"USER_READ",
|
|
8
|
+
"USER_CREATED",
|
|
8
9
|
"USER_UPDATED",
|
|
10
|
+
"USER_DELETED",
|
|
11
|
+
"USER_SUSPENDED",
|
|
12
|
+
"USER_BANNED",
|
|
9
13
|
"USERS_LISTED",
|
|
10
14
|
"ADMIN_FORGOT_PASSWORD",
|
|
11
15
|
"ADMIN_LOGGED_IN",
|
|
@@ -2,6 +2,12 @@ import { Model, InferAttributes, InferCreationAttributes, CreationOptional, NonA
|
|
|
2
2
|
import type { Device } from "./device.models";
|
|
3
3
|
import type { Payment } from "./payment.models";
|
|
4
4
|
import type { SecurityClearance } from "./securityClearance.models";
|
|
5
|
+
export interface DeletionStatus {
|
|
6
|
+
deleted: boolean;
|
|
7
|
+
deletedAt?: Date | null;
|
|
8
|
+
deletedBy?: string | null;
|
|
9
|
+
reason?: string | null;
|
|
10
|
+
}
|
|
5
11
|
export interface UserAttributes {
|
|
6
12
|
id: string;
|
|
7
13
|
firstName: string;
|
|
@@ -26,6 +32,7 @@ export interface UserAttributes {
|
|
|
26
32
|
deactivatedAt: Date | null;
|
|
27
33
|
lastLoginAt: Date | null;
|
|
28
34
|
tokenVersion: number;
|
|
35
|
+
deletion: DeletionStatus;
|
|
29
36
|
createdAt: Date;
|
|
30
37
|
devices?: Device[];
|
|
31
38
|
payments?: Payment[];
|
|
@@ -63,12 +70,14 @@ export declare class User extends Model<InferAttributes<User>, InferCreationAttr
|
|
|
63
70
|
deactivatedAt: CreationOptional<Date | null>;
|
|
64
71
|
lastLoginAt: CreationOptional<Date | null>;
|
|
65
72
|
tokenVersion: CreationOptional<number>;
|
|
73
|
+
deletion: CreationOptional<DeletionStatus>;
|
|
66
74
|
readonly createdAt: CreationOptional<Date>;
|
|
67
75
|
devices?: NonAttribute<Device[]>;
|
|
68
76
|
payments?: NonAttribute<Payment[]>;
|
|
69
77
|
securityClearance?: NonAttribute<SecurityClearance>;
|
|
70
78
|
static initialize(sequelize: any): void;
|
|
71
79
|
static associate(models: Record<string, ModelStatic<Model>>): void;
|
|
80
|
+
softDelete(deletedBy: string, reason?: string): Promise<void>;
|
|
72
81
|
updateLastLogin(): Promise<void>;
|
|
73
82
|
generateOTP(): Promise<string>;
|
|
74
83
|
clearOTP(): Promise<void>;
|
|
@@ -105,6 +105,16 @@ class User extends vr_migrations_1.Model {
|
|
|
105
105
|
type: vr_migrations_1.DataTypes.DATE,
|
|
106
106
|
allowNull: true,
|
|
107
107
|
},
|
|
108
|
+
deletion: {
|
|
109
|
+
type: vr_migrations_1.DataTypes.JSONB,
|
|
110
|
+
allowNull: false,
|
|
111
|
+
defaultValue: {
|
|
112
|
+
deleted: false,
|
|
113
|
+
deletedAt: null,
|
|
114
|
+
deletedBy: null,
|
|
115
|
+
reason: null,
|
|
116
|
+
},
|
|
117
|
+
},
|
|
108
118
|
createdAt: {
|
|
109
119
|
type: vr_migrations_1.DataTypes.DATE,
|
|
110
120
|
defaultValue: vr_migrations_1.DataTypes.NOW,
|
|
@@ -140,6 +150,15 @@ class User extends vr_migrations_1.Model {
|
|
|
140
150
|
});
|
|
141
151
|
}
|
|
142
152
|
// Custom instance methods (example methods)
|
|
153
|
+
async softDelete(deletedBy, reason) {
|
|
154
|
+
this.deletion = {
|
|
155
|
+
deleted: true,
|
|
156
|
+
deletedAt: new Date(),
|
|
157
|
+
deletedBy,
|
|
158
|
+
reason,
|
|
159
|
+
};
|
|
160
|
+
await this.save();
|
|
161
|
+
}
|
|
143
162
|
async updateLastLogin() {
|
|
144
163
|
this.lastLoginAt = new Date();
|
|
145
164
|
await this.save();
|