@vibe-flats/booking-engine-common-server 1.0.91 → 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.
@@ -65,6 +65,7 @@ export interface UnitDocument extends mongoose.Document {
65
65
  website: {
66
66
  description: string;
67
67
  slug: string;
68
+ lastCachePurgedAt?: Date;
68
69
  };
69
70
  deal: {
70
71
  total: number;
@@ -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,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.91",
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
  }