@vibe-flats/booking-engine-common-server 1.0.100 → 1.0.103
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/build/src/models/guests.d.ts +4 -9
- package/build/src/models/guests.js +1 -20
- package/build/src/models/units.d.ts +1 -0
- package/build/src/models/units.js +2 -1
- package/build/src/units-models.d.ts +3 -1
- package/build/src/utils/guesty-price.d.ts +16 -7
- package/build/src/utils/guesty-price.js +22 -9
- package/package.json +1 -1
|
@@ -1,14 +1,9 @@
|
|
|
1
|
-
import mongoose
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
2
|
export interface GuestDocument extends mongoose.Document {
|
|
3
3
|
firstName: string;
|
|
4
4
|
lastName: string;
|
|
5
5
|
externalId: string;
|
|
6
6
|
}
|
|
7
|
-
export
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
lastName: string;
|
|
11
|
-
externalId: string;
|
|
12
|
-
}): Promise<GuestDocument>;
|
|
13
|
-
}
|
|
14
|
-
export declare const GuestModel: (connection: mongoose.Connection) => GuestModelInterface;
|
|
7
|
+
export declare const GuestModel: (connection: mongoose.Connection) => mongoose.Model<GuestDocument, {}, {}, {}, mongoose.Document<unknown, {}, GuestDocument> & GuestDocument & Required<{
|
|
8
|
+
_id: unknown;
|
|
9
|
+
}>, any>;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -22,17 +13,7 @@ const schema = new mongoose_1.default.Schema({
|
|
|
22
13
|
timestamps: true,
|
|
23
14
|
versionKey: false
|
|
24
15
|
});
|
|
25
|
-
// Create a unique index on externalId
|
|
26
|
-
schema.index({ externalId: 1 }, { unique: true });
|
|
27
16
|
const GuestModel = (connection) => {
|
|
28
|
-
|
|
29
|
-
model.findOrCreate = (guestData) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
-
const existingGuest = yield model.findOne({ externalId: guestData.externalId });
|
|
31
|
-
if (existingGuest) {
|
|
32
|
-
return existingGuest;
|
|
33
|
-
}
|
|
34
|
-
return yield model.create(guestData);
|
|
35
|
-
});
|
|
36
|
-
return model;
|
|
17
|
+
return connection.model('Guest', schema);
|
|
37
18
|
};
|
|
38
19
|
exports.GuestModel = GuestModel;
|
|
@@ -96,6 +96,7 @@ export interface UnitDocument extends mongoose.Document {
|
|
|
96
96
|
rating: number;
|
|
97
97
|
}[];
|
|
98
98
|
}[];
|
|
99
|
+
salesBlockWarning: string;
|
|
99
100
|
}
|
|
100
101
|
export declare const UnitModel: (connection: mongoose.Connection) => mongoose.Model<UnitDocument, {}, {}, {}, mongoose.Document<unknown, {}, UnitDocument> & UnitDocument & Required<{
|
|
101
102
|
_id: unknown;
|
|
@@ -18,5 +18,7 @@ export declare const unitsModels: (connection: mongoose.Connection) => {
|
|
|
18
18
|
AreaModel: mongoose.Model<import("./models/areas").AreaDocument, {}, {}, {}, mongoose.Document<unknown, {}, import("./models/areas").AreaDocument> & import("./models/areas").AreaDocument & Required<{
|
|
19
19
|
_id: unknown;
|
|
20
20
|
}>, any>;
|
|
21
|
-
GuestModel: import("./models/guests").
|
|
21
|
+
GuestModel: mongoose.Model<import("./models/guests").GuestDocument, {}, {}, {}, mongoose.Document<unknown, {}, import("./models/guests").GuestDocument> & import("./models/guests").GuestDocument & Required<{
|
|
22
|
+
_id: unknown;
|
|
23
|
+
}>, any>;
|
|
22
24
|
};
|
|
@@ -1,14 +1,23 @@
|
|
|
1
|
-
import { AvailabilityDocument } from '../models/availability';
|
|
2
1
|
import { UnitDocument } from '../models/units';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
stay: AvailabilityDocument[];
|
|
6
|
-
excludeCleaning?: boolean;
|
|
7
|
-
}) => {
|
|
2
|
+
import { AvailabilityDocument } from '../models/availability';
|
|
3
|
+
export interface VibePrice {
|
|
8
4
|
nights: number;
|
|
9
5
|
rent: number;
|
|
10
6
|
cleaning: number;
|
|
11
7
|
utilities: number;
|
|
8
|
+
subTotal: number;
|
|
12
9
|
total: number;
|
|
13
10
|
discount: number;
|
|
14
|
-
|
|
11
|
+
monthly: {
|
|
12
|
+
discount: number;
|
|
13
|
+
rent: number;
|
|
14
|
+
subTotal: number;
|
|
15
|
+
total: number;
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export declare const vibePrice: (obj: {
|
|
19
|
+
unit: UnitDocument;
|
|
20
|
+
stay: AvailabilityDocument[];
|
|
21
|
+
excludeCleaning?: boolean;
|
|
22
|
+
excludeUtilities?: boolean;
|
|
23
|
+
}) => VibePrice;
|
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.vibePrice = void 0;
|
|
4
4
|
const app_1 = require("../config/app");
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
const { unit, stay, excludeCleaning } = obj;
|
|
5
|
+
const monthly_diff_1 = require("./monthly-diff");
|
|
6
|
+
const vibePrice = (obj) => {
|
|
7
|
+
const { unit, stay, excludeCleaning, excludeUtilities } = obj;
|
|
8
8
|
const nights = stay.length;
|
|
9
9
|
const multiplier = nights >= app_1.COMMON_SERVER.priceFactor.monthly ? unit.prices.monthlyPriceFactor : 1;
|
|
10
10
|
// Apply multiplier: Guesty's approach to monthly pricing
|
|
11
11
|
const rent = +(stay.reduce((acc, stay) => acc + stay.price, 0) * multiplier).toFixed(0);
|
|
12
12
|
const cleaning = excludeCleaning ? 0 : unit.prices.cleaningFee;
|
|
13
|
-
const utilities = unit.prices.utilities * nights;
|
|
14
|
-
const
|
|
13
|
+
const utilities = excludeUtilities ? 0 : unit.prices.utilities * nights;
|
|
14
|
+
const subTotal = rent + utilities + cleaning;
|
|
15
15
|
const discount = nights >= app_1.COMMON_SERVER.priceFactor.monthly && unit.prices.monthlyPriceFactor !== 1
|
|
16
|
-
?
|
|
16
|
+
? subTotal * (1 - unit.prices.monthlyPriceFactor)
|
|
17
17
|
: 0;
|
|
18
|
-
|
|
18
|
+
const total = subTotal - discount;
|
|
19
|
+
// Get min and max dates from stay array
|
|
20
|
+
const sortedStay = [...stay].sort((a, b) => a.date.getTime() - b.date.getTime());
|
|
21
|
+
const dateFrom = sortedStay[0].date;
|
|
22
|
+
const dateTo = sortedStay[sortedStay.length - 1].date;
|
|
23
|
+
// Calculate exact months difference using dayjs
|
|
24
|
+
const monthsDiff = (0, monthly_diff_1.calculatePreciseMonthDifference)(dateFrom, dateTo);
|
|
25
|
+
const monthly = {
|
|
26
|
+
rent: Math.round(rent / monthsDiff),
|
|
27
|
+
discount: Math.round(discount / monthsDiff),
|
|
28
|
+
subTotal: Math.round(subTotal / monthsDiff),
|
|
29
|
+
total: Math.round(total / monthsDiff)
|
|
30
|
+
};
|
|
31
|
+
return { nights, rent, cleaning, utilities, subTotal, discount, total, monthly };
|
|
19
32
|
};
|
|
20
|
-
exports.
|
|
33
|
+
exports.vibePrice = vibePrice;
|