-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvehicle.js
58 lines (51 loc) · 1.53 KB
/
vehicle.js
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
'use strict';
const nhtsa = require('./nhtsa');
const querySymbol = Symbol('query');
/**
* Class representing a vehicle.
*
*/
class Vehicle {
/**
*
* Creates a vehicle instance
* @constructor
* @param {object} queryData - nhtsa api request paramaters.
* @param {number} queryData.year - year of vehicle model.
* @param {string} queryData.manufacturer - manufacturer of vehicle.
* @param {string} queryData.model - model name of vehicle.
* @param {object} rawVehicle - vehicle data from response object of nhtsa
* @param {string} rawVehicle.VehicleDescription - Model description
* @param {number} rawVehicle.VehicleId - nhtsa id for the model.
*/
constructor(queryData, rawVehicle){
/**
* Private in case of direct usage of instance in JSON.stringify.
* @type {Object}
*/
this[querySymbol] = queryData;
/**
* NHTSA ID
* @type {number}
*/
this.VehicleId = rawVehicle.VehicleId;
/**
* Model description of vehicle.
* @type {string}
*/
this.Description = rawVehicle.VehicleDescription;
}
/**
* Populates Vehicle#CrashRating data from NCAP API
*/
async populateCrashRating(){
let data = await nhtsa.getStars(this);
/**
* Overall Crashrating star count of vehicle.
* @type {string}
*/
this.CrashRaiting = data.data.Results[0].OverallRating;
return data;
}
}
module.exports = Vehicle;