picker-db 3.4.0

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.
Files changed (43) hide show
  1. package/.editorconfig +8 -0
  2. package/.eslintignore +9 -0
  3. package/.eslintrc.json +35 -0
  4. package/.nvmrc +1 -0
  5. package/.vscode/settings.json +11 -0
  6. package/README.md +21 -0
  7. package/bitbucket-pipelines.yml +24 -0
  8. package/constants.js +420 -0
  9. package/index.js +5 -0
  10. package/lib/Logger/index.js +45 -0
  11. package/lib/Mongo/index.js +126 -0
  12. package/modules/picker/index.js +259 -0
  13. package/modules/picker/models/identityCounter.js +15 -0
  14. package/modules/picker/models/index.js +50 -0
  15. package/modules/picker/schemas/address.js +74 -0
  16. package/modules/picker/schemas/adminSetting.js +125 -0
  17. package/modules/picker/schemas/balanceTransaction.js +132 -0
  18. package/modules/picker/schemas/bill.js +70 -0
  19. package/modules/picker/schemas/bookingProduct.js +50 -0
  20. package/modules/picker/schemas/bookings.js +699 -0
  21. package/modules/picker/schemas/business.js +231 -0
  22. package/modules/picker/schemas/businessCategory.js +61 -0
  23. package/modules/picker/schemas/customer.js +28 -0
  24. package/modules/picker/schemas/driver.js +162 -0
  25. package/modules/picker/schemas/fareSettings.js +122 -0
  26. package/modules/picker/schemas/fraudBooking.js +21 -0
  27. package/modules/picker/schemas/identityCounter.js +10 -0
  28. package/modules/picker/schemas/kmRange.js +27 -0
  29. package/modules/picker/schemas/massDelivery.js +119 -0
  30. package/modules/picker/schemas/notification.js +76 -0
  31. package/modules/picker/schemas/paymentezCustomer.js +41 -0
  32. package/modules/picker/schemas/paymentezTransaction.js +67 -0
  33. package/modules/picker/schemas/preference.js +40 -0
  34. package/modules/picker/schemas/pricingDetails.js +90 -0
  35. package/modules/picker/schemas/referralUsage.js +33 -0
  36. package/modules/picker/schemas/region.js +75 -0
  37. package/modules/picker/schemas/review.js +42 -0
  38. package/modules/picker/schemas/session.js +25 -0
  39. package/modules/picker/schemas/superRegion.js +41 -0
  40. package/modules/picker/schemas/user.js +337 -0
  41. package/package.json +29 -0
  42. package/playground/testConnection.js +24 -0
  43. package/playground/testService.js +27 -0
