whitelabel-db 1.0.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,7 @@
1
+ export { connect } from './libs/database';
2
+ export { Agency } from './models/Agency';
3
+ export { City } from './models/City';
4
+ export { Country } from './models/Country';
5
+ export { Hotel } from './models/Hotel';
6
+ export { User } from './models/User';
7
+ export { Project } from './models/Project';
package/dist/index.js ADDED
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Project = exports.User = exports.Hotel = exports.Country = exports.City = exports.Agency = exports.connect = void 0;
4
+ var database_1 = require("./libs/database");
5
+ Object.defineProperty(exports, "connect", { enumerable: true, get: function () { return database_1.connect; } });
6
+ var Agency_1 = require("./models/Agency");
7
+ Object.defineProperty(exports, "Agency", { enumerable: true, get: function () { return Agency_1.Agency; } });
8
+ var City_1 = require("./models/City");
9
+ Object.defineProperty(exports, "City", { enumerable: true, get: function () { return City_1.City; } });
10
+ var Country_1 = require("./models/Country");
11
+ Object.defineProperty(exports, "Country", { enumerable: true, get: function () { return Country_1.Country; } });
12
+ var Hotel_1 = require("./models/Hotel");
13
+ Object.defineProperty(exports, "Hotel", { enumerable: true, get: function () { return Hotel_1.Hotel; } });
14
+ var User_1 = require("./models/User");
15
+ Object.defineProperty(exports, "User", { enumerable: true, get: function () { return User_1.User; } });
16
+ var Project_1 = require("./models/Project");
17
+ Object.defineProperty(exports, "Project", { enumerable: true, get: function () { return Project_1.Project; } });
@@ -0,0 +1,9 @@
1
+ import { Sequelize } from 'sequelize-typescript';
2
+ interface ConnectionDetails {
3
+ host: string;
4
+ username: string;
5
+ password: string;
6
+ dbname: string;
7
+ }
8
+ export declare const connect: (connectionDetails: ConnectionDetails) => Promise<void | Sequelize>;
9
+ export {};
@@ -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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.connect = void 0;
13
+ const sequelize_typescript_1 = require("sequelize-typescript");
14
+ const User_1 = require("../models/User");
15
+ const Agency_1 = require("../models/Agency");
16
+ const Project_1 = require("../models/Project");
17
+ const Hotel_1 = require("../models/Hotel");
18
+ const connect = (connectionDetails) => __awaiter(void 0, void 0, void 0, function* () {
19
+ const connection = new sequelize_typescript_1.Sequelize({
20
+ dialect: 'postgres',
21
+ host: connectionDetails.host,
22
+ username: connectionDetails.username,
23
+ password: connectionDetails.password,
24
+ database: connectionDetails.dbname,
25
+ logging: false,
26
+ models: [User_1.User, Agency_1.Agency, Project_1.Project, Hotel_1.Hotel],
27
+ });
28
+ return connection
29
+ .authenticate()
30
+ .then(() => {
31
+ console.log('Database connection has been established successfully.');
32
+ return connection.sync();
33
+ })
34
+ .catch((err) => {
35
+ console.error('Unable to connect to the database:', err);
36
+ });
37
+ });
38
+ exports.connect = connect;
@@ -0,0 +1,23 @@
1
+ export interface HotelsRequest {
2
+ timeout: number;
3
+ hotelIds: string;
4
+ checkin: string;
5
+ checkout: string;
6
+ currency: string;
7
+ guestNationality: string;
8
+ adults: number;
9
+ children?: string;
10
+ }
11
+ export interface AvailabilityResult {
12
+ hotelId: string;
13
+ currency: string;
14
+ price: number;
15
+ supplier: string;
16
+ supplierId: number;
17
+ }
18
+ export declare class LiteApiClient {
19
+ private apiKey;
20
+ constructor(apiKey: string);
21
+ getHotels(options: HotelsRequest): Promise<AvailabilityResult[]>;
22
+ getHotelById(hotelId: string): Promise<AvailabilityResult>;
23
+ }
@@ -0,0 +1,44 @@
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.LiteApiClient = void 0;
16
+ const axios_1 = __importDefault(require("axios"));
17
+ const baseUrl = 'https://api.liteapi.travel';
18
+ class LiteApiClient {
19
+ constructor(apiKey) {
20
+ this.apiKey = apiKey;
21
+ }
22
+ getHotels(options) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ return (yield (0, axios_1.default)({
25
+ url: `${baseUrl}/v2.0/hotels`,
26
+ params: options,
27
+ headers: {
28
+ 'X-API-Key': this.apiKey,
29
+ },
30
+ })).data.data;
31
+ });
32
+ }
33
+ getHotelById(hotelId) {
34
+ return __awaiter(this, void 0, void 0, function* () {
35
+ return (yield (0, axios_1.default)({
36
+ url: `${baseUrl}/v2.0/hotels/${hotelId}`,
37
+ headers: {
38
+ 'X-API-Key': this.apiKey,
39
+ },
40
+ })).data.data;
41
+ });
42
+ }
43
+ }
44
+ exports.LiteApiClient = LiteApiClient;
@@ -0,0 +1,9 @@
1
+ import { Model } from 'sequelize-typescript';
2
+ import { User } from './User';
3
+ import { Project } from './Project';
4
+ export declare class Agency extends Model<Partial<Agency>> {
5
+ id: string;
6
+ name: string;
7
+ users?: User[];
8
+ projects?: Project[];
9
+ }
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Agency = void 0;
13
+ const sequelize_typescript_1 = require("sequelize-typescript");
14
+ const User_1 = require("./User");
15
+ const Project_1 = require("./Project");
16
+ let Agency = class Agency extends sequelize_typescript_1.Model {
17
+ };
18
+ exports.Agency = Agency;
19
+ __decorate([
20
+ (0, sequelize_typescript_1.IsUUID)(4),
21
+ sequelize_typescript_1.PrimaryKey,
22
+ (0, sequelize_typescript_1.Column)({
23
+ type: sequelize_typescript_1.DataType.UUID,
24
+ defaultValue: sequelize_typescript_1.DataType.UUIDV4,
25
+ }),
26
+ __metadata("design:type", String)
27
+ ], Agency.prototype, "id", void 0);
28
+ __decorate([
29
+ (0, sequelize_typescript_1.Column)({
30
+ type: sequelize_typescript_1.DataType.STRING,
31
+ allowNull: false,
32
+ }),
33
+ __metadata("design:type", String)
34
+ ], Agency.prototype, "name", void 0);
35
+ __decorate([
36
+ (0, sequelize_typescript_1.HasMany)(() => User_1.User),
37
+ __metadata("design:type", Array)
38
+ ], Agency.prototype, "users", void 0);
39
+ __decorate([
40
+ (0, sequelize_typescript_1.HasMany)(() => Project_1.Project),
41
+ __metadata("design:type", Array)
42
+ ], Agency.prototype, "projects", void 0);
43
+ exports.Agency = Agency = __decorate([
44
+ (0, sequelize_typescript_1.Table)({
45
+ tableName: 'agencies',
46
+ })
47
+ ], Agency);
@@ -0,0 +1,5 @@
1
+ import { Model } from 'sequelize-typescript';
2
+ export declare class City extends Model<Partial<City>> {
3
+ city: string;
4
+ countryCode: string;
5
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.City = void 0;
13
+ const sequelize_typescript_1 = require("sequelize-typescript");
14
+ let City = class City extends sequelize_typescript_1.Model {
15
+ };
16
+ exports.City = City;
17
+ __decorate([
18
+ sequelize_typescript_1.Index,
19
+ (0, sequelize_typescript_1.Column)({
20
+ type: sequelize_typescript_1.DataType.STRING,
21
+ allowNull: false,
22
+ }),
23
+ __metadata("design:type", String)
24
+ ], City.prototype, "city", void 0);
25
+ __decorate([
26
+ sequelize_typescript_1.Index,
27
+ (0, sequelize_typescript_1.Column)({
28
+ type: sequelize_typescript_1.DataType.STRING,
29
+ allowNull: false,
30
+ }),
31
+ __metadata("design:type", String)
32
+ ], City.prototype, "countryCode", void 0);
33
+ exports.City = City = __decorate([
34
+ (0, sequelize_typescript_1.Table)({
35
+ tableName: 'static_cities',
36
+ })
37
+ ], City);
@@ -0,0 +1,5 @@
1
+ import { Model } from 'sequelize-typescript';
2
+ export declare class Country extends Model<Partial<Country>> {
3
+ name: string;
4
+ code: string;
5
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Country = void 0;
13
+ const sequelize_typescript_1 = require("sequelize-typescript");
14
+ let Country = class Country extends sequelize_typescript_1.Model {
15
+ };
16
+ exports.Country = Country;
17
+ __decorate([
18
+ (0, sequelize_typescript_1.Column)({
19
+ type: sequelize_typescript_1.DataType.STRING,
20
+ allowNull: false,
21
+ }),
22
+ __metadata("design:type", String)
23
+ ], Country.prototype, "name", void 0);
24
+ __decorate([
25
+ sequelize_typescript_1.Index,
26
+ (0, sequelize_typescript_1.Column)({
27
+ type: sequelize_typescript_1.DataType.STRING,
28
+ allowNull: false,
29
+ }),
30
+ __metadata("design:type", String)
31
+ ], Country.prototype, "code", void 0);
32
+ exports.Country = Country = __decorate([
33
+ (0, sequelize_typescript_1.Table)({
34
+ tableName: 'static_countries',
35
+ })
36
+ ], Country);
@@ -0,0 +1,17 @@
1
+ import { Model } from 'sequelize-typescript';
2
+ import { AvailabilityResult } from '../libs/liteapi';
3
+ export declare class Hotel extends Model<Partial<Hotel>> {
4
+ id: string;
5
+ name: string;
6
+ hotelDescription: string;
7
+ currency: string;
8
+ country: string;
9
+ city: string;
10
+ latitude: string;
11
+ longitude: string;
12
+ address: string;
13
+ zip: string;
14
+ main_photo: string;
15
+ stars: string;
16
+ rate: AvailabilityResult;
17
+ }
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Hotel = void 0;
13
+ const sequelize_typescript_1 = require("sequelize-typescript");
14
+ let Hotel = class Hotel extends sequelize_typescript_1.Model {
15
+ };
16
+ exports.Hotel = Hotel;
17
+ __decorate([
18
+ sequelize_typescript_1.Index,
19
+ sequelize_typescript_1.PrimaryKey,
20
+ (0, sequelize_typescript_1.Column)({
21
+ type: sequelize_typescript_1.DataType.STRING,
22
+ allowNull: false,
23
+ }),
24
+ __metadata("design:type", String)
25
+ ], Hotel.prototype, "id", void 0);
26
+ __decorate([
27
+ (0, sequelize_typescript_1.Column)({
28
+ type: sequelize_typescript_1.DataType.STRING(512),
29
+ allowNull: false,
30
+ }),
31
+ __metadata("design:type", String)
32
+ ], Hotel.prototype, "name", void 0);
33
+ __decorate([
34
+ (0, sequelize_typescript_1.Column)({
35
+ type: sequelize_typescript_1.DataType.TEXT,
36
+ allowNull: false,
37
+ }),
38
+ __metadata("design:type", String)
39
+ ], Hotel.prototype, "hotelDescription", void 0);
40
+ __decorate([
41
+ (0, sequelize_typescript_1.Column)({
42
+ type: sequelize_typescript_1.DataType.STRING,
43
+ allowNull: false,
44
+ }),
45
+ __metadata("design:type", String)
46
+ ], Hotel.prototype, "currency", void 0);
47
+ __decorate([
48
+ sequelize_typescript_1.Index,
49
+ (0, sequelize_typescript_1.Column)({
50
+ type: sequelize_typescript_1.DataType.STRING,
51
+ allowNull: false,
52
+ }),
53
+ __metadata("design:type", String)
54
+ ], Hotel.prototype, "country", void 0);
55
+ __decorate([
56
+ sequelize_typescript_1.Index,
57
+ (0, sequelize_typescript_1.Column)({
58
+ type: sequelize_typescript_1.DataType.STRING,
59
+ allowNull: false,
60
+ }),
61
+ __metadata("design:type", String)
62
+ ], Hotel.prototype, "city", void 0);
63
+ __decorate([
64
+ sequelize_typescript_1.Index,
65
+ (0, sequelize_typescript_1.Column)({
66
+ type: sequelize_typescript_1.DataType.FLOAT,
67
+ allowNull: false,
68
+ }),
69
+ __metadata("design:type", String)
70
+ ], Hotel.prototype, "latitude", void 0);
71
+ __decorate([
72
+ sequelize_typescript_1.Index,
73
+ (0, sequelize_typescript_1.Column)({
74
+ type: sequelize_typescript_1.DataType.FLOAT,
75
+ allowNull: false,
76
+ }),
77
+ __metadata("design:type", String)
78
+ ], Hotel.prototype, "longitude", void 0);
79
+ __decorate([
80
+ (0, sequelize_typescript_1.Column)({
81
+ type: sequelize_typescript_1.DataType.STRING,
82
+ allowNull: false,
83
+ }),
84
+ __metadata("design:type", String)
85
+ ], Hotel.prototype, "address", void 0);
86
+ __decorate([
87
+ (0, sequelize_typescript_1.Column)({
88
+ type: sequelize_typescript_1.DataType.STRING,
89
+ allowNull: false,
90
+ }),
91
+ __metadata("design:type", String)
92
+ ], Hotel.prototype, "zip", void 0);
93
+ __decorate([
94
+ (0, sequelize_typescript_1.Column)({
95
+ type: sequelize_typescript_1.DataType.STRING,
96
+ allowNull: false,
97
+ }),
98
+ __metadata("design:type", String)
99
+ ], Hotel.prototype, "main_photo", void 0);
100
+ __decorate([
101
+ (0, sequelize_typescript_1.Column)({
102
+ type: sequelize_typescript_1.DataType.STRING,
103
+ allowNull: false,
104
+ }),
105
+ __metadata("design:type", String)
106
+ ], Hotel.prototype, "stars", void 0);
107
+ exports.Hotel = Hotel = __decorate([
108
+ (0, sequelize_typescript_1.Table)({
109
+ tableName: 'static_hotels',
110
+ })
111
+ ], Hotel);
@@ -0,0 +1,11 @@
1
+ import { Model } from 'sequelize-typescript';
2
+ import { Agency } from './Agency';
3
+ export declare class Project extends Model<Partial<Project>> {
4
+ id: string;
5
+ name: string;
6
+ templateName: string;
7
+ domain?: string;
8
+ settings?: object;
9
+ agencyId?: string;
10
+ agency?: Agency;
11
+ }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Project = void 0;
13
+ const sequelize_typescript_1 = require("sequelize-typescript");
14
+ const Agency_1 = require("./Agency");
15
+ let Project = class Project extends sequelize_typescript_1.Model {
16
+ };
17
+ exports.Project = Project;
18
+ __decorate([
19
+ (0, sequelize_typescript_1.IsUUID)(4),
20
+ sequelize_typescript_1.PrimaryKey,
21
+ (0, sequelize_typescript_1.Column)({
22
+ type: sequelize_typescript_1.DataType.UUID,
23
+ defaultValue: sequelize_typescript_1.DataType.UUIDV4,
24
+ }),
25
+ __metadata("design:type", String)
26
+ ], Project.prototype, "id", void 0);
27
+ __decorate([
28
+ (0, sequelize_typescript_1.Column)({
29
+ type: sequelize_typescript_1.DataType.STRING,
30
+ allowNull: false,
31
+ }),
32
+ __metadata("design:type", String)
33
+ ], Project.prototype, "name", void 0);
34
+ __decorate([
35
+ (0, sequelize_typescript_1.Column)({
36
+ type: sequelize_typescript_1.DataType.STRING,
37
+ allowNull: false,
38
+ defaultValue: 'default',
39
+ }),
40
+ __metadata("design:type", String)
41
+ ], Project.prototype, "templateName", void 0);
42
+ __decorate([
43
+ sequelize_typescript_1.Unique,
44
+ sequelize_typescript_1.Index,
45
+ (0, sequelize_typescript_1.Column)({
46
+ type: sequelize_typescript_1.DataType.STRING,
47
+ allowNull: true,
48
+ }),
49
+ __metadata("design:type", String)
50
+ ], Project.prototype, "domain", void 0);
51
+ __decorate([
52
+ (0, sequelize_typescript_1.Column)({
53
+ type: sequelize_typescript_1.DataType.JSONB,
54
+ allowNull: false,
55
+ defaultValue: {},
56
+ }),
57
+ __metadata("design:type", Object)
58
+ ], Project.prototype, "settings", void 0);
59
+ __decorate([
60
+ (0, sequelize_typescript_1.ForeignKey)(() => Agency_1.Agency),
61
+ sequelize_typescript_1.Index,
62
+ (0, sequelize_typescript_1.Column)({
63
+ type: sequelize_typescript_1.DataType.UUID,
64
+ }),
65
+ __metadata("design:type", String)
66
+ ], Project.prototype, "agencyId", void 0);
67
+ __decorate([
68
+ (0, sequelize_typescript_1.BelongsTo)(() => Agency_1.Agency),
69
+ __metadata("design:type", Agency_1.Agency)
70
+ ], Project.prototype, "agency", void 0);
71
+ exports.Project = Project = __decorate([
72
+ (0, sequelize_typescript_1.Table)({
73
+ tableName: 'projects',
74
+ })
75
+ ], Project);
@@ -0,0 +1,11 @@
1
+ import { Model } from 'sequelize-typescript';
2
+ import { Agency } from './Agency';
3
+ export declare class User extends Model<Partial<User>> {
4
+ id: string;
5
+ email: string;
6
+ password: string;
7
+ agencyId?: string;
8
+ agency?: Agency;
9
+ static checkEmail(email: string): Promise<void>;
10
+ generateSession(secret: string): string;
11
+ }
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
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
+ };
20
+ var __importDefault = (this && this.__importDefault) || function (mod) {
21
+ return (mod && mod.__esModule) ? mod : { "default": mod };
22
+ };
23
+ var User_1;
24
+ Object.defineProperty(exports, "__esModule", { value: true });
25
+ exports.User = void 0;
26
+ const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
27
+ const sequelize_typescript_1 = require("sequelize-typescript");
28
+ const Agency_1 = require("./Agency");
29
+ let User = User_1 = class User extends sequelize_typescript_1.Model {
30
+ static checkEmail(email) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ if (yield User_1.findOne({ where: { email } })) {
33
+ throw new Error('This email is already registered to another account.');
34
+ }
35
+ });
36
+ }
37
+ generateSession(secret) {
38
+ return jsonwebtoken_1.default.sign({ id: this.id }, secret, {
39
+ algorithm: 'HS256',
40
+ expiresIn: 86400, // 24 hours
41
+ });
42
+ }
43
+ };
44
+ exports.User = User;
45
+ __decorate([
46
+ (0, sequelize_typescript_1.IsUUID)(4),
47
+ sequelize_typescript_1.PrimaryKey,
48
+ (0, sequelize_typescript_1.Column)({
49
+ type: sequelize_typescript_1.DataType.UUID,
50
+ defaultValue: sequelize_typescript_1.DataType.UUIDV4,
51
+ }),
52
+ __metadata("design:type", String)
53
+ ], User.prototype, "id", void 0);
54
+ __decorate([
55
+ sequelize_typescript_1.Index,
56
+ sequelize_typescript_1.Unique,
57
+ (0, sequelize_typescript_1.Column)({
58
+ type: sequelize_typescript_1.DataType.STRING,
59
+ allowNull: false,
60
+ }),
61
+ __metadata("design:type", String)
62
+ ], User.prototype, "email", void 0);
63
+ __decorate([
64
+ (0, sequelize_typescript_1.Column)({
65
+ type: sequelize_typescript_1.DataType.STRING,
66
+ allowNull: false,
67
+ }),
68
+ __metadata("design:type", String)
69
+ ], User.prototype, "password", void 0);
70
+ __decorate([
71
+ (0, sequelize_typescript_1.ForeignKey)(() => Agency_1.Agency),
72
+ sequelize_typescript_1.Index,
73
+ (0, sequelize_typescript_1.Column)({
74
+ type: sequelize_typescript_1.DataType.UUID,
75
+ }),
76
+ __metadata("design:type", String)
77
+ ], User.prototype, "agencyId", void 0);
78
+ __decorate([
79
+ (0, sequelize_typescript_1.BelongsTo)(() => Agency_1.Agency),
80
+ __metadata("design:type", Agency_1.Agency)
81
+ ], User.prototype, "agency", void 0);
82
+ exports.User = User = User_1 = __decorate([
83
+ (0, sequelize_typescript_1.Table)({
84
+ tableName: 'users',
85
+ })
86
+ ], User);
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "whitelabel-db",
3
+ "version": "1.0.0",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "start": "node dist/index.js",
9
+ "start:dev": "ts-node src/index.ts",
10
+ "build": "tsc"
11
+ },
12
+ "author": "",
13
+ "license": "ISC",
14
+ "devDependencies": {
15
+ "@types/jsonwebtoken": "^9.0.4",
16
+ "@types/node": "^20.8.9",
17
+ "@types/shuffle-array": "^1.0.3",
18
+ "axios": "^1.5.1",
19
+ "eslint": "^8.51.0",
20
+ "eslint-config-prettier": "^9.0.0",
21
+ "eslint-plugin-prettier": "^5.0.1",
22
+ "ts-node": "^10.9.1",
23
+ "typescript": "^5.2.2"
24
+ },
25
+ "dependencies": {
26
+ "@aws-sdk/client-sqs": "^3.438.0",
27
+ "@sentry/node": "^7.74.1",
28
+ "@typescript-eslint/eslint-plugin": "^6.8.0",
29
+ "@typescript-eslint/parser": "^6.8.0",
30
+ "api": "^6.1.1",
31
+ "jsonwebtoken": "^9.0.2",
32
+ "pg": "^8.11.3",
33
+ "pg-hstore": "^2.3.4",
34
+ "promise-limit": "^2.7.0",
35
+ "reflect-metadata": "^0.1.13",
36
+ "sequelize": "^6.33.0",
37
+ "sequelize-typescript": "^2.1.5",
38
+ "shuffle-array": "^1.0.1",
39
+ "sqs-consumer": "^7.4.0"
40
+ },
41
+ "files": [
42
+ "/dist"
43
+ ]
44
+ }