-
Notifications
You must be signed in to change notification settings - Fork 8
/
GetVehicleTypesForMakeId.ts
90 lines (80 loc) · 2.65 KB
/
GetVehicleTypesForMakeId.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/**
* @module api/endpoints/GetVehicleTypesForMakeId
* @category API Endpoints
*/
import { useNHTSA } from '@/api'
import { catchInvalidArguments, rejectWithError } from '@/utils'
import type { IArgToValidate, NhtsaResponse } from '@/types'
/**
* ::: tip :bulb: More Information
* See: [GetVehicleTypesForMakeId Documentation](/api/endpoints/get-vehicle-types-for-make-id)
* :::
*
* `GetVehicleTypesForMakeId` returns the Models in the vPIC dataset for a specified Make
* whose ID is equal to the `makeID` in the vPIC Dataset.
*
* You can get `makeID`s via `MAKE_ID` key in Results objects of the following endpoints:
* - `GetAllMakes` endpoint
* - `GetMakeForManufacturer` endpoint
* - `GetModelsForMake` endpoint
* - `GetModelsForMakeYear` endpoint
*
* You can get `makeID`s via `MakeID` key in Results objects of the following endpoints:
* - `DecodeVinValues`
* - `DecodeVinValuesBatch`
*
* You can get `makeID`s via `ValueId` key in Results objects of the following endpoints.
* One of the objects in the `Results` array will contain both `Variable: "Make"` and
* `VariableId: 26`. The `ValueId` key in that same object is the `makeID` for use in this
* endpoint.
* - `DecodeVin`
* - `DecodeVinExtended`
*
* @param {(string|number)} makeId - Make ID to search
* @param {boolean} [doFetch=true] - Whether to fetch the data or just return the URL
* (default: `true`)
* @returns {(Promise<NhtsaResponse<GetVehicleTypesForMakeIdResults> | string>)} - Api Response
* `object` -or- url `string` if `doFetch = false`
*/
function GetVehicleTypesForMakeId(
makeId: string | number,
doFetch?: true
): Promise<NhtsaResponse<GetVehicleTypesForMakeIdResults>>
function GetVehicleTypesForMakeId(
makeId: string | number,
doFetch: false
): Promise<string>
async function GetVehicleTypesForMakeId(
makeId: string | number,
doFetch = true
): Promise<NhtsaResponse<GetVehicleTypesForMakeIdResults> | string> {
const endpointName = 'GetVehicleTypesForMakeId'
try {
const args: IArgToValidate[] = [
{
name: 'makeId',
value: makeId,
required: true,
types: ['string', 'number'],
},
]
catchInvalidArguments({ args })
const { get, createCachedUrl, getCachedUrl } = useNHTSA()
createCachedUrl({ endpointName, path: makeId.toString() })
if (!doFetch) {
return getCachedUrl()
} else {
return get()
}
} catch (error) {
return rejectWithError(error)
}
}
export { GetVehicleTypesForMakeId }
/**
* Objects found in the `Results` array of `GetVehicleTypesForMakeId` endpoint response.
*/
export type GetVehicleTypesForMakeIdResults = {
VehicleTypeId: number
VehicleTypeName: string
}