vr-models 1.0.18 → 1.0.20

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,38 @@
1
+ import { Model, InferAttributes, InferCreationAttributes, CreationOptional, ModelStatic, NonAttribute } from "vr-migrations";
2
+ import { User } from "./user.models";
3
+ export interface BanAttributes {
4
+ id?: string;
5
+ userId: string;
6
+ adminId: string;
7
+ reason: string;
8
+ bannedAt: Date;
9
+ isPermanent: boolean;
10
+ appealedAt?: Date;
11
+ appealReason?: string;
12
+ appealStatus?: "pending" | "approved" | "rejected";
13
+ revokedAt?: Date;
14
+ revokedBy?: string;
15
+ revocationReason?: string;
16
+ user?: User;
17
+ }
18
+ export interface BanCreationAttributes extends Omit<BanAttributes, "id" | "createdAt" | "updatedAt"> {
19
+ id?: string;
20
+ }
21
+ export declare class Ban extends Model<InferAttributes<Ban>, InferCreationAttributes<Ban>> implements BanAttributes {
22
+ id: CreationOptional<string>;
23
+ userId: string;
24
+ adminId: string;
25
+ reason: string;
26
+ bannedAt: Date;
27
+ isPermanent: boolean;
28
+ appealedAt: CreationOptional<Date | undefined>;
29
+ appealReason: CreationOptional<string | undefined>;
30
+ appealStatus: CreationOptional<"pending" | "approved" | "rejected" | undefined>;
31
+ revokedAt: CreationOptional<Date | undefined>;
32
+ revokedBy: CreationOptional<string | undefined>;
33
+ revocationReason: CreationOptional<string | undefined>;
34
+ user: NonAttribute<User>;
35
+ static initialize(sequelize: any): void;
36
+ static associate(models: Record<string, ModelStatic<Model>>): void;
37
+ }
38
+ export type BanModel = typeof Ban;
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Ban = void 0;
4
+ const vr_migrations_1 = require("vr-migrations");
5
+ class Ban extends vr_migrations_1.Model {
6
+ static initialize(sequelize) {
7
+ this.init({
8
+ id: {
9
+ type: vr_migrations_1.DataTypes.UUID,
10
+ defaultValue: vr_migrations_1.DataTypes.UUIDV4,
11
+ primaryKey: true,
12
+ allowNull: false,
13
+ },
14
+ userId: {
15
+ type: vr_migrations_1.DataTypes.UUID,
16
+ allowNull: true,
17
+ },
18
+ adminId: {
19
+ type: vr_migrations_1.DataTypes.UUID,
20
+ allowNull: false,
21
+ },
22
+ reason: {
23
+ type: vr_migrations_1.DataTypes.TEXT,
24
+ allowNull: false,
25
+ },
26
+ bannedAt: {
27
+ type: vr_migrations_1.DataTypes.DATE,
28
+ allowNull: false,
29
+ defaultValue: vr_migrations_1.DataTypes.NOW,
30
+ },
31
+ isPermanent: {
32
+ type: vr_migrations_1.DataTypes.BOOLEAN,
33
+ allowNull: false,
34
+ defaultValue: false,
35
+ },
36
+ appealedAt: {
37
+ type: vr_migrations_1.DataTypes.DATE,
38
+ allowNull: true,
39
+ },
40
+ appealReason: {
41
+ type: vr_migrations_1.DataTypes.TEXT,
42
+ allowNull: true,
43
+ },
44
+ appealStatus: {
45
+ type: vr_migrations_1.DataTypes.ENUM("pending", "approved", "rejected"),
46
+ allowNull: true,
47
+ },
48
+ revokedAt: {
49
+ type: vr_migrations_1.DataTypes.DATE,
50
+ allowNull: true,
51
+ },
52
+ revokedBy: {
53
+ type: vr_migrations_1.DataTypes.UUID,
54
+ allowNull: true,
55
+ },
56
+ revocationReason: {
57
+ type: vr_migrations_1.DataTypes.TEXT,
58
+ allowNull: true,
59
+ },
60
+ }, {
61
+ sequelize,
62
+ modelName: "Ban",
63
+ tableName: "bans",
64
+ timestamps: true,
65
+ paranoid: false,
66
+ underscored: false,
67
+ freezeTableName: true,
68
+ });
69
+ }
70
+ static associate(models) {
71
+ this.belongsTo(models.User, {
72
+ foreignKey: "userId",
73
+ as: "user",
74
+ onDelete: "CASCADE",
75
+ onUpdate: "CASCADE",
76
+ });
77
+ this.belongsTo(models.User, {
78
+ foreignKey: "adminId",
79
+ as: "admin",
80
+ onDelete: "CASCADE",
81
+ onUpdate: "CASCADE",
82
+ });
83
+ }
84
+ }
85
+ exports.Ban = Ban;
@@ -1,11 +1,11 @@
1
1
  import { Model, InferAttributes, InferCreationAttributes, CreationOptional, NonAttribute, ModelStatic } from "vr-migrations";
