vr-models 1.0.1
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.
- package/README.md +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +17 -0
- package/dist/models/device.models.d.ts +18 -0
- package/dist/models/device.models.js +55 -0
- package/dist/models/devicePaymentPlan.models.d.ts +29 -0
- package/dist/models/devicePaymentPlan.models.js +98 -0
- package/dist/models/eventLog.models.d.ts +18 -0
- package/dist/models/eventLog.models.js +100 -0
- package/dist/models/idempotencyRecord.models.d.ts +14 -0
- package/dist/models/idempotencyRecord.models.js +62 -0
- package/dist/models/index.d.ts +11 -0
- package/dist/models/index.js +26 -0
- package/dist/models/payment.models.d.ts +24 -0
- package/dist/models/payment.models.js +64 -0
- package/dist/models/pricing.models.d.ts +18 -0
- package/dist/models/pricing.models.js +42 -0
- package/dist/models/product.models.d.ts +15 -0
- package/dist/models/product.models.js +35 -0
- package/dist/models/securityClearance.models.d.ts +46 -0
- package/dist/models/securityClearance.models.js +93 -0
- package/dist/models/transaction.models.d.ts +18 -0
- package/dist/models/transaction.models.js +40 -0
- package/dist/models/types.d.ts +10 -0
- package/dist/models/types.js +2 -0
- package/dist/models/user.models.d.ts +35 -0
- package/dist/models/user.models.js +122 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./models";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./models"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Model, InferAttributes, InferCreationAttributes, CreationOptional, NonAttribute } from "vr-migrations";
|
|
2
|
+
import type { Product } from "./product.models";
|
|
3
|
+
import type { DevicePaymentPlan } from "./devicePaymentPlan.models";
|
|
4
|
+
export type DeviceStatus = "locked" | "unlocked" | "disabled";
|
|
5
|
+
export declare class Device extends Model<InferAttributes<Device>, InferCreationAttributes<Device>> {
|
|
6
|
+
id: CreationOptional<string>;
|
|
7
|
+
serialNumber: string;
|
|
8
|
+
productId: string;
|
|
9
|
+
status: CreationOptional<DeviceStatus>;
|
|
10
|
+
isPermanentlyUnlocked: CreationOptional<boolean>;
|
|
11
|
+
activatedAt: CreationOptional<Date | null>;
|
|
12
|
+
readonly createdAt: CreationOptional<Date>;
|
|
13
|
+
readonly updatedAt: CreationOptional<Date>;
|
|
14
|
+
product?: NonAttribute<Product>;
|
|
15
|
+
paymentPlans?: NonAttribute<DevicePaymentPlan[]>;
|
|
16
|
+
}
|
|
17
|
+
export declare const initDeviceModel: (sequelize: any) => void;
|
|
18
|
+
export type DeviceModel = typeof Device;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initDeviceModel = exports.Device = void 0;
|
|
4
|
+
// src/models/device.models.ts
|
|
5
|
+
const vr_migrations_1 = require("vr-migrations");
|
|
6
|
+
class Device extends vr_migrations_1.Model {
|
|
7
|
+
}
|
|
8
|
+
exports.Device = Device;
|
|
9
|
+
const initDeviceModel = (sequelize) => {
|
|
10
|
+
Device.init({
|
|
11
|
+
id: {
|
|
12
|
+
type: vr_migrations_1.DataTypes.UUID,
|
|
13
|
+
defaultValue: vr_migrations_1.DataTypes.UUIDV4,
|
|
14
|
+
primaryKey: true,
|
|
15
|
+
},
|
|
16
|
+
serialNumber: {
|
|
17
|
+
type: vr_migrations_1.DataTypes.STRING(64),
|
|
18
|
+
allowNull: false,
|
|
19
|
+
unique: true,
|
|
20
|
+
},
|
|
21
|
+
productId: {
|
|
22
|
+
type: vr_migrations_1.DataTypes.UUID,
|
|
23
|
+
allowNull: false,
|
|
24
|
+
},
|
|
25
|
+
status: {
|
|
26
|
+
type: vr_migrations_1.DataTypes.ENUM("locked", "unlocked", "disabled"),
|
|
27
|
+
allowNull: false,
|
|
28
|
+
defaultValue: "locked",
|
|
29
|
+
},
|
|
30
|
+
isPermanentlyUnlocked: {
|
|
31
|
+
type: vr_migrations_1.DataTypes.BOOLEAN,
|
|
32
|
+
allowNull: false,
|
|
33
|
+
defaultValue: false,
|
|
34
|
+
},
|
|
35
|
+
activatedAt: {
|
|
36
|
+
type: vr_migrations_1.DataTypes.DATE,
|
|
37
|
+
allowNull: true,
|
|
38
|
+
},
|
|
39
|
+
createdAt: {
|
|
40
|
+
type: vr_migrations_1.DataTypes.DATE,
|
|
41
|
+
defaultValue: vr_migrations_1.DataTypes.NOW,
|
|
42
|
+
},
|
|
43
|
+
updatedAt: {
|
|
44
|
+
type: vr_migrations_1.DataTypes.DATE,
|
|
45
|
+
defaultValue: vr_migrations_1.DataTypes.NOW,
|
|
46
|
+
},
|
|
47
|
+
}, {
|
|
48
|
+
sequelize,
|
|
49
|
+
modelName: "Device",
|
|
50
|
+
tableName: "devices",
|
|
51
|
+
timestamps: true,
|
|
52
|
+
freezeTableName: true,
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
exports.initDeviceModel = initDeviceModel;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Model, InferAttributes, InferCreationAttributes, CreationOptional, NonAttribute } from "vr-migrations";
|
|
2
|
+
import type { Device } from "./device.models";
|
|
3
|
+
import type { User } from "./user.models";
|
|
4
|
+
export type PaymentPlanStatus = "ACTIVE" | "COMPLETED" | "DEFAULTED" | "CANCELLED";
|
|
5
|
+
export type InstallmentFrequency = "daily" | "weekly" | "monthly";
|
|
6
|
+
export declare class DevicePaymentPlan extends Model<InferAttributes<DevicePaymentPlan>, InferCreationAttributes<DevicePaymentPlan>> {
|
|
7
|
+
id: CreationOptional<string>;
|
|
8
|
+
deviceId: string;
|
|
9
|
+
userId: string;
|
|
10
|
+
pricingSnapshot: Record<string, any>;
|
|
11
|
+
totalAmount: number;
|
|
12
|
+
downPayment: number;
|
|
13
|
+
installmentAmount: number;
|
|
14
|
+
installmentFrequency: InstallmentFrequency;
|
|
15
|
+
paidAmount: CreationOptional<number>;
|
|
16
|
+
outstandingAmount: number;
|
|
17
|
+
lastPaymentAt: CreationOptional<Date | null>;
|
|
18
|
+
nextInstallmentDueAt: CreationOptional<Date | null>;
|
|
19
|
+
gracePeriodDays: CreationOptional<number>;
|
|
20
|
+
autoLockOnMiss: CreationOptional<boolean>;
|
|
21
|
+
status: CreationOptional<PaymentPlanStatus>;
|
|
22
|
+
completedAt: CreationOptional<Date | null>;
|
|
23
|
+
readonly createdAt: CreationOptional<Date>;
|
|
24
|
+
readonly updatedAt: CreationOptional<Date>;
|
|
25
|
+
device?: NonAttribute<Device>;
|
|
26
|
+
user?: NonAttribute<User>;
|
|
27
|
+
}
|
|
28
|
+
export declare const initDevicePaymentPlanModel: (sequelize: any) => void;
|
|
29
|
+
export type DevicePaymentPlanModel = typeof DevicePaymentPlan;
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initDevicePaymentPlanModel = exports.DevicePaymentPlan = void 0;
|
|
4
|
+
// src/models/devicePaymentPlan.models.ts
|
|
5
|
+
const vr_migrations_1 = require("vr-migrations");
|
|
6
|
+
class DevicePaymentPlan extends vr_migrations_1.Model {
|
|
7
|
+
}
|
|
8
|
+
exports.DevicePaymentPlan = DevicePaymentPlan;
|
|
9
|
+
const initDevicePaymentPlanModel = (sequelize) => {
|
|
10
|
+
DevicePaymentPlan.init({
|
|
11
|
+
id: {
|
|
12
|
+
type: vr_migrations_1.DataTypes.UUID,
|
|
13
|
+
defaultValue: vr_migrations_1.DataTypes.UUIDV4,
|
|
14
|
+
primaryKey: true,
|
|
15
|
+
},
|
|
16
|
+
deviceId: {
|
|
17
|
+
type: vr_migrations_1.DataTypes.UUID,
|
|
18
|
+
allowNull: false,
|
|
19
|
+
unique: true,
|
|
20
|
+
},
|
|
21
|
+
userId: {
|
|
22
|
+
type: vr_migrations_1.DataTypes.UUID,
|
|
23
|
+
allowNull: false,
|
|
24
|
+
},
|
|
25
|
+
pricingSnapshot: {
|
|
26
|
+
type: vr_migrations_1.DataTypes.JSONB,
|
|
27
|
+
allowNull: false,
|
|
28
|
+
},
|
|
29
|
+
totalAmount: {
|
|
30
|
+
type: vr_migrations_1.DataTypes.FLOAT,
|
|
31
|
+
allowNull: false,
|
|
32
|
+
},
|
|
33
|
+
downPayment: {
|
|
34
|
+
type: vr_migrations_1.DataTypes.FLOAT,
|
|
35
|
+
allowNull: false,
|
|
36
|
+
},
|
|
37
|
+
installmentAmount: {
|
|
38
|
+
type: vr_migrations_1.DataTypes.FLOAT,
|
|
39
|
+
allowNull: false,
|
|
40
|
+
},
|
|
41
|
+
installmentFrequency: {
|
|
42
|
+
type: vr_migrations_1.DataTypes.ENUM("DAILY", "WEEKLY", "MONTHLY"),
|
|
43
|
+
allowNull: false,
|
|
44
|
+
defaultValue: "WEEKLY",
|
|
45
|
+
},
|
|
46
|
+
paidAmount: {
|
|
47
|
+
type: vr_migrations_1.DataTypes.FLOAT,
|
|
48
|
+
allowNull: false,
|
|
49
|
+
defaultValue: 0,
|
|
50
|
+
},
|
|
51
|
+
outstandingAmount: {
|
|
52
|
+
type: vr_migrations_1.DataTypes.FLOAT,
|
|
53
|
+
allowNull: false,
|
|
54
|
+
},
|
|
55
|
+
lastPaymentAt: {
|
|
56
|
+
type: vr_migrations_1.DataTypes.DATE,
|
|
57
|
+
allowNull: true,
|
|
58
|
+
},
|
|
59
|
+
nextInstallmentDueAt: {
|
|
60
|
+
type: vr_migrations_1.DataTypes.DATE,
|
|
61
|
+
allowNull: true,
|
|
62
|
+
},
|
|
63
|
+
gracePeriodDays: {
|
|
64
|
+
type: vr_migrations_1.DataTypes.INTEGER,
|
|
65
|
+
allowNull: false,
|
|
66
|
+
defaultValue: 2,
|
|
67
|
+
},
|
|
68
|
+
autoLockOnMiss: {
|
|
69
|
+
type: vr_migrations_1.DataTypes.BOOLEAN,
|
|
70
|
+
allowNull: false,
|
|
71
|
+
defaultValue: true,
|
|
72
|
+
},
|
|
73
|
+
status: {
|
|
74
|
+
type: vr_migrations_1.DataTypes.ENUM("ACTIVE", "COMPLETED", "DEFAULTED", "CANCELLED"),
|
|
75
|
+
allowNull: false,
|
|
76
|
+
defaultValue: "ACTIVE",
|
|
77
|
+
},
|
|
78
|
+
completedAt: {
|
|
79
|
+
type: vr_migrations_1.DataTypes.DATE,
|
|
80
|
+
allowNull: true,
|
|
81
|
+
},
|
|
82
|
+
createdAt: {
|
|
83
|
+
type: vr_migrations_1.DataTypes.DATE,
|
|
84
|
+
defaultValue: vr_migrations_1.DataTypes.NOW,
|
|
85
|
+
},
|
|
86
|
+
updatedAt: {
|
|
87
|
+
type: vr_migrations_1.DataTypes.DATE,
|
|
88
|
+
defaultValue: vr_migrations_1.DataTypes.NOW,
|
|
89
|
+
},
|
|
90
|
+
}, {
|
|
91
|
+
sequelize,
|
|
92
|
+
modelName: "DevicePaymentPlan",
|
|
93
|
+
tableName: "device_payment_plans",
|
|
94
|
+
timestamps: true,
|
|
95
|
+
freezeTableName: true,
|
|
96
|
+
});
|
|
97
|
+
};
|
|
98
|
+
exports.initDevicePaymentPlanModel = initDevicePaymentPlanModel;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Model, InferAttributes, InferCreationAttributes, CreationOptional } from "vr-migrations";
|
|
2
|
+
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 type EventAction = (typeof EVENT_ACTIONS)[number];
|
|
4
|
+
export type EventActorType = "USER" | "SYSTEM";
|
|
5
|
+
export declare class EventLog extends Model<InferAttributes<EventLog>, InferCreationAttributes<EventLog>> {
|
|
6
|
+
id: CreationOptional<string>;
|
|
7
|
+
actorType?: EventActorType;
|
|
8
|
+
actorId: CreationOptional<string | null>;
|
|
9
|
+
action: EventAction;
|
|
10
|
+
entity: string;
|
|
11
|
+
entityId?: CreationOptional<string | null>;
|
|
12
|
+
metadata?: CreationOptional<Record<string, any>>;
|
|
13
|
+
ipAddress?: CreationOptional<string | null>;
|
|
14
|
+
userAgent?: CreationOptional<string | null>;
|
|
15
|
+
readonly createdAt: CreationOptional<Date>;
|
|
16
|
+
static initialize(sequelize: any): void;
|
|
17
|
+
}
|
|
18
|
+
export type EventLogModel = typeof EventLog;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EventLog = exports.EVENT_ACTIONS = void 0;
|
|
4
|
+
const vr_migrations_1 = require("vr-migrations");
|
|
5
|
+
exports.EVENT_ACTIONS = [
|
|
6
|
+
"USER_READ",
|
|
7
|
+
"USER_UPDATED",
|
|
8
|
+
"USERS_LISTED",
|
|
9
|
+
"ADMIN_FORGOT_PASSWORD",
|
|
10
|
+
"ADMIN_LOGGED_IN",
|
|
11
|
+
"ADMIN_LOGGED_OUT",
|
|
12
|
+
"PASSENGER_ACCOUNT_DEACTIVATED",
|
|
13
|
+
"PASSENGER_ACCOUNT_DELETED",
|
|
14
|
+
"AGENT_CREATED_RIDER",
|
|
15
|
+
"AGENT_UPDATED_RIDER",
|
|
16
|
+
"ADMIN_CREATED_USER",
|
|
17
|
+
"ADMIN_UPDATED_USER",
|
|
18
|
+
"SUPER_ADMIN_PASSWORD_CHANGED",
|
|
19
|
+
"SUPER_ADMIN_CHANGED_USER_ACCOUNT_STATUS",
|
|
20
|
+
"SUPER_ADMIN_UPDATED_USER",
|
|
21
|
+
"SUPER_ADMIN_CREATED_USER",
|
|
22
|
+
"PRODUCT_CREATED",
|
|
23
|
+
"PRODUCT_READ",
|
|
24
|
+
"PRODUCT_UPDATED",
|
|
25
|
+
"PRODUCT_DELETED",
|
|
26
|
+
"PRODUCTS_LISTED",
|
|
27
|
+
"DEVICE_ASSIGNED",
|
|
28
|
+
"DEVICE_READ",
|
|
29
|
+
"DEVICE_UPDATED",
|
|
30
|
+
"DEVICES_LISTED",
|
|
31
|
+
"DEVICE_REPOSSESSED",
|
|
32
|
+
"DEVICE_PAYMENT_PLAN_CREATED",
|
|
33
|
+
"DEVICE_PAYMENT_PLAN_READ",
|
|
34
|
+
"DEVICE_PAYMENT_PLAN_UPDATED",
|
|
35
|
+
"DEVICE_PAYMENT_DEFAULT_MARKED",
|
|
36
|
+
"PAYMENT_CREATED",
|
|
37
|
+
"PAYMENT_READ",
|
|
38
|
+
"PAYMENTS_LISTED",
|
|
39
|
+
"TRANSACTION_READ",
|
|
40
|
+
"TRANSACTIONS_LISTED",
|
|
41
|
+
"EVENT_LOG_READ",
|
|
42
|
+
"EVENT_LOGS_LISTED",
|
|
43
|
+
"SECURITY_CLEARANCE_MANAGED",
|
|
44
|
+
"DEVICE_LOCK_OVERRIDDEN",
|
|
45
|
+
];
|
|
46
|
+
class EventLog extends vr_migrations_1.Model {
|
|
47
|
+
static initialize(sequelize) {
|
|
48
|
+
this.init({
|
|
49
|
+
id: {
|
|
50
|
+
type: vr_migrations_1.DataTypes.UUID,
|
|
51
|
+
defaultValue: vr_migrations_1.DataTypes.UUIDV4,
|
|
52
|
+
primaryKey: true,
|
|
53
|
+
},
|
|
54
|
+
actorType: {
|
|
55
|
+
type: vr_migrations_1.DataTypes.ENUM("USER", "SYSTEM"),
|
|
56
|
+
allowNull: false,
|
|
57
|
+
},
|
|
58
|
+
actorId: {
|
|
59
|
+
type: vr_migrations_1.DataTypes.UUID,
|
|
60
|
+
allowNull: true,
|
|
61
|
+
},
|
|
62
|
+
action: {
|
|
63
|
+
type: vr_migrations_1.DataTypes.STRING(100),
|
|
64
|
+
allowNull: false,
|
|
65
|
+
},
|
|
66
|
+
entity: {
|
|
67
|
+
type: vr_migrations_1.DataTypes.STRING(100),
|
|
68
|
+
allowNull: false,
|
|
69
|
+
},
|
|
70
|
+
entityId: {
|
|
71
|
+
type: vr_migrations_1.DataTypes.UUID,
|
|
72
|
+
allowNull: true,
|
|
73
|
+
},
|
|
74
|
+
metadata: {
|
|
75
|
+
type: vr_migrations_1.DataTypes.JSONB,
|
|
76
|
+
allowNull: false,
|
|
77
|
+
defaultValue: {},
|
|
78
|
+
},
|
|
79
|
+
ipAddress: {
|
|
80
|
+
type: vr_migrations_1.DataTypes.STRING(45),
|
|
81
|
+
allowNull: true,
|
|
82
|
+
},
|
|
83
|
+
userAgent: {
|
|
84
|
+
type: vr_migrations_1.DataTypes.TEXT,
|
|
85
|
+
allowNull: true,
|
|
86
|
+
},
|
|
87
|
+
createdAt: {
|
|
88
|
+
type: vr_migrations_1.DataTypes.DATE,
|
|
89
|
+
defaultValue: vr_migrations_1.DataTypes.NOW,
|
|
90
|
+
},
|
|
91
|
+
}, {
|
|
92
|
+
sequelize,
|
|
93
|
+
tableName: "event_logs",
|
|
94
|
+
modelName: "EventLog",
|
|
95
|
+
timestamps: true,
|
|
96
|
+
updatedAt: false,
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
exports.EventLog = EventLog;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Model, InferAttributes, InferCreationAttributes, CreationOptional } from "vr-migrations";
|
|
2
|
+
export declare class IdempotencyRecord extends Model<InferAttributes<IdempotencyRecord>, InferCreationAttributes<IdempotencyRecord>> {
|
|
3
|
+
id: CreationOptional<string>;
|
|
4
|
+
key: string;
|
|
5
|
+
requestMethod: string;
|
|
6
|
+
requestPath: string;
|
|
7
|
+
requestParams: CreationOptional<Record<string, any> | null>;
|
|
8
|
+
responseStatusCode: CreationOptional<number | null>;
|
|
9
|
+
responseBody: CreationOptional<Record<string, any>>;
|
|
10
|
+
readonly createdAt: CreationOptional<Date>;
|
|
11
|
+
expiresAt: Date;
|
|
12
|
+
static initialize(sequelize: any): void;
|
|
13
|
+
}
|
|
14
|
+
export type IdempotencyRecordModel = typeof IdempotencyRecord;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IdempotencyRecord = void 0;
|
|
4
|
+
const vr_migrations_1 = require("vr-migrations");
|
|
5
|
+
class IdempotencyRecord 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
|
+
},
|
|
13
|
+
key: {
|
|
14
|
+
type: vr_migrations_1.DataTypes.STRING(128),
|
|
15
|
+
allowNull: false,
|
|
16
|
+
unique: true,
|
|
17
|
+
},
|
|
18
|
+
requestMethod: {
|
|
19
|
+
type: vr_migrations_1.DataTypes.STRING(10),
|
|
20
|
+
allowNull: false,
|
|
21
|
+
},
|
|
22
|
+
requestPath: {
|
|
23
|
+
type: vr_migrations_1.DataTypes.STRING(255),
|
|
24
|
+
allowNull: false,
|
|
25
|
+
},
|
|
26
|
+
requestParams: {
|
|
27
|
+
type: vr_migrations_1.DataTypes.JSONB,
|
|
28
|
+
allowNull: true,
|
|
29
|
+
},
|
|
30
|
+
responseStatusCode: {
|
|
31
|
+
type: vr_migrations_1.DataTypes.INTEGER,
|
|
32
|
+
allowNull: true,
|
|
33
|
+
},
|
|
34
|
+
responseBody: {
|
|
35
|
+
type: vr_migrations_1.DataTypes.JSONB,
|
|
36
|
+
allowNull: true,
|
|
37
|
+
},
|
|
38
|
+
createdAt: {
|
|
39
|
+
type: vr_migrations_1.DataTypes.DATE,
|
|
40
|
+
defaultValue: vr_migrations_1.DataTypes.NOW,
|
|
41
|
+
},
|
|
42
|
+
expiresAt: {
|
|
43
|
+
type: vr_migrations_1.DataTypes.DATE,
|
|
44
|
+
allowNull: false,
|
|
45
|
+
},
|
|
46
|
+
}, {
|
|
47
|
+
sequelize,
|
|
48
|
+
tableName: "idempotency_records",
|
|
49
|
+
modelName: "IdempotencyRecord",
|
|
50
|
+
timestamps: true,
|
|
51
|
+
updatedAt: false,
|
|
52
|
+
hooks: {
|
|
53
|
+
beforeCreate(record) {
|
|
54
|
+
const expiresAt = new Date();
|
|
55
|
+
expiresAt.setHours(expiresAt.getHours() + 24);
|
|
56
|
+
record.expiresAt = expiresAt;
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.IdempotencyRecord = IdempotencyRecord;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export * from "./user.models";
|
|
2
|
+
export * from "./device.models";
|
|
3
|
+
export * from "./devicePaymentPlan.models";
|
|
4
|
+
export * from "./eventLog.models";
|
|
5
|
+
export * from "./idempotencyRecord.models";
|
|
6
|
+
export * from "./payment.models";
|
|
7
|
+
export * from "./pricing.models";
|
|
8
|
+
export * from "./product.models";
|
|
9
|
+
export * from "./securityClearance.models";
|
|
10
|
+
export * from "./transaction.models";
|
|
11
|
+
export type { UserModel, TransactionModel, SecurityClearanceModel, ProductModel, PricingModel, PaymentModel, IdempotencyRecordModel, EventLogModel, DevicePaymentPlanModel, DeviceModel, } from "./types";
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./user.models"), exports);
|
|
18
|
+
__exportStar(require("./device.models"), exports);
|
|
19
|
+
__exportStar(require("./devicePaymentPlan.models"), exports);
|
|
20
|
+
__exportStar(require("./eventLog.models"), exports);
|
|
21
|
+
__exportStar(require("./idempotencyRecord.models"), exports);
|
|
22
|
+
__exportStar(require("./payment.models"), exports);
|
|
23
|
+
__exportStar(require("./pricing.models"), exports);
|
|
24
|
+
__exportStar(require("./product.models"), exports);
|
|
25
|
+
__exportStar(require("./securityClearance.models"), exports);
|
|
26
|
+
__exportStar(require("./transaction.models"), exports);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Model, InferAttributes, InferCreationAttributes, CreationOptional, NonAttribute, ModelStatic } from "vr-migrations";
|
|
2
|
+
export type PaymentProvider = "mtn_momo" | "airtel_money";
|
|
3
|
+
export type PaymentStatus = "pending" | "succeeded" | "failed";
|
|
4
|
+
export declare class Payment extends Model<InferAttributes<Payment>, InferCreationAttributes<Payment>> {
|
|
5
|
+
id: CreationOptional<string>;
|
|
6
|
+
userId: string;
|
|
7
|
+
devicePaymentPlanId: string;
|
|
8
|
+
transactionId: CreationOptional<string | null>;
|
|
9
|
+
idempotencyKeyId: CreationOptional<string | null>;
|
|
10
|
+
amount: number;
|
|
11
|
+
provider: PaymentProvider;
|
|
12
|
+
providerReference: CreationOptional<string | null>;
|
|
13
|
+
status: PaymentStatus;
|
|
14
|
+
metadata: Record<string, any>;
|
|
15
|
+
readonly createdAt: CreationOptional<Date>;
|
|
16
|
+
readonly updatedAt: CreationOptional<Date>;
|
|
17
|
+
user?: NonAttribute<any>;
|
|
18
|
+
devicePaymentPlan?: NonAttribute<any>;
|
|
19
|
+
transaction?: NonAttribute<any>;
|
|
20
|
+
idempotencyKey?: NonAttribute<any>;
|
|
21
|
+
static initialize(sequelize: any): void;
|
|
22
|
+
static associate(models: Record<string, ModelStatic<Model>>): void;
|
|
23
|
+
}
|
|
24
|
+
export type PaymentModel = typeof Payment;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Payment = void 0;
|
|
4
|
+
const vr_migrations_1 = require("vr-migrations");
|
|
5
|
+
class Payment 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
|
+
},
|
|
13
|
+
userId: { type: vr_migrations_1.DataTypes.UUID, allowNull: false },
|
|
14
|
+
devicePaymentPlanId: { type: vr_migrations_1.DataTypes.UUID, allowNull: false },
|
|
15
|
+
transactionId: { type: vr_migrations_1.DataTypes.UUID, allowNull: true },
|
|
16
|
+
idempotencyKeyId: { type: vr_migrations_1.DataTypes.UUID, allowNull: true },
|
|
17
|
+
amount: {
|
|
18
|
+
type: vr_migrations_1.DataTypes.FLOAT,
|
|
19
|
+
allowNull: false,
|
|
20
|
+
validate: { min: 1 },
|
|
21
|
+
},
|
|
22
|
+
provider: {
|
|
23
|
+
type: vr_migrations_1.DataTypes.ENUM("mtn_momo", "airtel_money"),
|
|
24
|
+
allowNull: false,
|
|
25
|
+
},
|
|
26
|
+
providerReference: { type: vr_migrations_1.DataTypes.STRING, allowNull: true },
|
|
27
|
+
status: {
|
|
28
|
+
type: vr_migrations_1.DataTypes.ENUM("pending", "succeeded", "failed"),
|
|
29
|
+
allowNull: false,
|
|
30
|
+
defaultValue: "pending",
|
|
31
|
+
},
|
|
32
|
+
metadata: { type: vr_migrations_1.DataTypes.JSONB, allowNull: false, defaultValue: {} },
|
|
33
|
+
createdAt: { type: vr_migrations_1.DataTypes.DATE, defaultValue: vr_migrations_1.DataTypes.NOW },
|
|
34
|
+
updatedAt: { type: vr_migrations_1.DataTypes.DATE, defaultValue: vr_migrations_1.DataTypes.NOW },
|
|
35
|
+
}, {
|
|
36
|
+
sequelize,
|
|
37
|
+
tableName: "payments",
|
|
38
|
+
modelName: "Payment",
|
|
39
|
+
hooks: {
|
|
40
|
+
beforeUpdate: (payment) => {
|
|
41
|
+
if (payment.status === "succeeded" && !payment.providerReference) {
|
|
42
|
+
throw new Error("providerReference is required for successful payments");
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
static associate(models) {
|
|
49
|
+
this.belongsTo(models.User, { foreignKey: "userId", as: "user" });
|
|
50
|
+
this.belongsTo(models.DevicePaymentPlan, {
|
|
51
|
+
foreignKey: "devicePaymentPlanId",
|
|
52
|
+
as: "devicePaymentPlan",
|
|
53
|
+
});
|
|
54
|
+
this.belongsTo(models.Transaction, {
|
|
55
|
+
foreignKey: "transactionId",
|
|
56
|
+
as: "transaction",
|
|
57
|
+
});
|
|
58
|
+
this.belongsTo(models.IdempotencyRecord, {
|
|
59
|
+
foreignKey: "idempotencyKeyId",
|
|
60
|
+
as: "idempotencyKey",
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
exports.Payment = Payment;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Model, InferAttributes, InferCreationAttributes, CreationOptional, NonAttribute, ModelStatic } from "vr-migrations";
|
|
2
|
+
export declare class Pricing extends Model<InferAttributes<Pricing>, InferCreationAttributes<Pricing>> {
|
|
3
|
+
id: CreationOptional<string>;
|
|
4
|
+
productId: string;
|
|
5
|
+
name: string;
|
|
6
|
+
upfrontPrice: number;
|
|
7
|
+
downPayment: number;
|
|
8
|
+
installmentAmount?: number;
|
|
9
|
+
installmentIntervalDays?: number;
|
|
10
|
+
totalAmount: number;
|
|
11
|
+
isActive: CreationOptional<boolean>;
|
|
12
|
+
readonly createdAt: CreationOptional<Date>;
|
|
13
|
+
readonly updatedAt: CreationOptional<Date>;
|
|
14
|
+
product?: NonAttribute<any>;
|
|
15
|
+
static initialize(sequelize: any): void;
|
|
16
|
+
static associate(models: Record<string, ModelStatic<Model>>): void;
|
|
17
|
+
}
|
|
18
|
+
export type PricingModel = typeof Pricing;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Pricing = void 0;
|
|
4
|
+
const vr_migrations_1 = require("vr-migrations");
|
|
5
|
+
class Pricing 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
|
+
},
|
|
13
|
+
productId: { type: vr_migrations_1.DataTypes.UUID, allowNull: false },
|
|
14
|
+
name: { type: vr_migrations_1.DataTypes.STRING(100), allowNull: false },
|
|
15
|
+
upfrontPrice: { type: vr_migrations_1.DataTypes.DECIMAL(10, 2), allowNull: false },
|
|
16
|
+
downPayment: {
|
|
17
|
+
type: vr_migrations_1.DataTypes.DECIMAL(10, 2),
|
|
18
|
+
allowNull: false,
|
|
19
|
+
defaultValue: 0,
|
|
20
|
+
},
|
|
21
|
+
installmentAmount: { type: vr_migrations_1.DataTypes.DECIMAL(10, 2), allowNull: true },
|
|
22
|
+
installmentIntervalDays: { type: vr_migrations_1.DataTypes.INTEGER, allowNull: true },
|
|
23
|
+
totalAmount: { type: vr_migrations_1.DataTypes.DECIMAL(10, 2), allowNull: false },
|
|
24
|
+
isActive: {
|
|
25
|
+
type: vr_migrations_1.DataTypes.BOOLEAN,
|
|
26
|
+
allowNull: false,
|
|
27
|
+
defaultValue: true,
|
|
28
|
+
},
|
|
29
|
+
createdAt: { type: vr_migrations_1.DataTypes.DATE, defaultValue: vr_migrations_1.DataTypes.NOW },
|
|
30
|
+
updatedAt: { type: vr_migrations_1.DataTypes.DATE, defaultValue: vr_migrations_1.DataTypes.NOW },
|
|
31
|
+
}, {
|
|
32
|
+
sequelize,
|
|
33
|
+
tableName: "pricings",
|
|
34
|
+
modelName: "Pricing",
|
|
35
|
+
timestamps: true,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
static associate(models) {
|
|
39
|
+
this.belongsTo(models.Product, { foreignKey: "productId", as: "product" });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
exports.Pricing = Pricing;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Model, InferAttributes, InferCreationAttributes, CreationOptional, NonAttribute, ModelStatic } from "vr-migrations";
|
|
2
|
+
export declare class Product extends Model<InferAttributes<Product>, InferCreationAttributes<Product>> {
|
|
3
|
+
id: CreationOptional<string>;
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
stock: CreationOptional<number>;
|
|
7
|
+
isActive: CreationOptional<boolean>;
|
|
8
|
+
readonly createdAt: CreationOptional<Date>;
|
|
9
|
+
readonly updatedAt: CreationOptional<Date>;
|
|
10
|
+
pricings?: NonAttribute<any[]>;
|
|
11
|
+
devices?: NonAttribute<any[]>;
|
|
12
|
+
static initialize(sequelize: any): void;
|
|
13
|
+
static associate(models: Record<string, ModelStatic<Model>>): void;
|
|
14
|
+
}
|
|
15
|
+
export type ProductModel = typeof Product;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Product = void 0;
|
|
4
|
+
const vr_migrations_1 = require("vr-migrations");
|
|
5
|
+
class Product 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
|
+
},
|
|
13
|
+
name: { type: vr_migrations_1.DataTypes.STRING(150), allowNull: false },
|
|
14
|
+
description: { type: vr_migrations_1.DataTypes.TEXT, allowNull: true },
|
|
15
|
+
stock: { type: vr_migrations_1.DataTypes.INTEGER, allowNull: false, defaultValue: 0 },
|
|
16
|
+
isActive: {
|
|
17
|
+
type: vr_migrations_1.DataTypes.BOOLEAN,
|
|
18
|
+
allowNull: false,
|
|
19
|
+
defaultValue: true,
|
|
20
|
+
},
|
|
21
|
+
createdAt: { type: vr_migrations_1.DataTypes.DATE, defaultValue: vr_migrations_1.DataTypes.NOW },
|
|
22
|
+
updatedAt: { type: vr_migrations_1.DataTypes.DATE, defaultValue: vr_migrations_1.DataTypes.NOW },
|
|
23
|
+
}, {
|
|
24
|
+
sequelize,
|
|
25
|
+
tableName: "products",
|
|
26
|
+
modelName: "Product",
|
|
27
|
+
timestamps: true,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
static associate(models) {
|
|
31
|
+
this.hasMany(models.Pricing, { foreignKey: "productId", as: "pricings" });
|
|
32
|
+
this.hasMany(models.Device, { foreignKey: "productId", as: "devices" });
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.Product = Product;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Model, InferAttributes, InferCreationAttributes, CreationOptional, NonAttribute } from "vr-migrations";
|
|
2
|
+
import type { User } from "./user.models";
|
|
3
|
+
export declare const USER_ROLES: readonly ["RIDER", "PASSENGER", "ADMIN", "AGENT", "SUPER_ADMIN"];
|
|
4
|
+
export type UserRole = (typeof USER_ROLES)[number];
|
|
5
|
+
export declare enum Permission {
|
|
6
|
+
READ_USER = "READ_USER",
|
|
7
|
+
UPDATE_USER = "UPDATE_USER",
|
|
8
|
+
LIST_USERS = "LIST_USERS",
|
|
9
|
+
CREATE_PRODUCT = "CREATE_PRODUCT",
|
|
10
|
+
READ_PRODUCT = "READ_PRODUCT",
|
|
11
|
+
UPDATE_PRODUCT = "UPDATE_PRODUCT",
|
|
12
|
+
DELETE_PRODUCT = "DELETE_PRODUCT",
|
|
13
|
+
LIST_PRODUCTS = "LIST_PRODUCTS",
|
|
14
|
+
ASSIGN_DEVICE = "ASSIGN_DEVICE",
|
|
15
|
+
READ_DEVICE = "READ_DEVICE",
|
|
16
|
+
UPDATE_DEVICE = "UPDATE_DEVICE",
|
|
17
|
+
LIST_DEVICES = "LIST_DEVICES",
|
|
18
|
+
REPOSSESS_DEVICE = "REPOSSESS_DEVICE",
|
|
19
|
+
CREATE_DEVICE_PAYMENT_PLAN = "CREATE_DEVICE_PAYMENT_PLAN",
|
|
20
|
+
READ_DEVICE_PAYMENT_PLAN = "READ_DEVICE_PAYMENT_PLAN",
|
|
21
|
+
UPDATE_DEVICE_PAYMENT_PLAN = "UPDATE_DEVICE_PAYMENT_PLAN",
|
|
22
|
+
MARK_PAYMENT_DEFAULT = "MARK_PAYMENT_DEFAULT",
|
|
23
|
+
CREATE_PAYMENT = "CREATE_PAYMENT",
|
|
24
|
+
READ_PAYMENT = "READ_PAYMENT",
|
|
25
|
+
LIST_PAYMENTS = "LIST_PAYMENTS",
|
|
26
|
+
READ_TRANSACTION = "READ_TRANSACTION",
|
|
27
|
+
LIST_TRANSACTIONS = "LIST_TRANSACTIONS",
|
|
28
|
+
READ_EVENT_LOG = "READ_EVENT_LOG",
|
|
29
|
+
LIST_EVENT_LOGS = "LIST_EVENT_LOGS",
|
|
30
|
+
MANAGE_SECURITY_CLEARANCE = "MANAGE_SECURITY_CLEARANCE",
|
|
31
|
+
OVERRIDE_DEVICE_LOCK = "OVERRIDE_DEVICE_LOCK"
|
|
32
|
+
}
|
|
33
|
+
export declare class SecurityClearance extends Model<InferAttributes<SecurityClearance>, InferCreationAttributes<SecurityClearance>> {
|
|
34
|
+
id: CreationOptional<string>;
|
|
35
|
+
role: UserRole;
|
|
36
|
+
description: CreationOptional<string | null>;
|
|
37
|
+
level: number;
|
|
38
|
+
permissions: Permission[];
|
|
39
|
+
isDefault: boolean;
|
|
40
|
+
createdAt: CreationOptional<Date>;
|
|
41
|
+
updatedAt: CreationOptional<Date>;
|
|
42
|
+
users?: NonAttribute<User[]>;
|
|
43
|
+
hasPermission(permission: Permission): boolean;
|
|
44
|
+
}
|
|
45
|
+
export declare const initSecurityClearanceModel: (sequelize: any) => void;
|
|
46
|
+
export type SecurityClearanceModel = typeof SecurityClearance;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initSecurityClearanceModel = exports.SecurityClearance = exports.Permission = exports.USER_ROLES = void 0;
|
|
4
|
+
// src/models/securityClearance.models.ts
|
|
5
|
+
const vr_migrations_1 = require("vr-migrations");
|
|
6
|
+
exports.USER_ROLES = [
|
|
7
|
+
"RIDER",
|
|
8
|
+
"PASSENGER",
|
|
9
|
+
"ADMIN",
|
|
10
|
+
"AGENT",
|
|
11
|
+
"SUPER_ADMIN",
|
|
12
|
+
];
|
|
13
|
+
var Permission;
|
|
14
|
+
(function (Permission) {
|
|
15
|
+
Permission["READ_USER"] = "READ_USER";
|
|
16
|
+
Permission["UPDATE_USER"] = "UPDATE_USER";
|
|
17
|
+
Permission["LIST_USERS"] = "LIST_USERS";
|
|
18
|
+
Permission["CREATE_PRODUCT"] = "CREATE_PRODUCT";
|
|
19
|
+
Permission["READ_PRODUCT"] = "READ_PRODUCT";
|
|
20
|
+
Permission["UPDATE_PRODUCT"] = "UPDATE_PRODUCT";
|
|
21
|
+
Permission["DELETE_PRODUCT"] = "DELETE_PRODUCT";
|
|
22
|
+
Permission["LIST_PRODUCTS"] = "LIST_PRODUCTS";
|
|
23
|
+
Permission["ASSIGN_DEVICE"] = "ASSIGN_DEVICE";
|
|
24
|
+
Permission["READ_DEVICE"] = "READ_DEVICE";
|
|
25
|
+
Permission["UPDATE_DEVICE"] = "UPDATE_DEVICE";
|
|
26
|
+
Permission["LIST_DEVICES"] = "LIST_DEVICES";
|
|
27
|
+
Permission["REPOSSESS_DEVICE"] = "REPOSSESS_DEVICE";
|
|
28
|
+
Permission["CREATE_DEVICE_PAYMENT_PLAN"] = "CREATE_DEVICE_PAYMENT_PLAN";
|
|
29
|
+
Permission["READ_DEVICE_PAYMENT_PLAN"] = "READ_DEVICE_PAYMENT_PLAN";
|
|
30
|
+
Permission["UPDATE_DEVICE_PAYMENT_PLAN"] = "UPDATE_DEVICE_PAYMENT_PLAN";
|
|
31
|
+
Permission["MARK_PAYMENT_DEFAULT"] = "MARK_PAYMENT_DEFAULT";
|
|
32
|
+
Permission["CREATE_PAYMENT"] = "CREATE_PAYMENT";
|
|
33
|
+
Permission["READ_PAYMENT"] = "READ_PAYMENT";
|
|
34
|
+
Permission["LIST_PAYMENTS"] = "LIST_PAYMENTS";
|
|
35
|
+
Permission["READ_TRANSACTION"] = "READ_TRANSACTION";
|
|
36
|
+
Permission["LIST_TRANSACTIONS"] = "LIST_TRANSACTIONS";
|
|
37
|
+
Permission["READ_EVENT_LOG"] = "READ_EVENT_LOG";
|
|
38
|
+
Permission["LIST_EVENT_LOGS"] = "LIST_EVENT_LOGS";
|
|
39
|
+
Permission["MANAGE_SECURITY_CLEARANCE"] = "MANAGE_SECURITY_CLEARANCE";
|
|
40
|
+
Permission["OVERRIDE_DEVICE_LOCK"] = "OVERRIDE_DEVICE_LOCK";
|
|
41
|
+
})(Permission || (exports.Permission = Permission = {}));
|
|
42
|
+
class SecurityClearance extends vr_migrations_1.Model {
|
|
43
|
+
hasPermission(permission) {
|
|
44
|
+
return this.permissions.includes(permission);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.SecurityClearance = SecurityClearance;
|
|
48
|
+
const initSecurityClearanceModel = (sequelize) => {
|
|
49
|
+
SecurityClearance.init({
|
|
50
|
+
id: {
|
|
51
|
+
type: vr_migrations_1.DataTypes.UUID,
|
|
52
|
+
defaultValue: vr_migrations_1.DataTypes.UUIDV4,
|
|
53
|
+
primaryKey: true,
|
|
54
|
+
},
|
|
55
|
+
role: {
|
|
56
|
+
type: vr_migrations_1.DataTypes.ENUM(...exports.USER_ROLES),
|
|
57
|
+
allowNull: false,
|
|
58
|
+
unique: true,
|
|
59
|
+
},
|
|
60
|
+
description: {
|
|
61
|
+
type: vr_migrations_1.DataTypes.TEXT,
|
|
62
|
+
allowNull: true,
|
|
63
|
+
},
|
|
64
|
+
level: {
|
|
65
|
+
type: vr_migrations_1.DataTypes.INTEGER,
|
|
66
|
+
allowNull: false,
|
|
67
|
+
},
|
|
68
|
+
permissions: {
|
|
69
|
+
type: vr_migrations_1.DataTypes.ARRAY(vr_migrations_1.DataTypes.STRING),
|
|
70
|
+
allowNull: false,
|
|
71
|
+
defaultValue: [],
|
|
72
|
+
},
|
|
73
|
+
isDefault: {
|
|
74
|
+
type: vr_migrations_1.DataTypes.BOOLEAN,
|
|
75
|
+
defaultValue: false,
|
|
76
|
+
},
|
|
77
|
+
createdAt: {
|
|
78
|
+
type: vr_migrations_1.DataTypes.DATE,
|
|
79
|
+
defaultValue: vr_migrations_1.DataTypes.NOW,
|
|
80
|
+
},
|
|
81
|
+
updatedAt: {
|
|
82
|
+
type: vr_migrations_1.DataTypes.DATE,
|
|
83
|
+
defaultValue: vr_migrations_1.DataTypes.NOW,
|
|
84
|
+
},
|
|
85
|
+
}, {
|
|
86
|
+
sequelize,
|
|
87
|
+
modelName: "SecurityClearance",
|
|
88
|
+
tableName: "security_clearances",
|
|
89
|
+
timestamps: true,
|
|
90
|
+
freezeTableName: true,
|
|
91
|
+
});
|
|
92
|
+
};
|
|
93
|
+
exports.initSecurityClearanceModel = initSecurityClearanceModel;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Model, InferAttributes, InferCreationAttributes, CreationOptional, NonAttribute, ModelStatic } from "vr-migrations";
|
|
2
|
+
export type TransactionStatus = "succeeded" | "failed";
|
|
3
|
+
export declare class Transaction extends Model<InferAttributes<Transaction>, InferCreationAttributes<Transaction>> {
|
|
4
|
+
id: CreationOptional<string>;
|
|
5
|
+
userId: string;
|
|
6
|
+
paymentId: string;
|
|
7
|
+
amount: number;
|
|
8
|
+
status: TransactionStatus;
|
|
9
|
+
providerReference: string;
|
|
10
|
+
metadata: Record<string, any>;
|
|
11
|
+
readonly createdAt: CreationOptional<Date>;
|
|
12
|
+
readonly updatedAt: CreationOptional<Date>;
|
|
13
|
+
payment?: NonAttribute<any>;
|
|
14
|
+
user?: NonAttribute<any>;
|
|
15
|
+
static initialize(sequelize: any): void;
|
|
16
|
+
static associate(models: Record<string, ModelStatic<Model>>): void;
|
|
17
|
+
}
|
|
18
|
+
export type TransactionModel = typeof Transaction;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Transaction = void 0;
|
|
4
|
+
const vr_migrations_1 = require("vr-migrations");
|
|
5
|
+
class Transaction 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
|
+
},
|
|
13
|
+
userId: { type: vr_migrations_1.DataTypes.UUID, allowNull: false },
|
|
14
|
+
paymentId: { type: vr_migrations_1.DataTypes.UUID, allowNull: false },
|
|
15
|
+
amount: {
|
|
16
|
+
type: vr_migrations_1.DataTypes.FLOAT,
|
|
17
|
+
allowNull: false,
|
|
18
|
+
validate: { min: 1 },
|
|
19
|
+
},
|
|
20
|
+
status: {
|
|
21
|
+
type: vr_migrations_1.DataTypes.ENUM("succeeded", "failed"),
|
|
22
|
+
allowNull: false,
|
|
23
|
+
},
|
|
24
|
+
providerReference: { type: vr_migrations_1.DataTypes.STRING, allowNull: false },
|
|
25
|
+
metadata: { type: vr_migrations_1.DataTypes.JSONB, allowNull: false, defaultValue: {} },
|
|
26
|
+
createdAt: { type: vr_migrations_1.DataTypes.DATE, defaultValue: vr_migrations_1.DataTypes.NOW },
|
|
27
|
+
updatedAt: { type: vr_migrations_1.DataTypes.DATE, defaultValue: vr_migrations_1.DataTypes.NOW },
|
|
28
|
+
}, {
|
|
29
|
+
sequelize,
|
|
30
|
+
tableName: "transactions",
|
|
31
|
+
modelName: "Transaction",
|
|
32
|
+
timestamps: true,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
static associate(models) {
|
|
36
|
+
this.belongsTo(models.Payment, { foreignKey: "paymentId", as: "payment" });
|
|
37
|
+
this.belongsTo(models.User, { foreignKey: "userId", as: "user" });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.Transaction = Transaction;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type { UserModel } from "./user.models";
|
|
2
|
+
export type { TransactionModel } from "./transaction.models";
|
|
3
|
+
export type { SecurityClearanceModel } from "./securityClearance.models";
|
|
4
|
+
export type { ProductModel } from "./product.models";
|
|
5
|
+
export type { PricingModel } from "./pricing.models";
|
|
6
|
+
export type { PaymentModel } from "./payment.models";
|
|
7
|
+
export type { IdempotencyRecordModel } from "./idempotencyRecord.models";
|
|
8
|
+
export type { EventLogModel } from "./eventLog.models";
|
|
9
|
+
export type { DevicePaymentPlanModel } from "./devicePaymentPlan.models";
|
|
10
|
+
export type { DeviceModel } from "./device.models";
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Model, InferAttributes, InferCreationAttributes, CreationOptional, NonAttribute } from "vr-migrations";
|
|
2
|
+
import type { Device } from "./device.models";
|
|
3
|
+
import type { Payment } from "./payment.models";
|
|
4
|
+
import type { SecurityClearance } from "./securityClearance.models";
|
|
5
|
+
export declare class User extends Model<InferAttributes<User>, InferCreationAttributes<User>> {
|
|
6
|
+
id: CreationOptional<string>;
|
|
7
|
+
firstName: string;
|
|
8
|
+
lastName: string;
|
|
9
|
+
phoneNumber: string;
|
|
10
|
+
jacketId: string;
|
|
11
|
+
email: CreationOptional<string | null>;
|
|
12
|
+
password: CreationOptional<string | null>;
|
|
13
|
+
securityClearanceId: string;
|
|
14
|
+
plateNumber: CreationOptional<string | null>;
|
|
15
|
+
nationalId: string;
|
|
16
|
+
isActive: CreationOptional<boolean>;
|
|
17
|
+
isSuspended: CreationOptional<boolean>;
|
|
18
|
+
bannedAt: CreationOptional<Date | null>;
|
|
19
|
+
banReason: CreationOptional<string | null>;
|
|
20
|
+
suspendedAt: CreationOptional<Date | null>;
|
|
21
|
+
suspensionReason: CreationOptional<string | null>;
|
|
22
|
+
forgotPassword: CreationOptional<boolean>;
|
|
23
|
+
otp: CreationOptional<string | null>;
|
|
24
|
+
otpExpiresAt: CreationOptional<Date | null>;
|
|
25
|
+
isDeactivated: CreationOptional<boolean>;
|
|
26
|
+
deactivatedAt: CreationOptional<Date | null>;
|
|
27
|
+
lastLoginAt: CreationOptional<Date | null>;
|
|
28
|
+
tokenVersion: CreationOptional<number>;
|
|
29
|
+
readonly createdAt: CreationOptional<Date>;
|
|
30
|
+
devices?: NonAttribute<Device[]>;
|
|
31
|
+
payments?: NonAttribute<Payment[]>;
|
|
32
|
+
securityClearance?: NonAttribute<SecurityClearance>;
|
|
33
|
+
}
|
|
34
|
+
export declare const initUserModel: (sequelize: any) => void;
|
|
35
|
+
export type UserModel = typeof User;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initUserModel = exports.User = void 0;
|
|
4
|
+
// src/models/user.models.ts
|
|
5
|
+
const vr_migrations_1 = require("vr-migrations");
|
|
6
|
+
class User extends vr_migrations_1.Model {
|
|
7
|
+
}
|
|
8
|
+
exports.User = User;
|
|
9
|
+
const initUserModel = (sequelize) => {
|
|
10
|
+
User.init({
|
|
11
|
+
id: {
|
|
12
|
+
type: vr_migrations_1.DataTypes.UUID,
|
|
13
|
+
defaultValue: vr_migrations_1.DataTypes.UUIDV4,
|
|
14
|
+
primaryKey: true,
|
|
15
|
+
},
|
|
16
|
+
firstName: {
|
|
17
|
+
type: vr_migrations_1.DataTypes.STRING(100),
|
|
18
|
+
allowNull: false,
|
|
19
|
+
},
|
|
20
|
+
lastName: {
|
|
21
|
+
type: vr_migrations_1.DataTypes.STRING(100),
|
|
22
|
+
allowNull: false,
|
|
23
|
+
},
|
|
24
|
+
phoneNumber: {
|
|
25
|
+
type: vr_migrations_1.DataTypes.STRING(20),
|
|
26
|
+
allowNull: false,
|
|
27
|
+
unique: true,
|
|
28
|
+
},
|
|
29
|
+
nationalId: {
|
|
30
|
+
type: vr_migrations_1.DataTypes.STRING(16),
|
|
31
|
+
allowNull: false,
|
|
32
|
+
unique: true,
|
|
33
|
+
},
|
|
34
|
+
jacketId: {
|
|
35
|
+
type: vr_migrations_1.DataTypes.STRING(50),
|
|
36
|
+
allowNull: false,
|
|
37
|
+
unique: true,
|
|
38
|
+
},
|
|
39
|
+
email: {
|
|
40
|
+
type: vr_migrations_1.DataTypes.STRING(100),
|
|
41
|
+
allowNull: true,
|
|
42
|
+
unique: true,
|
|
43
|
+
},
|
|
44
|
+
password: {
|
|
45
|
+
type: vr_migrations_1.DataTypes.STRING,
|
|
46
|
+
allowNull: true,
|
|
47
|
+
},
|
|
48
|
+
securityClearanceId: {
|
|
49
|
+
type: vr_migrations_1.DataTypes.UUID,
|
|
50
|
+
allowNull: false,
|
|
51
|
+
},
|
|
52
|
+
plateNumber: {
|
|
53
|
+
type: vr_migrations_1.DataTypes.STRING(20),
|
|
54
|
+
allowNull: true,
|
|
55
|
+
},
|
|
56
|
+
isActive: {
|
|
57
|
+
type: vr_migrations_1.DataTypes.BOOLEAN,
|
|
58
|
+
defaultValue: true,
|
|
59
|
+
},
|
|
60
|
+
isSuspended: {
|
|
61
|
+
type: vr_migrations_1.DataTypes.BOOLEAN,
|
|
62
|
+
defaultValue: false,
|
|
63
|
+
},
|
|
64
|
+
bannedAt: {
|
|
65
|
+
type: vr_migrations_1.DataTypes.DATE,
|
|
66
|
+
allowNull: true,
|
|
67
|
+
},
|
|
68
|
+
banReason: {
|
|
69
|
+
type: vr_migrations_1.DataTypes.TEXT,
|
|
70
|
+
allowNull: true,
|
|
71
|
+
},
|
|
72
|
+
suspendedAt: {
|
|
73
|
+
type: vr_migrations_1.DataTypes.DATE,
|
|
74
|
+
allowNull: true,
|
|
75
|
+
},
|
|
76
|
+
suspensionReason: {
|
|
77
|
+
type: vr_migrations_1.DataTypes.TEXT,
|
|
78
|
+
allowNull: true,
|
|
79
|
+
},
|
|
80
|
+
lastLoginAt: {
|
|
81
|
+
type: vr_migrations_1.DataTypes.DATE,
|
|
82
|
+
allowNull: true,
|
|
83
|
+
},
|
|
84
|
+
tokenVersion: {
|
|
85
|
+
type: vr_migrations_1.DataTypes.INTEGER,
|
|
86
|
+
allowNull: false,
|
|
87
|
+
defaultValue: 1,
|
|
88
|
+
},
|
|
89
|
+
forgotPassword: {
|
|
90
|
+
type: vr_migrations_1.DataTypes.BOOLEAN,
|
|
91
|
+
defaultValue: false,
|
|
92
|
+
},
|
|
93
|
+
otp: {
|
|
94
|
+
type: vr_migrations_1.DataTypes.STRING(6),
|
|
95
|
+
allowNull: true,
|
|
96
|
+
},
|
|
97
|
+
otpExpiresAt: {
|
|
98
|
+
type: vr_migrations_1.DataTypes.DATE,
|
|
99
|
+
allowNull: true,
|
|
100
|
+
},
|
|
101
|
+
isDeactivated: {
|
|
102
|
+
type: vr_migrations_1.DataTypes.BOOLEAN,
|
|
103
|
+
defaultValue: false,
|
|
104
|
+
},
|
|
105
|
+
deactivatedAt: {
|
|
106
|
+
type: vr_migrations_1.DataTypes.DATE,
|
|
107
|
+
allowNull: true,
|
|
108
|
+
},
|
|
109
|
+
createdAt: {
|
|
110
|
+
type: vr_migrations_1.DataTypes.DATE,
|
|
111
|
+
defaultValue: vr_migrations_1.DataTypes.NOW,
|
|
112
|
+
},
|
|
113
|
+
}, {
|
|
114
|
+
sequelize,
|
|
115
|
+
modelName: "User",
|
|
116
|
+
tableName: "users",
|
|
117
|
+
timestamps: true,
|
|
118
|
+
updatedAt: false,
|
|
119
|
+
freezeTableName: true,
|
|
120
|
+
});
|
|
121
|
+
};
|
|
122
|
+
exports.initUserModel = initUserModel;
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vr-models",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "Shared database models package for VR applications",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist/**/*"
|
|
9
|
+
],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"clean": "rimraf dist",
|
|
12
|
+
"build": "npm run clean && tsc",
|
|
13
|
+
"test": "jest",
|
|
14
|
+
"version": "npm run build && git add -A dist",
|
|
15
|
+
"pub": "git add . && git commit -m \"Version update\" && npm version patch && npm publish && git push && git push --tags",
|
|
16
|
+
"prepublishOnly": "npm run build",
|
|
17
|
+
"postpublish": "git push && git push --tags"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"sequelize",
|
|
21
|
+
"models",
|
|
22
|
+
"typescript",
|
|
23
|
+
"vr",
|
|
24
|
+
"database"
|
|
25
|
+
],
|
|
26
|
+
"author": "kanu-cast",
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"sequelize": "^6.37.1",
|
|
30
|
+
"uuid": "^9.0.1"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"typescript": "^5.3.3",
|
|
34
|
+
"@types/node": "^20.11.19",
|
|
35
|
+
"rimraf": "^5.0.5",
|
|
36
|
+
"pg": "^8.11.3",
|
|
37
|
+
"pg-hstore": "^2.3.4",
|
|
38
|
+
"vr-migrations": "^1.0.3"
|
|
39
|
+
},
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"sequelize": "^6.x",
|
|
42
|
+
"vr-migrations": "^1.0.3"
|
|
43
|
+
}
|
|
44
|
+
}
|