@vibe-flats/booking-engine-common-server 1.0.91 → 1.0.93
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/index.d.ts +1 -0
- package/build/index.js +1 -0
- package/build/src/config/app.d.ts +3 -0
- package/build/src/config/app.js +3 -0
- package/build/src/models/units.d.ts +1 -0
- package/build/src/models/units.js +2 -1
- package/build/src/utils/purge-unit-cache.d.ts +2 -0
- package/build/src/utils/purge-unit-cache.js +42 -0
- package/package.json +2 -1
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -18,3 +18,4 @@ __exportStar(require("./src/units-models"), exports);
|
|
|
18
18
|
__exportStar(require("./src/config/app"), exports);
|
|
19
19
|
__exportStar(require("./src/utils/guesty-price"), exports);
|
|
20
20
|
__exportStar(require("./src/utils/monthly-diff"), exports);
|
|
21
|
+
__exportStar(require("./src/utils/purge-unit-cache"), exports);
|
package/build/src/config/app.js
CHANGED
|
@@ -99,7 +99,8 @@ const schema = new mongoose_1.default.Schema({
|
|
|
99
99
|
website: {
|
|
100
100
|
type: new mongoose_1.default.Schema({
|
|
101
101
|
description: { type: String, required: false },
|
|
102
|
-
slug: { type: String, required: false }
|
|
102
|
+
slug: { type: String, required: false },
|
|
103
|
+
lastCachePurgedAt: { type: Date, required: false }
|
|
103
104
|
}),
|
|
104
105
|
required: false,
|
|
105
106
|
_id: false
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.purgeUnitCache = void 0;
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
18
|
+
const app_1 = require("../config/app");
|
|
19
|
+
const purgeUnitCache = (unit) => __awaiter(void 0, void 0, void 0, function* () {
|
|
20
|
+
var _a, _b, _c;
|
|
21
|
+
//
|
|
22
|
+
if (!unit || !((_a = unit.website) === null || _a === void 0 ? void 0 : _a.slug) || !((_c = (_b = unit.market) === null || _b === void 0 ? void 0 : _b.website) === null || _c === void 0 ? void 0 : _c.slug)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
// Check that last purge date is older than 1 hour
|
|
26
|
+
if (unit.website.lastCachePurgedAt &&
|
|
27
|
+
(0, dayjs_1.default)(unit.website.lastCachePurgedAt).isAfter((0, dayjs_1.default)().subtract(app_1.COMMON_SERVER.website.purgeUnitCacheInterval, 'minutes'))) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
yield axios_1.default.post(`${process.env.BOOKING_ENGINE_NEXTJS_API_URL}/purge/unit`, {
|
|
31
|
+
unit: unit.website.slug,
|
|
32
|
+
market: unit.market.website.slug
|
|
33
|
+
}, {
|
|
34
|
+
headers: {
|
|
35
|
+
Authorization: `Bearer ${process.env.BOOKING_ENGINE_NEXTJS_API_TOKEN}`
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
// Save last purge date
|
|
39
|
+
unit.website.lastCachePurgedAt = new Date();
|
|
40
|
+
yield unit.save();
|
|
41
|
+
});
|
|
42
|
+
exports.purgeUnitCache = purgeUnitCache;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vibe-flats/booking-engine-common-server",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.93",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "./build/index.d.ts",
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"typescript": "^5.1.6"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
+
"axios": "^1.7.9",
|
|
24
25
|
"dayjs": "^1.11.13",
|
|
25
26
|
"mongoose": "^8.5.2"
|
|
26
27
|
}
|