2
2
  import type { User } from "./user.models";
3
+ import { UserRole } from "./securityClearance.models";
3
4
  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", "PRODUCTS_ACTIVATED", "PRODUCTS_DEACTIVATED", "PRODUCTS_LISTED", "PRODUCT_STOCK_SET_MANUALLY", "PRODUCT_STOCK_INCREMENTED", "PRODUCT_STOCK_DECREMENTED", "PRICING_CREATED", "PRICING_READ", "PRICING_UPDATED", "PRICING_DELETED", "DEVICE_CREATED", "DEVICES_BULK_CREATED", "DEVICE_ASSIGNED", "DEVICE_READ", "DEVICE_UPDATED", "DEVICES_LISTED", "DEVICE_LOCKED", "DEVICE_UNLOCKED", "DEVICE_DISABLED", "DEVICE_REACTIVATED", "DEVICE_DELETED_PERMANENTLY", "DEVICE_REPOSSESSED", "DEVICE_PAYMENT_PLAN_CREATED", "DEVICE_PAYMENT_PLAN_READ", "DEVICE_PAYMENT_PLAN_UPDATED", "DEVICE_PAYMENT_PLAN_MARKED_DEFAULTED", "DEVICE_PAYMENT_PLAN_SOFT_DELETED", "DEVICE_PAYMENT_PLAN_DELETED_PERMANENTLY", "PAYMENT_RECORDED", "PAYMENT_READ", "PAYMENTS_LISTED", "TRANSACTION_READ", "TRANSACTIONS_LISTED", "EVENT_LOG_READ", "EVENT_LOGS_LISTED", "SECURITY_CLEARANCE_MANAGED", "DEVICE_LOCK_OVERRIDDEN"];
4
5
  export type EventAction = (typeof EVENT_ACTIONS)[number];
5
- export type EventActorType = "USER" | "SYSTEM" | "ADMIN";
6
6
  export interface EventLogAttributes {
7
7
  id: string;
8
- actorType: EventActorType;
8
+ actorType: UserRole;
9
9
  actorId: string | null;
10
10
  action: EventAction;
11
11
  entity: string;
@@ -19,11 +19,11 @@ export interface EventLogAttributes {
19
19
  export interface EventLogCreationAttributes extends Omit<EventLogAttributes, "id" | "createdAt" | "metadata" | "actorType"> {
20
20
  id?: string;
21
21
  metadata?: Record<string, any>;
22
- actorType?: EventActorType;
22
+ actorType?: UserRole;
23
23
  }
24
24
  export declare class EventLog extends Model<InferAttributes<EventLog>, InferCreationAttributes<EventLog>> implements EventLogAttributes {
25
25
  id: CreationOptional<string>;
26
- actorType: CreationOptional<EventActorType>;
26
+ actorType: CreationOptional<UserRole>;
27
27
  actorId: CreationOptional<string | null>;
28
28
  action: EventAction;
29
29
  entity: string;
@@ -39,7 +39,5 @@ export declare class EventLog extends Model<InferAttributes<EventLog>, InferCrea
39
39
  static getUserEvents(userId: string, limit?: number): Promise<EventLog[]>;
40
40
  static getEntityEvents(entity: string, entityId: string, limit?: number): Promise<EventLog[]>;
41
41
  getSummary(): string;
42
- isUserAction(): boolean;
43
- isSystemAction(): boolean;
44
42
  }
45
43
  export type EventLogModel = typeof EventLog;
@@ -77,7 +77,7 @@ class EventLog extends vr_migrations_1.Model {
77
77
  primaryKey: true,
78
78
  },
79
79
  actorType: {
80
- type: vr_migrations_1.DataTypes.ENUM("USER", "SYSTEM", "ADMIN"),
80
+ type: vr_migrations_1.DataTypes.ENUM("RIDER", "PASSENGER", "AGENT", "ADMIN", "SUPER_ADMIN"),
81
81
  allowNull: false,
82
82
  defaultValue: "SYSTEM",
83
83
  },
@@ -151,13 +151,7 @@ class EventLog extends vr_migrations_1.Model {
151
151
  });
152
152
  }
