Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docstrings for website status service #9495

Merged
merged 1 commit into from
Aug 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions services/website-status.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,51 @@
/**
* 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(),
up_color: Joi.alternatives(Joi.string(), Joi.number()),
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',
down_message: 'offline',
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',
Expand Down
Loading