Skip to content

Commit c45197c

Browse files
committed
feat: add cycle information endpoint utility
1 parent 6e3833a commit c45197c

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

packages/amdb/src/api/getAmdbCycle.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Logger } from "@navigraph/app"
2+
import { isAxiosError, navigraphRequest } from "@navigraph/auth"
3+
import { getAmdbApiRoot } from "../constants"
4+
import { AmdbCycleResult } from "../types"
5+
6+
/**
7+
* Fetches information about the currently active cycle
8+
* @returns A record conntaining the cycle number along with start and end dates.
9+
*/
10+
export default async function getAmdbCycle() {
11+
const result = await navigraphRequest
12+
.get<AmdbCycleResult>(`${getAmdbApiRoot()}/cycle`)
13+
.catch((e: unknown) => Logger.err("Failed to fetch amdb cycle. Reason:", isAxiosError(e) ? e.message : e))
14+
15+
return result?.data || null
16+
}

packages/amdb/src/constants.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
import { getDefaultAppDomain } from "@navigraph/app"
22

33
export const getAmdbApiRoot = () => `https://amdb.api.${getDefaultAppDomain()}/v1`
4-
export const getInfoApiRoot = () => `https://amdb.api.${getDefaultAppDomain()}/info`

packages/amdb/src/lib/getAmdbAPI.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { getApp, Logger, NotInitializedError, Scope } from "@navigraph/app"
2+
import getAmdbCycle from "../api/getAmdbCycle"
23
import getAmdbLayer from "../api/getAmdbLayer"
34
import getAmdbLayers from "../api/getAmdbLayers"
45
import searchAmdb from "../api/searchAmdb"
@@ -18,6 +19,7 @@ export const getAmdbAPI = () => {
1819
return {
1920
getAmdbLayer,
2021
getAmdbLayers,
22+
getAmdbCycle,
2123
searchAmdb,
2224
}
2325
}

packages/amdb/src/types/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,10 @@ export interface AmdbSearchResult {
116116
name: string
117117
coordinates: { lat: number; lon: number }
118118
}
119+
120+
export interface AmdbCycleResult {
121+
cycle_start_date: string
122+
cycle_end_date: string
123+
import_time: string
124+
airac_cycle: number
125+
}

0 commit comments

Comments
 (0)