Skip to content

Commit

Permalink
Query for term procs now supports getting next cycle
Browse files Browse the repository at this point in the history
* Defaults to current cycle when next is not available
  • Loading branch information
marchchad committed Oct 29, 2020
1 parent 1de1d1e commit 4497ae2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
10 changes: 7 additions & 3 deletions example.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,22 @@ terminalProcedures.currentCycleEffectiveDates().then(c => {
console.log(c)
})

// Also try updateing the Flag property to include one or more of the following:
// Also try updating the Flag property to include one or more of the following:
// A for only those that were Added since the last effective date
// C for only those that were Changed since the last effective date
// D for only those that were Deleted since the last effective date
// Leave empty to get all regardless of if they've been added or changed
terminalProcedures.list('PANC', { flag: [ ], }).then(results => {
// The `getNextCycle` option will get the next cycle if it is available when set to true
// If it is omitted or set to false, the current cycle will be queried
terminalProcedures.list('PANC', { flag: [ ], getNextCycle: true, }).then(results => {
console.log(results)
const out = results.map(tp => {
return {
name: tp.procedure.name,
type: tp.type,
url: tp.procedure.url
url: tp.procedure.url,
effectiveStartDate: tp.effectiveStartDate,
effectiveEndDate: tp.effectiveEndDate,
}
})
console.log(
Expand Down
15 changes: 14 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,20 @@ terminalProcedures.fetchNextCycleCode = fetchNextCycleCode
* @returns {Array} - The scraped terminal procedures
*/
const listOne = async (icao, options) => {
const searchCycle = await fetchCurrentCycleCode()
let searchCycle = null

if (options.getNextCycle === true) {
searchCycle = await fetchNextCycleCode()
}

// If the next cycle is not requested, or it is, but it is not
// available, default to the current cycle
if (searchCycle === null) {
if (options.getNextCycle === true) {
console.warn('Next cycle not available. Retrieving current cycle instead.')
}
searchCycle = await fetchCurrentCycleCode()
}

// Build up a base set of query params
let urlParams = [ 'sort=type', 'dir=asc', `ident=${icao}`, ]
Expand Down

0 comments on commit 4497ae2

Please sign in to comment.