@vibe-flats/booking-engine-common-server 1.0.90 → 1.0.92

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.
@@ -55,7 +55,6 @@ export interface UnitDocument extends mongoose.Document {
55
55
  type: string;
56
56
  value: number;
57
57
  multiplier: 'PER_NIGHT' | 'PER_STAY' | 'PER_GUEST' | 'PER_GUEST_PER_NIGHT';
58
- isOptional: boolean;
59
58
  isPercentage: boolean;
60
59
  }[];
61
60
  urls: {
@@ -66,6 +65,7 @@ export interface UnitDocument extends mongoose.Document {
66
65
  website: {
67
66
  description: string;
68
67
  slug: string;
68
+ lastCachePurgedAt?: Date;
69
69
  };
70
70
  deal: {
71
71
  total: number;
@@ -83,7 +83,6 @@ const schema = new mongoose_1.default.Schema({
83
83
  type: { type: String, required: true },
84
84
  value: { type: Number, required: true },
85
85
  multiplier: { type: String, required: true },
86
- isOptional: { type: Boolean, required: true },
87
86
  isPercentage: { type: Boolean, required: true },
88
87
  _id: false
89
88
  }
@@ -100,7 +99,8 @@ const schema = new mongoose_1.default.Schema({
100
99
  website: {
101
100
  type: new mongoose_1.default.Schema({
102
101
  description: { type: String, required: false },
103
- slug: { type: String, required: false }
102
+ slug: { type: String, required: false },
103
+ lastCachePurgedAt: { type: Date, required: false }
104
104
  }),
105
105
  required: false,
106
106
  _id: false
@@ -0,0 +1,2 @@
1
+ import { UnitDocument } from '../models/units';
2
+ export declare const purgeUnitCache: (unit: UnitDocument) => Promise<void>;
@@ -0,0 +1,40 @@
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 purgeUnitCache = (unit) => __awaiter(void 0, void 0, void 0, function* () {
19
+ var _a, _b, _c;
20
+ //
21
+ 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)) {
22
+ return;
23
+ }
24
+ // Check that last purge date is older than 1 hour
25
+ if (unit.website.lastCachePurgedAt && (0, dayjs_1.default)(unit.website.lastCachePurgedAt).isAfter((0, dayjs_1.default)().subtract(1, 'hour'))) {
26
+ return;
27
+ }
28
+ yield axios_1.default.post(`${process.env.BOOKING_ENGINE_NEXTJS_API_URL}/purge/unit`, {
29
+ unit: unit.website.slug,
30
+ market: unit.market.website.slug
31
+ }, {
32
+ headers: {
33
+ Authorization: `Bearer ${process.env.BOOKING_ENGINE_NEXTJS_API_TOKEN}`
34
+ }
35
+ });
36
+ // Save last purge date
37
+ unit.website.lastCachePurgedAt = new Date();
38
+ yield unit.save();
39
+ });
40
+ 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.90",
3
+ "version": "1.0.92",
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
  }