@@ -0,0 +1,119 @@
1
+
2
+ const { STATUSES } = require("../../../constants").MASS_DELIVERY;
3
+ const { getModel } = require("../models/identityCounter");
4
+
5
+ /** @param {import("mongoose")} connection */
6
+ module.exports = (connection) => {
7
+ const IdentityCounterModel = getModel(connection);
8
+
9
+ const MassDeliverySchema = new connection.base.Schema({
10
+ massDeliveryID: {
11
+ type: Number,
12
+ index: true,
13
+ },
14
+ business: {
15
+ type: connection.base.Schema.ObjectId,
16
+ ref: "User",
17
+ },
18
+ businessName: {
19
+ type: String,
20
+ },
21
+ driver: {
22
+ type: connection.base.Schema.ObjectId,
23
+ ref: "User",
24
+ },
25
+ driverName: {
26
+ type: String,
27
+ },
28
+ totalDeliveryFee: {
29
+ type: Number,
30
+ min: 0,
31
+ max: 10000,
32
+ },
33
+ totalDistance: {
34
+ type: Number,
35
+ min: 0,
36
+ max: 10000,
37
+ },
38
+ totalLocations: {
39
+ type: Number,
40
+ min: 0,
41
+ max: 1000,
42
+ },
43
+ totalTime: {
44
+ type: Number,
45
+ min: 0,
46
+ },
47
+ totalOrderAmount: {
48
+ type: Number,
49
+ min: 0,
50
+ max: 1000,
51
+ },
52
+ totalSMR: {
53
+ type: Number,
54
+ min: 0,
55
+ },
56
+ currentStatus: {
57
+ type: Number,
58
+ index: true,
59
+ enum: [
60
+ STATUSES.PENDING.INDEX,
61
+ STATUSES.ONGOING.INDEX,
62
+ STATUSES.COMPLETED.INDEX,
63
+ STATUSES.CANCELLED.INDEX,
64
+ ],
65
+ default: STATUSES.PENDING.INDEX,
66
+ },
67
+ statusText: {
68
+ type: String,
69
+ enum: [
70
+ STATUSES.PENDING.TEXT,
71
+ STATUSES.ONGOING.TEXT,
72
+ STATUSES.COMPLETED.TEXT,
73
+ STATUSES.CANCELLED.TEXT,
74
+ ],
75
+ default: STATUSES.PENDING.TEXT,
76
+ },
77
+ startAt: {
78
+ type: Date,
79
+ default: Date.now(),
80
+ },
81
+ endAt: {
82
+ type: Date,
83
+ },
84
+ request: {
85
+ type: JSON,
86
+ },
87
+ fileUrl: {
88
+ type: String,
89
+ },
90
+ completedBookings: {
91
+ type: Number,
92
+ min: 0,
93
+ default: 0,
94
+ },
95
+ totalBookings: {
96
+ type: Number,
97
+ min: 0,
98
+ },
99
+ }, { timestamps: true });
100
+
101
+ MassDeliverySchema.pre("save", function (next) {
102
+ if (!this.isNew) {
103
+ return next();
104
+ }
105
+ const doc = this;
106
+ const query = { model: "MassDelivery" };
107
+ const update = { $inc: { count: 1 } };
108
+ const options = { new: true };
109
+ IdentityCounterModel.findOneAndUpdate(query, update, options, function (error, counter) {
110
+ if (error) {
111
+ return next(error);
112
+ }
113
+ doc.massDeliveryID = counter.count;
114
+ next();
115
+ });
116
+ });
117
+
118
+ return MassDeliverySchema;
119
+ };
@@ -0,0 +1,76 @@
1
+ const { VIA, PROVIDERS } = require("../../../constants").NOTIFICATION;
2
+ const _ = require("lodash");
3
+
4
+ /** @param {import("mongoose")} connection */
5
+ module.exports = (connection) => {
6
+ const NotificationSchema = new connection.base.Schema({
7
+ notificationUserID: [{
8
+ type: connection.base.Schema.ObjectId,
9
+ ref: "User",
10
+ index: true,
11
+ sparse: true,
12
+ }],
13
+ eventID: {
14
+ type: String,
15
+ index: true,
16
+ sparse: true,
17
+ }, // ID of the event that triggered the notification
18
+ eventType: {
19
+ type: String,
20
+ index: true,
21
+ }, // Notification type
22
+ title: { type: String },
23
+ message: { type: String },
24
+ messageHtml: { type: String }, // Html version of the message
25
+ provider: {
26
+ type: String,
27
+ index: true,
28
+ sparse: true,
29
+ },
30
+ via: {
31
+ type: String,
32
+ required: true,
33
+ index: true,
34
+ sparse: true,
35
+ enum: _.keys(VIA),
36
+ },
37
+ sentStatus: {
38
+ type: String,
39
+ enum: ["success", "failed"],
40
+ index: true,
41
+ sparse: true,
42
+ },
43
+ isAdminNotification: {
44
+ type: Boolean,
45
+ default: false,
46
+ index: true,
47
+ sparse: true,
48
+ },
49
+ isRead: {
50
+ type: Boolean,
51
+ default: false,
52
+ },
53
+ isDeleted: {
54
+ type: Boolean,
55
+ default: false,
56
+ },
57
+ data: {
58
+ type: JSON,
59
+ }, // Data sent as notification
60
+ error: {
61
+ type: String,
62
+ },
63
+ providerID: {
64
+ type: String,
65
+ index: true,
66
+ sparse: true,
67
+ },
68
+ deviceToken: {
69
+ type: String,
70
+ index: true,
71
+ sparse: true,
72
+ },
73
+ }, { timestamp: true });
74
+
75
+ return NotificationSchema;
76
+ };
@@ -0,0 +1,41 @@
1
+ /** @param {import("mongoose")} connection */
2
+ module.exports = (connection) => {
3
+ const PaymentezCustomerSchema = new connection.base.Schema({
4
+ user: {
5
+ type: connection.base.Schema.ObjectId,
6
+ ref: "User",
7
+ },
8
+ type: {
9
+ type: String,
10
+ },
11
+ token: {
12
+ type: String,
13
+ required: true,
14
+ },
15
+ transaction_reference: {
16
+ type: String,
17
+ default: null,
18
+ },
19
+ isDefault: {
20
+ type: Boolean,
21
+ default: 0,
22
+ },
23
+ taxPercentage: {
24
+ type: Number,
25
+ min: 0,
26
+ max: 1,
27
+ default: 0,
28
+ },
29
+ platform: {
30
+ type: String,
31
+ },
32
+ cardType: {
33
+ type: String,
34
+ },
35
+ bin: {
36
+ type: String,
37
+ },
38
+ }, { timestamps: true });
39
+
40
+ return PaymentezCustomerSchema;
41
+ };
@@ -0,0 +1,67 @@
1
+ const { PAYMENT_METHODS } = require("../../../constants");
2
+
3
+ /** @param {import("mongoose")} connection */
4
+ module.exports = (connection) => {
5
+ const PaymentezTransactionSchema = new connection.base.Schema({
6
+ customerId: {
7
+ type: connection.base.Schema.ObjectId,
8
+ ref: "PaymentezCustomer",
9
+ },
10
+ trxId: {
11
+ type: String,
12
+ required: false,
13
+ default: null,
14
+ },
15
+ type: {
16
+ type: String,
17
+ },
18
+ amount: {
19
+ type: Number,
20
+ },
21
+ paymentMethod: {
22
+ type: String,
23
+ required: false,
24
+ enum: [
25
+ PAYMENT_METHODS.CARD.TEXT,
26
+ PAYMENT_METHODS.CASH.TEXT,
27
+ ],
28
+ },
29
+ authCode: {
30
+ type: String,
31
+ },
32
+ bookingID: {
33
+ type: connection.base.Schema.ObjectId,
34
+ ref: "Bookings",
35
+ },
36
+ status: {
37
+ type: String,
38
+ },
39
+ message: {
40
+ type: String,
41
+ },
42
+ statusDetail: {
43
+ type: String,
44
+ },
45
+ taxCharge: {
46
+ type: Number,
47
+ min: 0,
48
+ default: 0,
49
+ },
50
+ registeredBy: {
51
+ type: connection.base.Schema.ObjectId,
52
+ ref: "User",
53
+ }, // Reference to the user who realized the transaction
54
+ refundedBy: {
55
+ type: connection.base.Schema.ObjectId,
56
+ ref: "User",
57
+ }, // Reference to the user who realized the refund
58
+ refundDate: {
59
+ type: Date,
60
+ },
61
+ refundError: {
62
+ type: String,
63
+ },
64
+ }, { timestamps: true });
65
+
66
+ return PaymentezTransactionSchema;
67
+ };
@@ -0,0 +1,40 @@
1
+ const {
2
+ PAYMENT_METHODS,
3
+ VEHICLE_TYPES,
4
+ } = require("../../../constants");
5
+
6
+ /** @param {import("mongoose")} connection */
7
+ module.exports = (connection) => {
8
+ const PreferenceSchema = new connection.base.Schema({
9
+ paymentMethod: {
10
+ type: String,
11
+ default: null,
12
+ enum: [
13
+ PAYMENT_METHODS.CASH.TEXT,
14
+ PAYMENT_METHODS.CARD.TEXT,
15
+ PAYMENT_METHODS.NONE.TEXT,
16
+ ],
17
+ default: PAYMENT_METHODS.CARD.TEXT,
18
+ },
19
+ carName: {
20
+ type: String,
21
+ default: null,
22
+ enum: [
23
+ VEHICLE_TYPES.BIKE.TEXT,
24
+ VEHICLE_TYPES.LITE.TEXT,
25
+ VEHICLE_TYPES.NONE.TEXT,
26
+ ],
27
+ default: VEHICLE_TYPES.BIKE.TEXT,
28
+ },
29
+ user_id: {
30
+ type: connection.base.Schema.ObjectId,
31
+ ref: "User",
32
+ },
33
+ language: {
34
+ type: String,
35
+ default: "es",
36
+ },
37
+ }, { timestamps: true });
38
+
39
+ return PreferenceSchema;
40
+ };
@@ -0,0 +1,90 @@
1
+ const _ = require("lodash");
2
+
3
+ const { RUSH_HOUR_INCREASE_TYPES } = require("../../../constants").FARE;
4
+
5
+ const KmRangeSchema = require("./kmRange");
6
+
7
+ /** @param {import("mongoose")} connection */
8
+ module.exports = (connection) => {
9
+ const PricingDetailsSchema = new connection.base.Schema({
10
+ baseFare: {
11
+ type: Number,
12
+ required: true,
13
+ min: 0,
14
+ },
15
+ perKmCharge: {
16
+ type: Number,
17
+ required: true,
18
+ min: 0,
19
+ },
20
+ perMinuteCharge: {
21
+ type: Number,
22
+ required: true,
23
+ min: 0,
24
+ },
25
+ freeTime: {
26
+ type: Number,
27
+ required: true,
28
+ min: 0,
29
+ },
30
+ baseDistance: {
31
+ type: Number,
32
+ required: true,
33
+ min: 0,
34
+ },
35
+ averageTime: {
36
+ type: Number,
37
+ required: true,
38
+ min: 0,
39
+ }, // IN SECONDS
40
+ kmRanges: [KmRangeSchema(connection)],
41
+ notShowTimeLimit: {
42
+ type: Number,
43
+ default: 10,
44
+ }, // IN SECONDS
45
+ notShowCustomerCharge: {
46
+ type: Number,
47
+ default: 0.50,
48
+ },
49
+ notShowDriverCommission: {
50
+ type: Number,
51
+ default: 0.50,
52
+ },
53
+ cancellationPolicy: {
54
+ type: String,
55
+ default: null,
56
+ },
57
+ cancellationFreeTimeInSecond: {
58
+ type: Number,
59
+ default: 0,
60
+ },
61
+ minimumCancellationFee: {
62
+ type: Number,
63
+ default: 1,
64
+ },
65
+ rainCharge: {
66
+ type: Number,
67
+ default: 0,
68
+ min: 0,
69
+ },
70
+ specialFeesActive: [{
71
+ type: String,
72
+ }],
73
+ rushHourIncreaseType: {
74
+ type: String,
75
+ enum: _.values(RUSH_HOUR_INCREASE_TYPES),
76
+ },
77
+ rushHourIncreaseCoefficient: {
78
+ type: Number,
79
+ default: 0,
80
+ min: 0,
81
+ },
82
+ rushHourIncrementAmount: {
83
+ type: Number,
84
+ default: 0,
85
+ min: 0,
86
+ },
87
+ }, { _id: false });
88
+
89
+ return PricingDetailsSchema;
90
+ };
@@ -0,0 +1,33 @@
1
+ /** @param {import("mongoose")} connection */
2
+ module.exports = (connection) => {
3
+ const ReferralUsageSchema = new connection.base.Schema({
4
+ referralPattern: {
5
+ type: String,
6
+ requied: true,
7
+ },
8
+ user: {
9
+ type: connection.base.Schema.ObjectId,
10
+ ref: "User",
11
+ default: null,
12
+ },
13
+ referralCode: {
14
+ type: String,
15
+ required: true,
16
+ index: true,
17
+ },
18
+ noOfReferralsUsed: {
19
+ type: Number,
20
+ default: 0,
21
+ },
22
+ referralCodeUsed: {
23
+ referralCode: { type: String },
24
+ date: { type: Date },
25
+ user: {
26
+ type: connection.base.Schema.ObjectId,
27
+ ref: "User",
28
+ }
29
+ },
30
+ }, { timestamps: true });
31
+
32
+ return ReferralUsageSchema;
33
+ };
@@ -0,0 +1,75 @@
1
+
2
+ const { VEHICLE_TYPES, PAYMENT_METHODS, RIDE_TYPES } = require("../../../constants");
3
+
4
+ /** @param {import("mongoose")} connection */
5
+ module.exports = (connection) => {
6
+ const RegionSchema = new connection.base.Schema({
7
+ regionName: {
8
+ type: String,
9
+ },
10
+ geoLongLat: {
11
+ type: {
12
+ type: String,
13
+ enum: "Polygon",
14
+ default: "Polygon",
15
+ },
16
+ coordinates: {
17
+ type: Array,
18
+ },
19
+ },
20
+ isBlocked: {
21
+ type: Boolean,
22
+ default: false,
23
+ },
24
+ isDeleted: {
25
+ type: Boolean,
26
+ default: false,
27
+ },
28
+ carType: {
29
+ type: Number,
30
+ enum: [
31
+ VEHICLE_TYPES.BIKE.INDEX,
32
+ VEHICLE_TYPES.LITE.INDEX,
33
+ VEHICLE_TYPES.BOTH.INDEX,
34
+ ],
35
+ index: true,
36
+ },
37
+ paymentType: {
38
+ type: Number,
39
+ required: true,
40
+ enum: [
41
+ PAYMENT_METHODS.CARD.INDEX,
42
+ PAYMENT_METHODS.CASH.INDEX,
43
+ PAYMENT_METHODS.BOTH.INDEX,
44
+ ],
45
+ },
46
+ rideType: {
47
+ type: Number,
48
+ required: true,
49
+ enum: [
50
+ RIDE_TYPES.NOW.INDEX,
51
+ RIDE_TYPES.LATER.INDEX,
52
+ RIDE_TYPES.BOTH.INDEX,
53
+ ],
54
+ },
55
+ superRegionID: {
56
+ type: connection.base.Schema.ObjectId,
57
+ ref: "SuperRegion",
58
+ required: true,
59
+ index: true,
60
+ },
61
+ highDemandThreshold: {
62
+ type: Number,
63
+ min: 0,
64
+ },
65
+ specialFeesActive: [{
66
+ type: String,
67
+ enum: [
68
+ "RAIN_FEE",
69
+ "RUSH_HOUR_FEE",
70
+ ],
71
+ }],
72
+ }, { timestamps: true });
73
+
74
+ return RegionSchema;
75
+ };
@@ -0,0 +1,42 @@
1
+ const { CALIFICATION } = require("../../../constants");
2
+
3
+ /** @param {import("mongoose")} connection */
4
+ module.exports = (connection) => {
5
+ const calificationsSchema = new connection.base.Schema({
6
+ number: {
7
+ type: Number,
8
+ required: true,
9
+ enum: [
10
+ CALIFICATION.EFFICIENT.text,
11
+ CALIFICATION.FAST.text,
12
+ CALIFICATION.INEFFICIENT.text,
13
+ CALIFICATION.KIND.text,
14
+ CALIFICATION.LATE.text,
15
+ CALIFICATION.RUDE.text
16
+ ]
17
+ },
18
+ text: {
19
+ type: String,
20
+ required: true,
21
+ enum: [
22
+ CALIFICATION.EFFICIENT.text,
23
+ CALIFICATION.FAST.text,
24
+ CALIFICATION.INEFFICIENT.text,
25
+ CALIFICATION.KIND.text,
26
+ CALIFICATION.LATE.text,
27
+ CALIFICATION.RUDE.text
28
+ ]
29
+ }
30
+ }, { _id: false });
31
+ const ReviewSchema = new connection.base.Schema({
32
+ reviewBy: { type: connection.base.Schema.ObjectId, ref: 'User', required: true },
33
+ reviewed: { type: connection.base.Schema.ObjectId, ref: 'User', required: true },
34
+ bookingID: { type: connection.base.Schema.ObjectId, ref: 'Bookings', required: true },
35
+ bookingNumericId: { type: Number },
36
+ review: { type: String, default: 'NA' },
37
+ rating: { type: Number },
38
+ califications: [calificationsSchema]
39
+ }, { timestamps: true });
40
+
41
+ return ReviewSchema;
42
+ };
@@ -0,0 +1,25 @@
1
+ const { DEVICE_TYPES } = require("../../../constants").USER;
2
+
3
+ /** @param {import("mongoose")} connection */
4
+ module.exports = (connection) => {
5
+ const SessionSchema = new connection.base.Schema({
6
+ user: {
7
+ type: connection.base.Schema.ObjectId,
8
+ ref: "User",
9
+ },
10
+ remoteIP: { type: String },
11
+ deviceType: {
12
+ type: String,
13
+ enum: [
14
+ DEVICE_TYPES.IOS,
15
+ DEVICE_TYPES.ANDROID,
16
+ DEVICE_TYPES.WEB,
17
+ ],
18
+ },
19
+ deviceToken: {
20
+ type: String,
21
+ },
22
+ }, { timestamps: true });
23
+
24
+ return SessionSchema;
25
+ };
@@ -0,0 +1,41 @@
1
+
2
+ const { VEHICLE_TYPES } = require("../../../constants");
3
+
4
+ /** @param {import("mongoose")} connection */
5
+ module.exports = (connection) => {
6
+ const RegionSchema = new connection.base.Schema({
7
+ name: {
8
+ type: String,
9
+ required: true,
10
+ },
11
+ isActive: {
12
+ type: Boolean,
13
+ required: true,
14
+ },
15
+ coordinates: {
16
+ type: {
17
+ type: String,
18
+ default: "Point",
19
+ },
20
+ coordinates: {
21
+ type: [Number],
22
+ default: [0, 0],
23
+ },
24
+ },
25
+ range: {
26
+ type: Number,
27
+ required: true,
28
+ }, // In kms
29
+ carType: {
30
+ type: Number,
31
+ enum: [
32
+ VEHICLE_TYPES.BIKE.INDEX,
33
+ VEHICLE_TYPES.LITE.INDEX,
34
+ VEHICLE_TYPES.BOTH.INDEX,
35
+ ],
36
+ index: true,
37
+ },
38
+ }, { timestamps: true });
39
+
40
+ return RegionSchema;
41
+ };