diff --git a/services/website-status.js b/services/website-status.js index c0fdb252b07b1..86cd4be4cd036 100644 --- a/services/website-status.js +++ b/services/website-status.js @@ -1,5 +1,17 @@ +/** + * Commonly used functions and utilities for tasks related to website status. + * + * @module + */ + import Joi from 'joi' +/** + * Joi schema for validating query params. + * Checks if the query params obect has valid up_message, down_message, up_color and down_color properties. + * + * @type {Joi} + */ const queryParamSchema = Joi.object({ up_message: Joi.string(), down_message: Joi.string(), @@ -7,6 +19,12 @@ const queryParamSchema = Joi.object({ down_color: Joi.alternatives(Joi.string(), Joi.number()), }).required() +/** + * Example query param object. + * Contains up_message, down_message, up_color and down_color properties. + * + * @type {object} + */ const exampleQueryParams = { up_message: 'online', up_color: 'blue', @@ -14,6 +32,20 @@ const exampleQueryParams = { down_color: 'lightgrey', } +/** + * Creates a badge object that displays information about website status. + * + * @param {object} options - The options for rendering the status + * @param {boolean} options.isUp - Whether the website or service is up or down + * @param {string} [options.upMessage='up'] - The message to display when the website or service is up + * @param {string} [options.downMessage='down'] - The message to display when the website or service is down + * @param {string} [options.upColor='brightgreen'] - The color to use when the website or service is up + * @param {string} [options.downColor='red'] - The color to use when the website or service is down + * @returns {object} An object with a message and a color property + * @example + * renderWebsiteStatus({ isUp: true }) // returns { message: 'up', color: 'brightgreen' } + * renderWebsiteStatus({ isUp: false }) // returns { message: 'down', color: 'red' } + */ function renderWebsiteStatus({ isUp, upMessage = 'up',