geonet
Version:
A Node.js API wrapper for GeoNet — Aotearoa's geological hazard monitoring system.
48 lines (47 loc) • 1.97 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.IntensityService = void 0;
const base_1 = require("../../@types/base");
const BaseService_1 = require("./BaseService");
/**
* IntensityService class for fetching intensity data from the GeoNet API.
* @extends BaseService
* @since 1.0.0
*/
class IntensityService extends BaseService_1.BaseService {
async getIntensity(req) {
/**
* Fetches shaking intensity information data based on the provided request parameters.
*
* @param {IntensityRequestUnion} req - The request parameters for fetching intensity data.
* @returns {Promise<IntensityResponse>} - A promise that resolves to the intensity response data.
* @throws {Error} - Throws an error if the request type is invalid.
* @since 1.0.0
*/
if (req.type === "measured") {
const params = new URLSearchParams({
type: req.type
});
return await this.GET({
endpoint: `/intensity?${params.toString()}`,
format: base_1.JSONFormatTypes.APPLICATION_VND_GEO_JSON_VERSION_2
});
}
else if (req.type === "reported") {
if (req.publicID && typeof (req.publicID) !== "string")
throw new Error("Public ID must be a string.");
const params = new URLSearchParams({
type: req.type,
...(req.aggregation && { aggregation: req.aggregation }),
...(req.publicID && { publicID: req.publicID })
});
return await this.GET({
endpoint: `/intensity?${params.toString()}`,
format: base_1.JSONFormatTypes.APPLICATION_VND_GEO_JSON_VERSION_2
});
}
else
throw new Error("Invalid req type. Must be either 'measured' or 'reported'.");
}
}
exports.IntensityService = IntensityService;