whitelabel-db 1.1.56 → 1.1.58
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/dist/libs/translation.d.ts +4 -0
- package/dist/libs/translation.js +21 -0
- package/dist/migrations/001-add-table-user1-test.js +2 -2
- package/dist/migrations/002-add-hotel-accessibility-columns.js +0 -2
- package/dist/migrations/003-add-accessibility-column-certificate-html.js +0 -2
- package/dist/migrations/004-add-hotels-columns.js +0 -2
- package/dist/migrations/005-add-translations-columns.js +0 -2
- package/dist/migrations/006-add-rates-columns.js +0 -2
- package/dist/migrations/007-add-user-columns.js +0 -2
- package/dist/migrations/008-add-hotel-column.d.ts +3 -0
- package/dist/migrations/008-add-hotel-column.js +39 -0
- package/dist/models/Hotel.d.ts +8 -0
- package/dist/models/Hotel.js +113 -0
- package/package.json +1 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getTranslationFallback = void 0;
|
|
4
|
+
const sequelize_1 = require("sequelize");
|
|
5
|
+
const HotelTranslation_1 = require("../models/HotelTranslation");
|
|
6
|
+
function getTranslationFallback(language = 'en', attributes) {
|
|
7
|
+
return {
|
|
8
|
+
include: [
|
|
9
|
+
{
|
|
10
|
+
model: HotelTranslation_1.HotelTranslation,
|
|
11
|
+
as: 'translations',
|
|
12
|
+
attributes,
|
|
13
|
+
where: {
|
|
14
|
+
[sequelize_1.Op.or]: [{ language }],
|
|
15
|
+
},
|
|
16
|
+
required: false,
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
exports.getTranslationFallback = getTranslationFallback;
|
|
@@ -36,7 +36,7 @@ const up = (queryInterface) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
36
36
|
console.log('Table user1 already exists, skipping.');
|
|
37
37
|
}
|
|
38
38
|
else {
|
|
39
|
-
|
|
39
|
+
console.error('Error while creating table user1:', error.message);
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
});
|
|
@@ -51,7 +51,7 @@ const down = (queryInterface) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
51
51
|
console.log('Table user1 does not exist, skipping.');
|
|
52
52
|
}
|
|
53
53
|
else {
|
|
54
|
-
|
|
54
|
+
console.error('Error while creating table user1:', error.message);
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
});
|
|
@@ -88,7 +88,6 @@ const up = (queryInterface) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
88
88
|
}
|
|
89
89
|
catch (error) {
|
|
90
90
|
console.error('Error while adding columns or indexes:', error.message);
|
|
91
|
-
throw error; // Re-throw to ensure migration failure is logged and handled.
|
|
92
91
|
}
|
|
93
92
|
});
|
|
94
93
|
exports.up = up;
|
|
@@ -108,7 +107,6 @@ const down = (queryInterface) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
108
107
|
}
|
|
109
108
|
catch (error) {
|
|
110
109
|
console.error('Error while removing columns or indexes:', error.message);
|
|
111
|
-
throw error; // Re-throw to ensure migration failure is logged and handled.
|
|
112
110
|
}
|
|
113
111
|
});
|
|
114
112
|
exports.down = down;
|
|
@@ -28,7 +28,6 @@ const up = (queryInterface) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
28
28
|
}
|
|
29
29
|
catch (error) {
|
|
30
30
|
console.error('Error while adding columns or indexes:', error.message);
|
|
31
|
-
throw error; // Re-throw to ensure migration failure is logged and handled.
|
|
32
31
|
}
|
|
33
32
|
});
|
|
34
33
|
exports.up = up;
|
|
@@ -42,7 +41,6 @@ const down = (queryInterface) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
42
41
|
}
|
|
43
42
|
catch (error) {
|
|
44
43
|
console.error('Error while removing columns or indexes:', error.message);
|
|
45
|
-
throw error; // Re-throw to ensure migration failure is logged and handled.
|
|
46
44
|
}
|
|
47
45
|
});
|
|
48
46
|
exports.down = down;
|
|
@@ -33,7 +33,6 @@ const up = (queryInterface) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
33
33
|
}
|
|
34
34
|
catch (error) {
|
|
35
35
|
console.error('Error while adding columns:', error.message);
|
|
36
|
-
throw error; // Re-throw to ensure migration failure is logged and handled.
|
|
37
36
|
}
|
|
38
37
|
});
|
|
39
38
|
exports.up = up;
|
|
@@ -48,7 +47,6 @@ const down = (queryInterface) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
48
47
|
}
|
|
49
48
|
catch (error) {
|
|
50
49
|
console.error('Error while removing columns:', error.message);
|
|
51
|
-
throw error; // Re-throw to ensure migration failure is logged and handled.
|
|
52
50
|
}
|
|
53
51
|
});
|
|
54
52
|
exports.down = down;
|
|
@@ -61,7 +61,6 @@ const up = (queryInterface) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
61
61
|
}
|
|
62
62
|
catch (error) {
|
|
63
63
|
console.error('Error in migration:', error.message);
|
|
64
|
-
throw error;
|
|
65
64
|
}
|
|
66
65
|
});
|
|
67
66
|
exports.up = up;
|
|
@@ -97,7 +96,6 @@ const down = (queryInterface) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
97
96
|
}
|
|
98
97
|
catch (error) {
|
|
99
98
|
console.error('Error in rollback:', error.message);
|
|
100
|
-
throw error;
|
|
101
99
|
}
|
|
102
100
|
});
|
|
103
101
|
exports.down = down;
|
|
@@ -28,7 +28,6 @@ const up = (queryInterface) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
28
28
|
}
|
|
29
29
|
catch (error) {
|
|
30
30
|
console.error('Error while adding columns:', error.message);
|
|
31
|
-
throw error; // Re-throw to ensure migration failure is logged and handled.
|
|
32
31
|
}
|
|
33
32
|
});
|
|
34
33
|
exports.up = up;
|
|
@@ -43,7 +42,6 @@ const down = (queryInterface) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
43
42
|
}
|
|
44
43
|
catch (error) {
|
|
45
44
|
console.error('Error while removing columns:', error.message);
|
|
46
|
-
throw error; // Re-throw to ensure migration failure is logged and handled.
|
|
47
45
|
}
|
|
48
46
|
});
|
|
49
47
|
exports.down = down;
|
|
@@ -34,7 +34,6 @@ const up = (queryInterface) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
34
34
|
}
|
|
35
35
|
catch (error) {
|
|
36
36
|
console.error('Error while adding columns:', error.message);
|
|
37
|
-
throw error; // Re-throw to ensure migration failure is logged and handled.
|
|
38
37
|
}
|
|
39
38
|
});
|
|
40
39
|
exports.up = up;
|
|
@@ -49,7 +48,6 @@ const down = (queryInterface) => __awaiter(void 0, void 0, void 0, function* ()
|
|
|
49
48
|
}
|
|
50
49
|
catch (error) {
|
|
51
50
|
console.error('Error while removing columns:', error.message);
|
|
52
|
-
throw error; // Re-throw to ensure migration failure is logged and handled.
|
|
53
51
|
}
|
|
54
52
|
});
|
|
55
53
|
exports.down = down;
|
|
@@ -0,0 +1,39 @@
|
|
|
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: Add parking column to static_hotels table.
|
|
14
|
+
const sequelize_1 = require("sequelize");
|
|
15
|
+
const up = (queryInterface) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
try {
|
|
17
|
+
// Add all columns in parallel
|
|
18
|
+
yield queryInterface.addColumn('static_hotels', 'parking', {
|
|
19
|
+
type: sequelize_1.DataTypes.STRING,
|
|
20
|
+
allowNull: true,
|
|
21
|
+
});
|
|
22
|
+
console.log('All columns added successfully.');
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
console.error('Error while adding columns:', error.message);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
exports.up = up;
|
|
29
|
+
const down = (queryInterface) => __awaiter(void 0, void 0, void 0, function* () {
|
|
30
|
+
try {
|
|
31
|
+
// Remove columns
|
|
32
|
+
yield queryInterface.removeColumn('static_hotels', 'parking');
|
|
33
|
+
console.log('All columns removed successfully.');
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.error('Error while removing columns:', error.message);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
exports.down = down;
|
package/dist/models/Hotel.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Model } from 'sequelize-typescript';
|
|
2
2
|
import { AvailabilityResult } from '../libs/liteapi';
|
|
3
3
|
import { HotelAccessibility } from './HotelAccessibility';
|
|
4
|
+
import { HotelTranslation } from './HotelTranslation';
|
|
4
5
|
export type HotelImage = {
|
|
5
6
|
url: string;
|
|
6
7
|
thumbnailUrl: string;
|
|
@@ -101,5 +102,12 @@ export declare class Hotel extends Model<Partial<Hotel>> {
|
|
|
101
102
|
bestSeller: boolean;
|
|
102
103
|
reviewSentiment: ReviewSentiment;
|
|
103
104
|
isAccessible: boolean;
|
|
105
|
+
parking?: string;
|
|
104
106
|
accessibility: HotelAccessibility;
|
|
107
|
+
translations: HotelTranslation[];
|
|
108
|
+
static includeTranslations(options: any, language?: string): any;
|
|
109
|
+
static applyTranslations(hotel: Hotel): Hotel;
|
|
110
|
+
static findOneWithTranslation(options: any, language?: string): Promise<Hotel>;
|
|
111
|
+
static findByPkWithTranslation(id: number | string, options?: any, language?: string): Promise<Hotel>;
|
|
112
|
+
static findAllWithTranslation(options: any, language?: string): Promise<Hotel[]>;
|
|
105
113
|
}
|
package/dist/models/Hotel.js
CHANGED
|
@@ -8,11 +8,113 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
|
|
|
8
8
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
9
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
10
|
};
|
|
11
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
12
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
13
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
14
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
15
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
16
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
17
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
18
|
+
});
|
|
19
|
+
};
|
|
11
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
21
|
exports.Hotel = void 0;
|
|
13
22
|
const sequelize_typescript_1 = require("sequelize-typescript");
|
|
14
23
|
const HotelAccessibility_1 = require("./HotelAccessibility");
|
|
24
|
+
const HotelTranslation_1 = require("./HotelTranslation");
|
|
15
25
|
let Hotel = class Hotel extends sequelize_typescript_1.Model {
|
|
26
|
+
// Include translations in the options
|
|
27
|
+
static includeTranslations(options, language) {
|
|
28
|
+
if (language && language !== 'en') {
|
|
29
|
+
options.include = options.include || [];
|
|
30
|
+
options.include.push({
|
|
31
|
+
model: HotelTranslation_1.HotelTranslation,
|
|
32
|
+
as: 'translations',
|
|
33
|
+
where: { language },
|
|
34
|
+
required: false,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
return options;
|
|
38
|
+
}
|
|
39
|
+
static applyTranslations(hotel) {
|
|
40
|
+
if (!hotel)
|
|
41
|
+
return hotel;
|
|
42
|
+
// Check if translations exist in normal object/array form
|
|
43
|
+
const hasObjectTranslations = hotel.translations &&
|
|
44
|
+
((Array.isArray(hotel.translations) && hotel.translations.length > 0) ||
|
|
45
|
+
(typeof hotel.translations === 'object' &&
|
|
46
|
+
Object.keys(hotel.translations).length > 0));
|
|
47
|
+
// Check if translations exist in dot-notation format (e.g., 'translations.address')
|
|
48
|
+
const hasDotNotationTranslations = Object.keys(hotel).some((key) => key.startsWith('translations.'));
|
|
49
|
+
// If no valid translations in any format, return the hotel as is
|
|
50
|
+
if (!hasObjectTranslations && !hasDotNotationTranslations) {
|
|
51
|
+
return hotel;
|
|
52
|
+
}
|
|
53
|
+
let translation = {};
|
|
54
|
+
if (hasObjectTranslations) {
|
|
55
|
+
// Extract normal translations (array or object)
|
|
56
|
+
translation = Array.isArray(hotel.translations)
|
|
57
|
+
? hotel.translations[0]
|
|
58
|
+
: hotel.translations;
|
|
59
|
+
}
|
|
60
|
+
else if (hasDotNotationTranslations) {
|
|
61
|
+
// Convert dot-notation translations into an object
|
|
62
|
+
translation = Object.keys(hotel)
|
|
63
|
+
.filter((key) => key.startsWith('translations.'))
|
|
64
|
+
.reduce((acc, key) => {
|
|
65
|
+
const cleanKey = key.replace('translations.', ''); // Remove 'translations.' prefix
|
|
66
|
+
acc[cleanKey] = hotel[key]; // Assign extracted value
|
|
67
|
+
return acc;
|
|
68
|
+
}, {});
|
|
69
|
+
}
|
|
70
|
+
// Helper function to get translated value or fallback
|
|
71
|
+
const getNestedValue = (key) => { var _a; return (_a = translation[key]) !== null && _a !== void 0 ? _a : hotel[key]; };
|
|
72
|
+
return Object.assign(hotel, {
|
|
73
|
+
name: getNestedValue('name'),
|
|
74
|
+
hotelDescription: getNestedValue('hotelDescription'),
|
|
75
|
+
markdownDescription: getNestedValue('markdownDescription'),
|
|
76
|
+
importantInfo: getNestedValue('importantInfo'),
|
|
77
|
+
address: getNestedValue('address'),
|
|
78
|
+
country: getNestedValue('country'),
|
|
79
|
+
city: getNestedValue('city'),
|
|
80
|
+
facilities: getNestedValue('facilities'),
|
|
81
|
+
policies: getNestedValue('policies'),
|
|
82
|
+
rooms: getNestedValue('rooms'),
|
|
83
|
+
reviews: getNestedValue('reviews'),
|
|
84
|
+
hotelType: getNestedValue('hotelType'),
|
|
85
|
+
parking: getNestedValue('parking'),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
static findOneWithTranslation(options, language) {
|
|
89
|
+
const _super = Object.create(null, {
|
|
90
|
+
findOne: { get: () => super.findOne }
|
|
91
|
+
});
|
|
92
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
+
options = this.includeTranslations(options, language);
|
|
94
|
+
const hotel = (yield _super.findOne.call(this, options));
|
|
95
|
+
return this.applyTranslations(hotel);
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
static findByPkWithTranslation(id, options = {}, language) {
|
|
99
|
+
const _super = Object.create(null, {
|
|
100
|
+
findByPk: { get: () => super.findByPk }
|
|
101
|
+
});
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
options = this.includeTranslations(options, language);
|
|
104
|
+
const hotel = (yield _super.findByPk.call(this, id, options));
|
|
105
|
+
return this.applyTranslations(hotel);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
static findAllWithTranslation(options, language) {
|
|
109
|
+
const _super = Object.create(null, {
|
|
110
|
+
findAll: { get: () => super.findAll }
|
|
111
|
+
});
|
|
112
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
113
|
+
options = this.includeTranslations(options, language);
|
|
114
|
+
const hotels = (yield _super.findAll.call(this, options));
|
|
115
|
+
return hotels.map((hotel) => this.applyTranslations(hotel));
|
|
116
|
+
});
|
|
117
|
+
}
|
|
16
118
|
};
|
|
17
119
|
exports.Hotel = Hotel;
|
|
18
120
|
__decorate([
|
|
@@ -297,10 +399,21 @@ __decorate([
|
|
|
297
399
|
}),
|
|
298
400
|
__metadata("design:type", Boolean)
|
|
299
401
|
], Hotel.prototype, "isAccessible", void 0);
|
|
402
|
+
__decorate([
|
|
403
|
+
(0, sequelize_typescript_1.Column)({
|
|
404
|
+
type: sequelize_typescript_1.DataType.STRING,
|
|
405
|
+
allowNull: true,
|
|
406
|
+
}),
|
|
407
|
+
__metadata("design:type", String)
|
|
408
|
+
], Hotel.prototype, "parking", void 0);
|
|
300
409
|
__decorate([
|
|
301
410
|
(0, sequelize_typescript_1.HasOne)(() => HotelAccessibility_1.HotelAccessibility),
|
|
302
411
|
__metadata("design:type", HotelAccessibility_1.HotelAccessibility)
|
|
303
412
|
], Hotel.prototype, "accessibility", void 0);
|
|
413
|
+
__decorate([
|
|
414
|
+
(0, sequelize_typescript_1.HasMany)(() => HotelTranslation_1.HotelTranslation),
|
|
415
|
+
__metadata("design:type", Array)
|
|
416
|
+
], Hotel.prototype, "translations", void 0);
|
|
304
417
|
exports.Hotel = Hotel = __decorate([
|
|
305
418
|
(0, sequelize_typescript_1.Table)({
|
|
306
419
|
tableName: 'static_hotels',
|