Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ export default class TourManager {
maps (): Modules.Maps.Api {
return new Modules.Maps.Api(this.axios)
}

products (): Modules.Products.Api {
return new Modules.Products.Api(this.axios)
}
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ export * as Images from './modules/images.js'
export * as Locations from './modules/locations.js'
export * as Organizations from './modules/organizations.js'
export * as Maps from './modules/maps.js'
export * as Products from './modules/products.js'
76 changes: 76 additions & 0 deletions src/modules/products.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import type {
Paginated,
PaginatedQuery,
QueryBoolean,
Entity,
Fields
} from './common.js'
import type { AxiosInstance } from 'axios'
import { ApiGroup } from './common.js'
import timestamp from '../annotations/timestamp.js'
import type {Organization} from "./organizations";

type Price = {
currency: string
value: number
}

type Provider = {
id: string
organization: Organization
name: string
descriptorUrl: string
enabled: boolean
}

export interface IProduct extends Entity {
name: string
provider: Provider
groupName: string
description: string | null
category: string
prices: Price[]
}

export class Product implements IProduct {
readonly id!: string
readonly provider!: Provider
readonly name!: string
readonly groupName!: string
readonly description!: string | null
readonly category!: string
readonly prices!: Price[]

private readonly axios: AxiosInstance
@timestamp() readonly updated_at!: Date
@timestamp() readonly created_at!: Date

constructor (data: IProduct, axios: AxiosInstance) {
this.axios = axios
Object.assign(this, data)
}

async list (provider: Provider): Promise<Paginated<Product>> {
const response = (await this.axios.get<Paginated<IProduct>>(`/products`, provider.id))
response.data = response.data.map(p => new Product(p, this.axios))
return response as Paginated<Product>
}

async reserve (id: string): Promise<Product> {
const response = await this.axios.post<IProduct>(`/products/reserve/${id}`)
return new Product(response, this.axios)
}
}

export class Api extends ApiGroup {
async list (provider: Provider): Promise<Paginated<Product>> {
const response = (await this.axios.get<Paginated<IProduct>>(`/products`, provider.id))
response.data = response.data.map(p => new Product(p, this.axios))
return response as Paginated<Product>
}

async reserve (id: string): Promise<Product> {
const response = await this.axios.post<IProduct>(`/products/reserve/${id}`)
return new Product(response, this.axios)
}
}