Skip to content

Commit

Permalink
Add advanced passenger capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoAdamek committed Aug 23, 2024
1 parent 8e140b0 commit cff0d3b
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tigerbay",
"version": "1.0.0-beta.14",
"version": "1.1.0-beta.1",
"description": "API Client library for TigerBay",
"main": "lib/client.js",
"type": "commonjs",
Expand Down Expand Up @@ -28,7 +28,7 @@
"typescript": "^4.1.3"
},
"dependencies": {
"axios": "^1.6.0",
"axios": "^1.7",
"qs": "^6.9.4"
},
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ export class Client {
return new Customers.Api(this.axios)
}

public customer(id: number): Customers.CustomerAPI {
return new Customers.CustomerAPI(this.axios, id)
}

/**
* Access payment related API actions
*/
Expand Down
3 changes: 2 additions & 1 deletion src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export * as Notes from './models/notes'
export * as Customers from './models/customers'
export * as Payments from './models/payments'
export * as Cache from './models/cache'
export * as Setup from './models/setup'
export * as Setup from './models/setup'
export * as Passengers from './models/passengers'
44 changes: 43 additions & 1 deletion src/models/customers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import qs from "qs";
import { APIGroup, LinkedObject, PatchPayload } from "./common";
import { AxiosInstance } from "axios";
import { PassengerAPIS } from "./passengers";

export interface CustomerSearchRequest {
username?: string
Expand Down Expand Up @@ -46,7 +48,7 @@ export interface CreateCustomerRequest {
DateOfBirth?: Date
}

export type ContactType = "Primary"
export type ContactType = "Primary" | "Emergency" | "Document Addition" | "Next of Kin" | "Other"

export interface CustomerContact {
Title: string
Expand Down Expand Up @@ -129,3 +131,43 @@ export class Api extends APIGroup {
return (await this.axios.post<CustomerContactResponse>(`/sales/customers/${customerId}/contacts`, contact)).data
}
}

export class CustomerAPI extends APIGroup {
private id: number;

constructor(axios: AxiosInstance, id: number) {
super(axios)
this.id = id
}

public get path(): string {
return `/sales/customers/${this.id}`
}

/**
* List contact addresses for a customer
* @param customerId
*/
public async contacts(): Promise<CustomerContactResponse[]> {
return (await this.axios.get<CustomerContactResponse[]>(`${this.path}/contacts`)).data
}

/**
* Get APIS details for a customer
*/
public async getApis(): Promise<PassengerAPIS> {
return (await this.axios.get(`${this.path}/apis`)).data
}

/**
* Update the customer APIS details.
* Merges the given APIs details with the existing ones.
* Any properties in `updates` which are null or undefined will be unchanged.
*/
public async updateApis(updates: Partial<PassengerAPIS>): Promise<void> {
const existing = await this.getApis()
const payload = { ...updates, ...existing }

await this.axios.put(`${this.path}/apis`, payload)
}
}
55 changes: 55 additions & 0 deletions src/models/passengers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { AxiosInstance } from "axios";
import { APIGroup } from "./common";
import { CustomerContact } from "./customers";

export class PassengerAPI extends APIGroup {
private booking: number;
private id: number;

constructor(axios: AxiosInstance, booking: number, passenger: number) {
super(axios)
this.booking = booking
this.id = passenger
}

public async getApis(): Promise<PassengerAPIS> {
return (await this.axios.get(`${this.path}/Apis`)).data
}


public async contacts(): Promise<CustomerContact[]> {
return (await this.axios.get(`${this.path}/Contacts`))
}

/**
* Update the passenger APIS details.
* Merges the given APIs details with the existing ones.
* Any properties in `updates` which are null or undefined will be unchanged.
*/
public async updateApis(updates: Partial<PassengerAPIS>): Promise<void> {
const existing = await this.getApis()
const payload = { ...updates, ...existing }

await this.axios.put(`${this.path}/apis`, payload)
}

/**
* Get the path to the current passenger resource.
*/
public get path(): string {
return `/reservations/${this.booking}/passengers/${this.id}`
}
}


export interface PassengerAPIS {
DocumentType: string;
DocumentNumber: string;
Nationality: string;
PlaceOfIssue: string;
CountryOfResidence: string;
IssueDate: string;
ExpiryDate: string;
DateOfBirth: string;
PlaceOfBirth: string;
}
5 changes: 5 additions & 0 deletions src/models/reservations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Tasks } from "../models";
import { APIGroup, LinkedObject, PassengerAssignment, PatchPayload } from "./common";
import { Note, NoteType } from "./notes";
import { Payment } from "./payments";
import { PassengerAPI } from "./passengers";


export interface FindReservationRequest {
Expand Down Expand Up @@ -569,6 +570,10 @@ export class Api extends APIGroup {
return (await this.axios.get<Passenger[]>(`/sales/reservations/${id}/passengers`)).data
}

public passenger(reservation: number, passenger: number): PassengerAPI {
return new PassengerAPI(this.axios, reservation, passenger)
}

/**
*
* Add a new note to a reservation
Expand Down

0 comments on commit cff0d3b

Please sign in to comment.