Skip to content

Commit

Permalink
Merge pull request #10 from octotravel/feat/update-mapping-types
Browse files Browse the repository at this point in the history
Updated mappings
  • Loading branch information
Faboslav authored Jan 17, 2024
2 parents 851e44d + 45d6a9e commit 729f1b5
Show file tree
Hide file tree
Showing 7 changed files with 897 additions and 1,225 deletions.
1,999 changes: 795 additions & 1,204 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"sqlite3": "^5.0.11",
"yup": "^0.32.11",
"dotenv": "^16.0.3",
"@octocloud/generators": "^1.0.1",
"@octocloud/types": "^1.5.11",
"@octocloud/generators": "1.0.2",
"@octocloud/types": "1.5.13",
"@types/jest": "^28.1.6",
"@types/koa": "^2.13.5",
"@types/koa__cors": "^3.3.0",
Expand Down
6 changes: 4 additions & 2 deletions src/services/mapping/GetMappingService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ProductModel } from "@octocloud/generators";
import { MappingModel, ProductModel } from "@octocloud/generators";
import { Mapping } from "@octocloud/types";
import { SpecificResellerGetMappingService } from "./reseller/SpecificResellerGetMappingService";
import { ViatorGetMappingService } from "./reseller/ViatorGetMappingService";
Expand All @@ -17,7 +17,9 @@ export class GetMappingService implements IGetMappingService {
return resellerMappingService.getMapping(productModels);
}

