whitelabel-db 1.4.4 → 1.5.0

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,3 @@
1
+ import { QueryInterface } from 'sequelize';
2
+ export declare const up: (queryInterface: QueryInterface) => Promise<void>;
3
+ export declare const down: (queryInterface: QueryInterface) => Promise<void>;
@@ -0,0 +1,107 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.down = exports.up = void 0;
13
+ // Purpose: Bring flight_bookings to parity with bookings — add liteAPI snapshot
14
+ // columns, structured payment metadata, status/cancellation tracking, a
15
+ // contactEmail lookup column, and a nullable guestId FK (column only; guest
16
+ // auth wiring is a separate task — see TODO(guest-flights)).
17
+ const sequelize_1 = require("sequelize");
18
+ const TABLE_NAME = 'flight_bookings';
19
+ const jsonbColumns = [
20
+ 'liteApiBookingData',
21
+ 'liteApiPrebookData',
22
+ 'bookingInputData',
23
+ 'paymentData',
24
+ ];
25
+ const stringColumns = [
26
+ // NOT NULL with '' default — mirrors bookings.bookingStatus / paymentStatus
27
+ { name: 'bookingStatus', allowNull: false, defaultValue: '' },
28
+ { name: 'paymentStatus', allowNull: false, defaultValue: '' },
29
+ // Nullable — mirrors bookings payment columns
30
+ { name: 'paymentProvider', allowNull: true },
31
+ { name: 'paymentMethod', allowNull: true },
32
+ { name: 'refundStatus', allowNull: true },
33
+ { name: 'contactEmail', allowNull: true },
34
+ ];
35
+ const up = (queryInterface) => __awaiter(void 0, void 0, void 0, function* () {
36
+ const tableDescription = yield queryInterface.describeTable(TABLE_NAME);
37
+ const existingColumns = Object.keys(tableDescription);
38
+ // JSONB snapshot/payment columns — NOT NULL, default {}
39
+ for (const name of jsonbColumns) {
40
+ if (!existingColumns.includes(name)) {
41
+ yield queryInterface.addColumn(TABLE_NAME, name, {
42
+ type: sequelize_1.DataTypes.JSONB,
43
+ allowNull: false,
44
+ defaultValue: {},
45
+ });
46
+ }
47
+ }
48
+ // String status/payment columns
49
+ for (const column of stringColumns) {
50
+ if (!existingColumns.includes(column.name)) {
51
+ yield queryInterface.addColumn(TABLE_NAME, column.name, Object.assign({ type: sequelize_1.DataTypes.STRING, allowNull: column.allowNull }, (column.defaultValue !== undefined
52
+ ? { defaultValue: column.defaultValue }
53
+ : {})));
54
+ }
55
+ }
56
+ // cancelledAt timestamp
57
+ if (!existingColumns.includes('cancelledAt')) {
58
+ yield queryInterface.addColumn(TABLE_NAME, 'cancelledAt', {
59
+ type: sequelize_1.DataTypes.DATE,
60
+ allowNull: true,
61
+ });
62
+ }
63
+ // guestId FK → guests.id (nullable, column only; not wired this phase)
64
+ if (!existingColumns.includes('guestId')) {
65
+ yield queryInterface.addColumn(TABLE_NAME, 'guestId', {
66
+ type: sequelize_1.DataTypes.UUID,
67
+ allowNull: true,
68
+ references: {
69
+ model: 'guests',
70
+ key: 'id',
71
+ },
72
+ onUpdate: 'CASCADE',
73
+ onDelete: 'SET NULL',
74
+ });
75
+ }
76
+ // Indexes for lookup columns (fail gracefully if they already exist)
77
+ const addIndexSafe = (columns, name) => __awaiter(void 0, void 0, void 0, function* () {
78
+ try {
79
+ yield queryInterface.addIndex(TABLE_NAME, columns, { name });
80
+ }
81
+ catch (error) {
82
+ const message = error instanceof Error ? error.message : String(error);
83
+ if (!message.includes('already exists')) {
84
+ throw error;
85
+ }
86
+ }
87
+ });
88
+ yield addIndexSafe(['contactEmail'], 'idx_flight_bookings_contact_email');
89
+ yield addIndexSafe(['guestId'], 'idx_flight_bookings_guest_id');
90
+ });
91
+ exports.up = up;
92
+ const down = (queryInterface) => __awaiter(void 0, void 0, void 0, function* () {
93
+ const tableDescription = yield queryInterface.describeTable(TABLE_NAME);
94
+ const existingColumns = Object.keys(tableDescription);
95
+ const allColumns = [
96
+ ...jsonbColumns,
97
+ ...stringColumns.map((c) => c.name),
98
+ 'cancelledAt',
99
+ 'guestId',
100
+ ];
101
+ for (const name of allColumns) {
102
+ if (existingColumns.includes(name)) {
103
+ yield queryInterface.removeColumn(TABLE_NAME, name);
104
+ }
105
+ }
106
+ });
107
+ exports.down = down;
@@ -1,5 +1,6 @@
1
1
  import { Model } from 'sequelize-typescript';
2
2
  import { Project } from './Project';
