@vibe-flats/booking-engine-common-server 1.0.96 → 1.0.100

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.
@@ -0,0 +1,14 @@
1
+ import mongoose, { Model } from 'mongoose';
2
+ export interface GuestDocument extends mongoose.Document {
3
+ firstName: string;
4
+ lastName: string;
5
+ externalId: string;
6
+ }
7
+ export interface GuestModelInterface extends Model<GuestDocument> {
8
+ findOrCreate(guestData: {
9
+ firstName: string;
10
+ lastName: string;
11
+ externalId: string;
12
+ }): Promise<GuestDocument>;
13
+ }
14
+ export declare const GuestModel: (connection: mongoose.Connection) => GuestModelInterface;
@@ -0,0 +1,38 @@
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.GuestModel = void 0;
16
+ const mongoose_1 = __importDefault(require("mongoose"));
17
+ const schema = new mongoose_1.default.Schema({
18
+ firstName: { type: String, required: true },
19
+ lastName: { type: String, required: true },
20
+ externalId: { type: String, required: true }
21
+ }, {
22
+ timestamps: true,
23
+ versionKey: false
24
+ });
25
+ // Create a unique index on externalId
26
+ schema.index({ externalId: 1 }, { unique: true });
27
+ const GuestModel = (connection) => {
28
+ const model = connection.model('Guest', schema);
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;
37
+ };
38
+ exports.GuestModel = GuestModel;
@@ -3,6 +3,7 @@ import { AreaDocument } from './areas';
3
3
  import { BuildingDocument } from './building';
4
4
  import { CityDocument } from './cities';
5
5
  import { MarketDocument } from './markets';
6
+ import { GuestDocument } from './guests';
6
7
  export type UnitReviewCategory = 'cleanliness' | 'communication' | 'checkin' | 'accuracy' | 'location' | 'value' | 'service';
7
8
  export type UnitReviewPlatform = 'direct' | 'airbnb' | 'vrbo' | 'booking';
8
9
  export interface UnitDocument extends mongoose.Document {
@@ -89,6 +90,7 @@ export interface UnitDocument extends mongoose.Document {
89
90
  reservationId: string;
90
91
  externalId: string;
91
92
  platform: UnitReviewPlatform;
93
+ guest: GuestDocument;
92
94
  categories: {
93
95
  name: UnitReviewCategory;
94
96
  rating: number;
@@ -129,6 +129,7 @@ const schema = new mongoose_1.default.Schema({
129
129
  reservationId: { type: String, required: true },
130
130
  externalId: { type: String, required: true },
131
131
  platform: { type: String, required: true },
132
+ guest: { type: mongoose_1.Schema.Types.ObjectId, ref: 'Guest', required: true },
132
133
  categories: {
133
134
  type: [
134
135
  {
@@ -136,7 +137,7 @@ const schema = new mongoose_1.default.Schema({
136
137
  rating: { type: Number, required: true }
137
138
  }
138
139
  ],
139
- required: false,
140
+ required: true,
140
141
  _id: false
141
142
  }
142
143
  }
@@ -18,4 +18,5 @@ 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").GuestModelInterface;
21
22
  };
@@ -7,12 +7,14 @@ const availability_1 = require("./models/availability");
7
7
  const building_1 = require("./models/building");
8
8
  const areas_1 = require("./models/areas");
9
9
  const markets_1 = require("./models/markets");
10
+ const guests_1 = require("./models/guests");
10
11
  const unitsModels = (connection) => ({
11
12
  MarketModel: (0, markets_1.MarketModel)(connection),
12
13
  CityModel: (0, cities_1.CityModel)(connection),
13
14
  UnitModel: (0, units_1.UnitModel)(connection),
14
15
  AvailabilityModel: (0, availability_1.AvailabilityModel)(connection),
15
16
  BuildingModel: (0, building_1.BuildingModel)(connection),
16
- AreaModel: (0, areas_1.AreaModel)(connection)
17
+ AreaModel: (0, areas_1.AreaModel)(connection),
18
+ GuestModel: (0, guests_1.GuestModel)(connection)
17
19
  });
18
20
  exports.unitsModels = unitsModels;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vibe-flats/booking-engine-common-server",
3
- "version": "1.0.96",
3
+ "version": "1.0.100",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",