private getMappingServiceForReseller(reseller: Reseller): SpecificResellerGetMappingService {
private getMappingServiceForReseller(
reseller: Reseller,
): SpecificResellerGetMappingService<MappingModel> {
switch (reseller) {
case Reseller.Viator:
return new ViatorGetMappingService();
Expand Down
37 changes: 31 additions & 6 deletions src/services/mapping/reseller/ExpediaGetMappingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,43 @@ import { ResellerStatus } from "@octocloud/types";
import Prando from "prando";
import { Reseller } from "../../../types/Reseller";
import { SpecificResellerGetMappingService } from "./SpecificResellerGetMappingService";
import { DataGenerator } from "../../../generators/DataGenerator";

export class ExpediaGetMappingService implements SpecificResellerGetMappingService {
export class ExpediaMappingModel extends MappingModel {
public readonly expediaTourTime: string;

public constructor(props: {
id: string;
resellerReference: string;
resellerStatus: ResellerStatus;
title: string;
url: string;
webhookUrl: Nullable<string>;
optionRequired: boolean;
unitRequired: boolean;
productId: Nullable<string>;
optionId: Nullable<string>;
unitId: Nullable<string>;
connected: boolean;
expediaTourTime: string;
}) {
super(props);
this.expediaTourTime = props.expediaTourTime;
}
}

export class ExpediaGetMappingService
implements SpecificResellerGetMappingService<ExpediaMappingModel>
{
private readonly connectedProductUuids = [
"9cbd7f33-6b53-45c4-a44b-730605f68753",
"b5c0ab15-6575-4ca4-a39d-a8c7995ccbda",
"bb9eb918-fcb5-4947-9fce-86586bbea111",
"0a8f2ef2-7469-4ef0-99fa-a67132ab0bce",
];

public async getMapping(productModels: ProductModel[]): Promise<MappingModel[]> {
const mappingModels: MappingModel[] = [];
public async getMapping(productModels: ProductModel[]): Promise<ExpediaMappingModel[]> {
const mappingModels: ExpediaMappingModel[] = [];

productModels.forEach((productModel) => {
productModel.optionModels.forEach((optionModel) => {
Expand All @@ -27,9 +53,9 @@ export class ExpediaGetMappingService implements SpecificResellerGetMappingServi
].join("_");

const title = `${productModel.internalName} | ${availabilityLocalStartTime}, ${optionModel.internalName} | ${unitModel.internalName}`;
const random = new Prando(resellerReference);

const mappingModel = new MappingModel({
const mappingModel = new ExpediaMappingModel({
id: DataGenerator.generateUUID(),
resellerReference: resellerReference,
resellerStatus: ResellerStatus.ACTIVE,
title: title,
Expand All @@ -42,7 +68,6 @@ export class ExpediaGetMappingService implements SpecificResellerGetMappingServi
unitId: unitModel.id,
connected: this.connectedProductUuids.includes(productModel.id),
expediaTourTime: availabilityLocalStartTime,
gygPriceOverApi: random.nextBoolean(),
});

mappingModels.push(mappingModel);
Expand Down
34 changes: 30 additions & 4 deletions src/services/mapping/reseller/GetYourGuideGetMappingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,51 @@ import { ProductModel, MappingModel } from "@octocloud/generators";
import { ResellerStatus } from "@octocloud/types";
import Prando from "prando";
import { SpecificResellerGetMappingService } from "./SpecificResellerGetMappingService";
import { DataGenerator } from "../../../generators/DataGenerator";

export class GetYourGuideGetMappingService implements SpecificResellerGetMappingService {
export class GetYourGuideMappingModel extends MappingModel {
public readonly gygPriceOverApi: boolean;

public constructor(props: {
id: string;
resellerReference: string;
resellerStatus: ResellerStatus;
title: string;
url: string;
webhookUrl: Nullable<string>;
optionRequired: boolean;
unitRequired: boolean;
productId: Nullable<string>;
optionId: Nullable<string>;
unitId: Nullable<string>;
connected: boolean;
gygPriceOverApi: boolean;
}) {
super(props);
this.gygPriceOverApi = props.gygPriceOverApi;
}
}

export class GetYourGuideGetMappingService
implements SpecificResellerGetMappingService<GetYourGuideMappingModel>
{
private readonly connectedProductUuids = [
"9cbd7f33-6b53-45c4-a44b-730605f68753",
"b5c0ab15-6575-4ca4-a39d-a8c7995ccbda",
"bb9eb918-fcb5-4947-9fce-86586bbea111",
"0a8f2ef2-7469-4ef0-99fa-a67132ab0bce",
];

public async getMapping(productModels: ProductModel[]): Promise<MappingModel[]> {
public async getMapping(productModels: ProductModel[]): Promise<GetYourGuideMappingModel[]> {
return productModels
.map((productModel) =>
productModel.optionModels.map((optionModel) =>
optionModel.unitModels.map((unitModel) => {
const resellerReference = [productModel.id, optionModel.id].join("-");
const random = new Prando(resellerReference);

return new MappingModel({
return new GetYourGuideMappingModel({
id: DataGenerator.generateUUID(),
resellerReference: resellerReference,
resellerStatus: ResellerStatus.ACTIVE,
title: productModel.internalName,
Expand All @@ -31,7 +58,6 @@ export class GetYourGuideGetMappingService implements SpecificResellerGetMapping
optionId: optionModel.id,
unitId: unitModel.id,
connected: this.connectedProductUuids.includes(productModel.id),
expediaTourTime: null,
gygPriceOverApi: random.nextBoolean(),
});
}),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { MappingModel, ProductModel } from "@octocloud/generators";

export interface SpecificResellerGetMappingService {
getMapping(productModels: ProductModel[]): Promise<MappingModel[]>;
export interface SpecificResellerGetMappingService<
SpecificResellerMappingModel extends MappingModel,
> {
getMapping(productModels: ProductModel[]): Promise<SpecificResellerMappingModel[]>;
}
36 changes: 31 additions & 5 deletions src/services/mapping/reseller/ViatorGetMappingService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,50 @@ import { ProductModel, MappingModel } from "@octocloud/generators";
import { ResellerStatus } from "@octocloud/types";
import Prando from "prando";
import { SpecificResellerGetMappingService } from "./SpecificResellerGetMappingService";
import { DataGenerator } from "../../../generators/DataGenerator";

export class ViatorGetMappingService implements SpecificResellerGetMappingService {
export class ViatorMappingModel extends MappingModel {
public readonly viatorRecurringPriceSync: boolean;

public constructor(props: {
id: string;
resellerReference: string;
resellerStatus: ResellerStatus;
title: string;
url: string;
webhookUrl: Nullable<string>;
optionRequired: boolean;
unitRequired: boolean;
productId: Nullable<string>;
optionId: Nullable<string>;
unitId: Nullable<string>;
connected: boolean;
viatorRecurringPriceSync: boolean;
}) {
super(props);
this.viatorRecurringPriceSync = props.viatorRecurringPriceSync;
}
}

export class ViatorGetMappingService
implements SpecificResellerGetMappingService<ViatorMappingModel>
{
private readonly connectedProductUuids = [
"9cbd7f33-6b53-45c4-a44b-730605f68753",
"b5c0ab15-6575-4ca4-a39d-a8c7995ccbda",
"bb9eb918-fcb5-4947-9fce-86586bbea111",
"0a8f2ef2-7469-4ef0-99fa-a67132ab0bce",
];

public async getMapping(productModels: ProductModel[]): Promise<MappingModel[]> {
public async getMapping(productModels: ProductModel[]): Promise<ViatorMappingModel[]> {
return productModels
.map((productModel) =>
productModel.optionModels.map((optionModel) => {
const resellerReference = productModel.id;
const random = new Prando(resellerReference);

return new MappingModel({
return new ViatorMappingModel({
id: DataGenerator.generateUUID(),
resellerReference: resellerReference,
resellerStatus: ResellerStatus.ACTIVE,
title: productModel.internalName,
Expand All @@ -30,8 +57,7 @@ export class ViatorGetMappingService implements SpecificResellerGetMappingServic
optionId: optionModel.id,
unitId: null,
connected: this.connectedProductUuids.includes(productModel.id),
expediaTourTime: null,
gygPriceOverApi: random.nextBoolean(),
viatorRecurringPriceSync: random.nextBoolean(),
});
}),
)
Expand Down

0 comments on commit 729f1b5

Please sign in to comment.