3
+ import { Guest } from './Guest';
3
4
  export declare class FlightBooking extends Model<Partial<FlightBooking>> {
4
5
  id: string;
5
6
  bookingId: string;
@@ -7,6 +8,19 @@ export declare class FlightBooking extends Model<Partial<FlightBooking>> {
7
8
  project?: Project;
8
9
  ticketedEmailSent: boolean;
9
10
  cancelledEmailSent: boolean;
11
+ liteApiBookingData?: object;
12
+ liteApiPrebookData?: object;
13
+ bookingInputData?: object;
14
+ paymentData?: object;
15
+ bookingStatus?: string;
16
+ paymentStatus?: string;
17
+ paymentProvider?: string;
18
+ paymentMethod?: string;
19
+ refundStatus?: string;
20
+ cancelledAt?: Date;
21
+ contactEmail?: string;
22
+ guestId?: string;
23
+ guest?: Guest;
10
24
  createdAt: Date;
11
25
  updatedAt: Date;
12
26
  }
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.FlightBooking = void 0;
13
13
  const sequelize_typescript_1 = require("sequelize-typescript");
14
14
  const Project_1 = require("./Project");
15
+ const Guest_1 = require("./Guest");
15
16
  let FlightBooking = class FlightBooking extends sequelize_typescript_1.Model {
16
17
  };
17
18
  exports.FlightBooking = FlightBooking;
@@ -60,6 +61,103 @@ __decorate([
60
61
  }),
61
62
  __metadata("design:type", Boolean)
62
63
  ], FlightBooking.prototype, "cancelledEmailSent", void 0);
64
+ __decorate([
65
+ (0, sequelize_typescript_1.Column)({
66
+ type: sequelize_typescript_1.DataType.JSONB,
67
+ allowNull: false,
68
+ defaultValue: {},
69
+ }),
70
+ __metadata("design:type", Object)
71
+ ], FlightBooking.prototype, "liteApiBookingData", void 0);
72
+ __decorate([
73
+ (0, sequelize_typescript_1.Column)({
74
+ type: sequelize_typescript_1.DataType.JSONB,
75
+ allowNull: false,
76
+ defaultValue: {},
77
+ }),
78
+ __metadata("design:type", Object)
79
+ ], FlightBooking.prototype, "liteApiPrebookData", void 0);
80
+ __decorate([
81
+ (0, sequelize_typescript_1.Column)({
82
+ type: sequelize_typescript_1.DataType.JSONB,
83
+ allowNull: false,
84
+ defaultValue: {},
85
+ }),
86
+ __metadata("design:type", Object)
87
+ ], FlightBooking.prototype, "bookingInputData", void 0);
88
+ __decorate([
89
+ (0, sequelize_typescript_1.Column)({
90
+ type: sequelize_typescript_1.DataType.JSONB,
91
+ allowNull: false,
92
+ defaultValue: {},
93
+ }),
94
+ __metadata("design:type", Object)
95
+ ], FlightBooking.prototype, "paymentData", void 0);
96
+ __decorate([
97
+ (0, sequelize_typescript_1.Column)({
98
+ type: sequelize_typescript_1.DataType.STRING,
99
+ allowNull: false,
100
+ defaultValue: '',
101
+ }),
102
+ __metadata("design:type", String)
103
+ ], FlightBooking.prototype, "bookingStatus", void 0);
104
+ __decorate([
105
+ (0, sequelize_typescript_1.Column)({
106
+ type: sequelize_typescript_1.DataType.STRING,
107
+ allowNull: false,
108
+ defaultValue: '',
109
+ }),
110
+ __metadata("design:type", String)
111
+ ], FlightBooking.prototype, "paymentStatus", void 0);
112
+ __decorate([
113
+ (0, sequelize_typescript_1.Column)({
114
+ type: sequelize_typescript_1.DataType.STRING,
115
+ allowNull: true,
116
+ }),
117
+ __metadata("design:type", String)
118
+ ], FlightBooking.prototype, "paymentProvider", void 0);
119
+ __decorate([
120
+ (0, sequelize_typescript_1.Column)({
121
+ type: sequelize_typescript_1.DataType.STRING,
122
+ allowNull: true,
123
+ }),
124
+ __metadata("design:type", String)
125
+ ], FlightBooking.prototype, "paymentMethod", void 0);
126
+ __decorate([
127
+ (0, sequelize_typescript_1.Column)({
128
+ type: sequelize_typescript_1.DataType.STRING,
129
+ allowNull: true,
130
+ }),
131
+ __metadata("design:type", String)
132
+ ], FlightBooking.prototype, "refundStatus", void 0);
133
+ __decorate([
134
+ (0, sequelize_typescript_1.Column)({
135
+ type: sequelize_typescript_1.DataType.DATE,
136
+ allowNull: true,
137
+ }),
138
+ __metadata("design:type", Date)
139
+ ], FlightBooking.prototype, "cancelledAt", void 0);
140
+ __decorate([
141
+ sequelize_typescript_1.Index,
142
+ (0, sequelize_typescript_1.Column)({
143
+ type: sequelize_typescript_1.DataType.STRING,
144
+ allowNull: true,
145
+ }),
146
+ __metadata("design:type", String)
147
+ ], FlightBooking.prototype, "contactEmail", void 0);
148
+ __decorate([
149
+ (0, sequelize_typescript_1.ForeignKey)(() => Guest_1.Guest),
150
+ sequelize_typescript_1.Index,
151
+ (0, sequelize_typescript_1.Column)({
152
+ type: sequelize_typescript_1.DataType.UUID,
153
+ allowNull: true,
154
+ }),
155
+ __metadata("design:type", String)
156
+ ], FlightBooking.prototype, "guestId", void 0);
157
+ __decorate([
158
+ (0, sequelize_typescript_1.BelongsTo)(() => Guest_1.Guest),
159
+ __metadata("design:type", Guest_1.Guest)
160
+ ], FlightBooking.prototype, "guest", void 0);
63
161
  __decorate([
64
162
  (0, sequelize_typescript_1.Column)({
65
163
  type: sequelize_typescript_1.DataType.DATE,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whitelabel-db",
3
- "version": "1.4.4",
3
+ "version": "1.5.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",