Skip to content

Commit

Permalink
updates for Bus Fares
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSanEM committed Mar 12, 2020
1 parent eaf7f58 commit 1dde697
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 12 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ npm install @everymundo/short-fare
```

## Usage
### Airline Fares
```js
const { ShortFareToMongo } = require('@everymundo/short-fare/ShortFareToMongo.class')

Expand All @@ -28,3 +29,30 @@ const doc = new ShortFareToMongo({
sourceId: undefined // optional. Field can be used to track the origin of the document
})
```
### Bus fares
```js
const { ShortFareToMongo } = require('@everymundo/short-fare/ShortFareToMongo.class')

const doc = new ShortFareBusToMongo({
tenantCode: 'XX',
departureBusStopId: '345678',
arrivalBusStopId: '234567',
departureCityGeoId: 567890,
arrivalCityGeoId: 345678,
departureCityName: 'Miami',
arrivalCityName: 'Orlando',
outboundDate: '2020-01-01',
inboundDate: '2020-02-01',
currencyCode: 'USD',
journeyType: 'RT', //RT || OW
fareClass: 'E', // E = ECONOMY / B = BUSINESS / F = FIRST
flightType: 'I', // I = INTERNATIONAL / D = DOMESTIC
siteEdition: ShortFareToMongo.formatSiteEdition('en-us'), // not required but enforces the format en_US
totalPrice: 1234.34,
createdAt: new Date(),
updatedAt: new Date(), // optional
isSoldOut: false, // defaults to false
sourceId: undefined // optional. Field can be used to track the origin of the document
})
```

9 changes: 6 additions & 3 deletions ShortFare.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const siteEditionRegExp = /^[a-z]{2}-[A-Z]{2}$/
const airlineIataCodeRegExp = /^[A-Z0-9]{2,3}$/
const _3upperCasedLettersRegExp = /^[A-Z]{3}$/
const dateRegExp = /\d{4}-\d{2}-\d{2}/
const dateRegExp = /^\d{4}-\d{2}-\d{2}/

class ShortFare {
static formatSiteEdition (siteEdition) {
Expand Down Expand Up @@ -71,7 +71,9 @@ class ShortFare {
return this.dd
}

set outboundDate (v) {
set outboundDate (_v) {
const v = _v instanceof Date ? _v.toJSON() : _v

if (!dateRegExp.test(v)) {
throw new Error(`outboundDate [${v}] is not valid`)
}
Expand All @@ -83,7 +85,8 @@ class ShortFare {
return this.rd
}

set inboundDate (v) {
set inboundDate (_v) {
const v = _v instanceof Date ? _v.toJSON() : _v
if (v !== undefined && !dateRegExp.test(v)) {
throw new Error(`outboundDate [${v}] is not valid`)
}
Expand Down
34 changes: 29 additions & 5 deletions ShortFareBus.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ class ShortFareBus extends ShortFare {
this.aCtGeo = undefined // arrivalCityGeoId
}

get tenantCode () {
return super.airlineIataCode
}

set tenantCode (v) {
try {
super.airlineIataCode = v
} catch (e) {
if (e.message.indexOf('airlineIataCode') > -1) {
e.message = e.message.replace('airlineIataCode', 'tenantCode')
}

throw e
}
}

get departureAirportIataCode () {
throw new Error('WRONG FIELD departureAirportIataCode! You must use departureBusStopId for Bus')
}
Expand Down Expand Up @@ -57,8 +73,12 @@ class ShortFareBus extends ShortFare {
}

set departureCityGeoId (v) {
if (Number.isNaN(+v)) {
throw new Error('Invalid departureCityGeoId')
if (v == null) {
return (this.dCtGeo = v)
}

if (v != null && Number.isNaN(+v)) {
throw new Error(`Invalid departureCityGeoId [${v}] is not a Number`)
}

this.dCtGeo = +v
Expand All @@ -69,8 +89,12 @@ class ShortFareBus extends ShortFare {
}

set arrivalCityGeoId (v) {
if (Number.isNaN(+v)) {
throw new Error('Invalid arrivalCityGeoId')
if (v == null) {
return (this.aCtGeo = v)
}

if (v != null && Number.isNaN(+v)) {
throw new Error(`Invalid arrivalCityGeoId [${v}] is not a Number`)
}

this.aCtGeo = +v
Expand Down Expand Up @@ -101,7 +125,7 @@ class ShortFareBus extends ShortFare {
rd: this.rd,
c: this.c,
jt: this.jt,
ft: this.ft,
// ft: this.ft,
se: this.se,
fc: this.fc
}
Expand Down
8 changes: 4 additions & 4 deletions ShortFareBusToMongo.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,21 @@ class ShortFareBusToMongo extends ShortFareBus {
super()

if (doc != null) {
this.tenantCode = doc.tenantCode

this.departureBusStopId = doc.departureBusStopId
this.arrivalBusStopId = doc.arrivalBusStopId

this.departureCityGeo = doc.departureCityGeo
this.arrivalCityGeo = doc.arrivalCityGeo
this.departureCityGeoId = doc.departureCityGeoId
this.arrivalCityGeoId = doc.arrivalCityGeoId
this.departureCityName = doc.departureCityName
this.arrivalCityName = doc.arrivalCityName

this.airlineIataCode = doc.airlineIataCode
this.outboundDate = doc.outboundDate
this.inboundDate = doc.inboundDate
this.currencyCode = doc.currencyCode
this.journeyType = doc.journeyType
this.fareClass = doc.fareClass
this.flightType = doc.flightType
this.siteEdition = doc.siteEdition
this.totalPrice = doc.totalPrice
this.createdAt = doc.createdAt || new Date()
Expand Down

0 comments on commit 1dde697

Please sign in to comment.