153
153
  getSummary() {
154
- return `${this.actorType}:${this.actorId || "SYSTEM"} performed ${this.action} on ${this.entity}${this.entityId ? `:${this.entityId}` : ""}`;
155
- }
156
- isUserAction() {
157
- return this.actorType === "USER";
158
- }
159
- isSystemAction() {
160
- return this.actorType === "SYSTEM";
154
+ return `${this.actorType}:${this.actorId} performed ${this.action} on ${this.entity}${this.entityId ? `:${this.entityId}` : ""}`;
161
155
  }
162
156
  }
163
157
  exports.EventLog = EventLog;
@@ -25,7 +25,7 @@ class Pricing extends vr_migrations_1.Model {
25
25
  },
26
26
  downPayment: {
27
27
  type: vr_migrations_1.DataTypes.DECIMAL(10, 2),
28
- allowNull: false,
28
+ allowNull: true,
29
29
  defaultValue: 0,
30
30
  },
31
31
  installmentAmount: {
@@ -0,0 +1,43 @@
1
+ import { Model, InferAttributes, InferCreationAttributes, CreationOptional, ModelStatic, NonAttribute } from "vr-migrations";
2
+ import { User } from "./user.models";
3
+ export interface SuspensionAttributes {
4
+ id: string;
5
+ userId: string;
6
+ adminId: string;
7
+ reason: string;
8
+ startedAt: Date;
9
+ endsAt: Date;
10
+ isActive: boolean;
11
+ appealedAt?: Date;
12
+ appealReason?: string;
13
+ appealStatus?: "pending" | "approved" | "rejected";
14
+ revokedAt?: Date;
15
+ revokedBy?: string;
16
+ revocationReason?: string;
17
+ createdAt?: Date;
18
+ updatedAt?: Date;
19
+ admin: NonAttribute<User>;
20
+ user: NonAttribute<User>;
21
+ }
22
+ export declare class Suspension extends Model<InferAttributes<Suspension>, InferCreationAttributes<Suspension>> implements SuspensionAttributes {
23
+ id: CreationOptional<string>;
24
+ userId: string;
25
+ adminId: string;
26
+ reason: string;
27
+ startedAt: Date;
28
+ endsAt: Date;
29
+ isActive: boolean;
30
+ appealedAt: CreationOptional<Date | undefined>;
31
+ appealReason: CreationOptional<string | undefined>;
32
+ appealStatus: CreationOptional<"pending" | "approved" | "rejected" | undefined>;
33
+ revokedAt: CreationOptional<Date | undefined>;
34
+ revokedBy: CreationOptional<string | undefined>;
35
+ revocationReason: CreationOptional<string | undefined>;
36
+ createdAt: CreationOptional<Date | undefined>;
37
+ updatedAt: CreationOptional<Date | undefined>;
38
+ admin: NonAttribute<User>;
39
+ user: NonAttribute<User>;
40
+ static initialize(sequelize: any): void;
41
+ static associate(models: Record<string, ModelStatic<Model>>): void;
42
+ }
43
+ export type SuspensionModel = typeof Suspension;
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Suspension = void 0;
4
+ const vr_migrations_1 = require("vr-migrations");
5
+ class Suspension extends vr_migrations_1.Model {
6
+ static initialize(sequelize) {
7
+ this.init({
8
+ id: {
9
+ type: vr_migrations_1.DataTypes.UUID,
10
+ defaultValue: vr_migrations_1.DataTypes.UUIDV4,
11
+ primaryKey: true,
12
+ allowNull: false,
13
+ },
14
+ userId: {
15
+ type: vr_migrations_1.DataTypes.UUID,
16
+ allowNull: true,
17
+ },
18
+ adminId: {
19
+ type: vr_migrations_1.DataTypes.UUID,
20
+ allowNull: false,
21
+ },
22
+ reason: {
23
+ type: vr_migrations_1.DataTypes.TEXT,
24
+ allowNull: false,
25
+ },
26
+ startedAt: {
27
+ type: vr_migrations_1.DataTypes.DATE,
28
+ allowNull: false,
29
+ defaultValue: vr_migrations_1.DataTypes.NOW,
30
+ },
31
+ endsAt: {
32
+ type: vr_migrations_1.DataTypes.DATE,
33
+ allowNull: false,
34
+ },
35
+ isActive: {
36
+ type: vr_migrations_1.DataTypes.BOOLEAN,
37
+ allowNull: false,
38
+ defaultValue: true,
39
+ },
40
+ appealedAt: {
41
+ type: vr_migrations_1.DataTypes.DATE,
42
+ allowNull: true,
43
+ },
44
+ appealReason: {
45
+ type: vr_migrations_1.DataTypes.TEXT,
46
+ allowNull: true,
47
+ },
48
+ appealStatus: {
49
+ type: vr_migrations_1.DataTypes.ENUM("pending", "approved", "rejected"),
50
+ allowNull: true,
51
+ },
52
+ revokedAt: {
53
+ type: vr_migrations_1.DataTypes.DATE,
54
+ allowNull: true,
55
+ },
56
+ revokedBy: {
57
+ type: vr_migrations_1.DataTypes.UUID,
58
+ allowNull: true,
59
+ },
60
+ revocationReason: {
61
+ type: vr_migrations_1.DataTypes.TEXT,
62
+ allowNull: true,
63
+ },
64
+ createdAt: {
65
+ type: vr_migrations_1.DataTypes.DATE,
66
+ allowNull: false,
67
+ defaultValue: vr_migrations_1.DataTypes.NOW,
68
+ },
69
+ updatedAt: {
70
+ type: vr_migrations_1.DataTypes.DATE,
71
+ allowNull: false,
72
+ defaultValue: vr_migrations_1.DataTypes.NOW,
73
+ },
74
+ }, {
75
+ sequelize,
76
+ modelName: "Suspension",
77
+ tableName: "suspensions",
78
+ timestamps: true,
79
+ paranoid: false,
80
+ underscored: false,
81
+ freezeTableName: true,
82
+ });
83
+ }
84
+ static associate(models) {
85
+ this.belongsTo(models.User, {
86
+ foreignKey: "userId",
87
+ as: "user",
88
+ onDelete: "CASCADE",
89
+ onUpdate: "CASCADE",
90
+ });
91
+ this.belongsTo(models.User, {
92
+ foreignKey: "adminId",
93
+ as: "admin",
94
+ onDelete: "CASCADE",
95
+ onUpdate: "CASCADE",
96
+ });
97
+ }
98
+ }
99
+ exports.Suspension = Suspension;
@@ -148,6 +148,20 @@ class User extends vr_migrations_1.Model {
148
148
  onDelete: "CASCADE",
149
149
  onUpdate: "CASCADE",
150
150
  });
151
+ // Suspensions
152
+ this.hasMany(models.Suspension, {
153
+ foreignKey: "userId",
154
+ as: "suspensions",
155
+ onDelete: "CASCADE",
156
+ onUpdate: "CASCADE",
157
+ });
158
+ // Bans
159
+ this.hasMany(models.Ban, {
160
+ foreignKey: "userId",
161
+ as: "bans",
162
+ onDelete: "CASCADE",
163
+ onUpdate: "CASCADE",
164
+ });
151
165
  }
152
166
  // Custom instance methods (example methods)
153
167
  async softDelete(deletedBy, reason) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vr-models",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "description": "Shared database models package for VR applications",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",