payservedb 9.7.1 → 9.7.2
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/index.js +2 -0
- package/package.json +1 -1
- package/src/models/booking_voucher.js +132 -0
- package/src/models/booking_voucher_config.js +57 -0
package/index.js
CHANGED
|
@@ -181,6 +181,8 @@ const models = {
|
|
|
181
181
|
BookingConfig: require("./src/models/bookingconfig"),
|
|
182
182
|
BookingAnalytics: require("./src/models/bookinganalytics"),
|
|
183
183
|
BookingInvoice: require("./src/models/booking_invoice"),
|
|
184
|
+
BookingVoucher: require("./src/models/booking_voucher"),
|
|
185
|
+
BookingVoucherConfig: require("./src/models/booking_voucher_config"),
|
|
184
186
|
CancellationPolicy: require("./src/models/cancellation_policy"),
|
|
185
187
|
BankDetails: require("./src/models/bankdetails"),
|
|
186
188
|
RevenueRecord: require("./src/models/bookingrevenuerecord"),
|
package/package.json
CHANGED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const EXPIRY_DURATION_MS = {
|
|
4
|
+
'2_weeks': 14 * 24 * 60 * 60 * 1000,
|
|
5
|
+
'1_month': 30 * 24 * 60 * 60 * 1000,
|
|
6
|
+
'3_months': 90 * 24 * 60 * 60 * 1000,
|
|
7
|
+
'6_months': 182 * 24 * 60 * 60 * 1000
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const bookingVoucherSchema = new mongoose.Schema({
|
|
11
|
+
facilityId: {
|
|
12
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
13
|
+
ref: 'Facility',
|
|
14
|
+
required: true
|
|
15
|
+
},
|
|
16
|
+
voucherCode: {
|
|
17
|
+
type: String,
|
|
18
|
+
required: true,
|
|
19
|
+
unique: true
|
|
20
|
+
},
|
|
21
|
+
sourceReservationId: {
|
|
22
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
23
|
+
ref: 'BookingReservation',
|
|
24
|
+
required: true
|
|
25
|
+
},
|
|
26
|
+
sourceInvoiceId: {
|
|
27
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
28
|
+
ref: 'BookingInvoice'
|
|
29
|
+
},
|
|
30
|
+
guestInfo: {
|
|
31
|
+
name: { type: String, required: true },
|
|
32
|
+
email: { type: String, required: true },
|
|
33
|
+
phone: { type: String, required: true }
|
|
34
|
+
},
|
|
35
|
+
// Audit trail for how `amount` was derived.
|
|
36
|
+
calculation: {
|
|
37
|
+
nightlyRate: { type: Number, required: true, min: 0 },
|
|
38
|
+
nightsUnused: { type: Number, required: true, min: 0 },
|
|
39
|
+
// 100% value of the unused nights, before percentageApplied
|
|
40
|
+
remainingAmount: { type: Number, required: true, min: 0 },
|
|
41
|
+
percentageApplied: { type: Number, required: true, min: 1, max: 100 }
|
|
42
|
+
},
|
|
43
|
+
// Redeemable value = remainingAmount * percentageApplied / 100
|
|
44
|
+
amount: {
|
|
45
|
+
type: Number,
|
|
46
|
+
required: true,
|
|
47
|
+
min: 0
|
|
48
|
+
},
|
|
49
|
+
currencyId: {
|
|
50
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
51
|
+
ref: 'Currency',
|
|
52
|
+
required: true
|
|
53
|
+
},
|
|
54
|
+
// 'revoked' (not 'cancelled') - a voucher is void by staff action
|
|
55
|
+
// (issued in error, flagged fraudulent, etc), which is deliberately a
|
|
56
|
+
// different word and a different code path from 'expired' (passive,
|
|
57
|
+
// time-based). Both are terminal and non-redeemable, but staff need
|
|
58
|
+
// to distinguish "we killed this on purpose, here's why" from "nobody
|
|
59
|
+
// used it in time" when reviewing a facility's voucher history.
|
|
60
|
+
status: {
|
|
61
|
+
type: String,
|
|
62
|
+
enum: ['active', 'used', 'expired', 'revoked'],
|
|
63
|
+
default: 'active'
|
|
64
|
+
},
|
|
65
|
+
statusHistory: [{
|
|
66
|
+
status: {
|
|
67
|
+
type: String,
|
|
68
|
+
enum: ['active', 'used', 'expired', 'revoked'],
|
|
69
|
+
required: true
|
|
70
|
+
},
|
|
71
|
+
timestamp: {
|
|
72
|
+
type: Date,
|
|
73
|
+
default: Date.now
|
|
74
|
+
},
|
|
75
|
+
updatedBy: mongoose.Schema.Types.ObjectId,
|
|
76
|
+
notes: String
|
|
77
|
+
}],
|
|
78
|
+
// Optional fixed-duration safety net (see BookingVoucherConfig). null
|
|
79
|
+
// means no calendar expiry - the voucher only dies when redeemed or
|
|
80
|
+
// explicitly revoked.
|
|
81
|
+
expiryDuration: {
|
|
82
|
+
type: String,
|
|
83
|
+
enum: ['2_weeks', '1_month', '3_months', '6_months', null],
|
|
84
|
+
default: null
|
|
85
|
+
},
|
|
86
|
+
expiresAt: {
|
|
87
|
+
type: Date,
|
|
88
|
+
default: null
|
|
89
|
+
},
|
|
90
|
+
usedAt: {
|
|
91
|
+
type: Date
|
|
92
|
+
},
|
|
93
|
+
usedOnReservationId: {
|
|
94
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
95
|
+
ref: 'BookingReservation'
|
|
96
|
+
},
|
|
97
|
+
amountApplied: {
|
|
98
|
+
type: Number
|
|
99
|
+
},
|
|
100
|
+
revokedReason: {
|
|
101
|
+
type: String
|
|
102
|
+
},
|
|
103
|
+
revokedAt: {
|
|
104
|
+
type: Date
|
|
105
|
+
},
|
|
106
|
+
issuedBy: {
|
|
107
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
108
|
+
ref: 'User'
|
|
109
|
+
},
|
|
110
|
+
updatedBy: {
|
|
111
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
112
|
+
ref: 'User'
|
|
113
|
+
}
|
|
114
|
+
}, {
|
|
115
|
+
timestamps: true
|
|
116
|
+
});
|
|
117
|
+
bookingVoucherSchema.pre('validate', function computeExpiresAt(next) {
|
|
118
|
+
if (this.expiryDuration && !this.expiresAt) {
|
|
119
|
+
const base = this.isNew ? Date.now() : (this.get('createdAt') ? this.get('createdAt').getTime() : Date.now());
|
|
120
|
+
this.expiresAt = new Date(base + EXPIRY_DURATION_MS[this.expiryDuration]);
|
|
121
|
+
}
|
|
122
|
+
next();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
bookingVoucherSchema.index({ facilityId: 1, status: 1 });
|
|
126
|
+
bookingVoucherSchema.index({ 'guestInfo.email': 1 });
|
|
127
|
+
bookingVoucherSchema.index({ 'guestInfo.phone': 1 });
|
|
128
|
+
bookingVoucherSchema.index({ status: 1, expiresAt: 1 });
|
|
129
|
+
|
|
130
|
+
const BookingVoucher = mongoose.model('BookingVoucher', bookingVoucherSchema);
|
|
131
|
+
|
|
132
|
+
module.exports = BookingVoucher;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
const bookingVoucherConfigSchema = new mongoose.Schema({
|
|
3
|
+
facilityId: {
|
|
4
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
5
|
+
ref: 'Facility',
|
|
6
|
+
required: true,
|
|
7
|
+
unique: true
|
|
8
|
+
},
|
|
9
|
+
isEnabled: {
|
|
10
|
+
type: Boolean,
|
|
11
|
+
default: true
|
|
12
|
+
},
|
|
13
|
+
allowedPercentages: {
|
|
14
|
+
type: [Number],
|
|
15
|
+
default: [80, 90, 100],
|
|
16
|
+
validate: {
|
|
17
|
+
validator: (arr) => Array.isArray(arr) && arr.length > 0 && arr.every((p) => p > 0 && p <= 100),
|
|
18
|
+
message: 'allowedPercentages must be a non-empty array of values between 1 and 100'
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
defaultPercentage: {
|
|
22
|
+
type: Number,
|
|
23
|
+
default: 100,
|
|
24
|
+
min: 1,
|
|
25
|
+
max: 100
|
|
26
|
+
},
|
|
27
|
+
allowedExpiryDurations: {
|
|
28
|
+
type: [String],
|
|
29
|
+
enum: ['2_weeks', '1_month', '3_months', '6_months'],
|
|
30
|
+
default: ['2_weeks', '1_month', '3_months', '6_months']
|
|
31
|
+
},
|
|
32
|
+
defaultExpiryDuration: {
|
|
33
|
+
type: String,
|
|
34
|
+
enum: ['2_weeks', '1_month', '3_months', '6_months', null],
|
|
35
|
+
default: null
|
|
36
|
+
},
|
|
37
|
+
voucherCodePrefix: {
|
|
38
|
+
type: String,
|
|
39
|
+
trim: true,
|
|
40
|
+
uppercase: true,
|
|
41
|
+
default: 'VCH'
|
|
42
|
+
},
|
|
43
|
+
createdBy: {
|
|
44
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
45
|
+
ref: 'User'
|
|
46
|
+
},
|
|
47
|
+
updatedBy: {
|
|
48
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
49
|
+
ref: 'User'
|
|
50
|
+
}
|
|
51
|
+
}, {
|
|
52
|
+
timestamps: true
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const BookingVoucherConfig = mongoose.model('BookingVoucherConfig', bookingVoucherConfigSchema);
|
|
56
|
+
|
|
57
|
+
module.exports = BookingVoucherConfig;
|