forked from dwp/BSP-State-Pension-Date
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: remove express server, big clean up and refactor
- Loading branch information
Showing
22 changed files
with
3,724 additions
and
4,979 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,142 +1,36 @@ | ||
# get-uk-state-pension-date # | ||
# get-state-pension-date # | ||
|
||
This package can be used in two different ways. | ||
This package provides two simple functions that allows the calculation of the date on which a UK citizen becomes eligible for their State Pension. | ||
|
||
1) Installed from a GitLab repository, as a dependency in your package.json file. | ||
## Installation | ||
|
||
2) Cloned from the repository to provide a simple REST based service. | ||
|
||
|
||
## 1) Package dependency | ||
|
||
This package, provides two simple functions that allows the calculation of the | ||
Date on which a UK citizen becomes elligible for their State Pension. | ||
|
||
The functions are... | ||
|
||
```javascript | ||
getStatePensionDate(dateOfBirth, gender) | ||
getStatePensionDateAsString(dateOfBirth, gender) | ||
```bash | ||
npm install get-state-pension-date | ||
``` | ||
|
||
Where... | ||
## Usage | ||
|
||
* 'dateOfBirth' must be in the YYYY-MM-DD format. | ||
* 'gender' must be one of 'F', 'FEMALE', 'M' or 'MALE' (case insensitive). | ||
* YYYY-MM-DD is the only format supported. | ||
* The YYYY section of the Date of Birth must be in the range 1000 - 4000 (Arbitrary limits imposed by author). | ||
* The 'getStatePensionDate' function returns a Date object representing the State Pension Date. | ||
* The 'getStatePensionDateAsString' function returns a String containing the State Pension Date in the YYYY-MM-DD format. | ||
* If the input provided is invalid the function will throw TypeError('Invalid Input'). | ||
* If the State Pension Date cannot be determined, a value of 'undefined' will be returned (by both functions). | ||
* Invalid date values (e.g. 29 feb in non-leap years, or 31 April etc.) will result in 'undefined' being returned (by both functions). | ||
* Invalid gender values (anything other than 'F', 'FEMALE', 'M' or 'MALE') will result in 'undefined' being returned (by both functions). | ||
`getStatePensionDate()` takes a date of birth string and gender and returns a state pension age `Date` object. | ||
`getStatePensionDateAsString()` takes the same parameters but returns a `string`. | ||
|
||
## Example | ||
|
||
Install by cloning this repository and running `npm install`. Once installed, then the functions can simply be required within a Javascrip file | ||
as follows... | ||
For example: | ||
|
||
```javascript | ||
// Require the module | ||
const UKStatePension = require('get-uk-state-pension-date'); | ||
|
||
const getUkStatePensionDate = UKStatePension.getUkStatePensionDate; | ||
const getUkStatePensionDateAsString = UKStatePension.getUkStatePensionDateAsString; | ||
|
||
// Get state pension date for a male born on 25 March 1990 | ||
const pensionDate = getUkStatePensionDate('1990-03-25', 'M'); | ||
|
||
// Write result to console | ||
console.log(`For a male born on 25 March 1990, their state Pension Date would be ${pensionDate}`); | ||
|
||
// Get the same item as a string in the YYYY-MM-DD format | ||
const pensionDateString = getUkStatePensionDateAsString('1990-03-25', 'M'); | ||
const {getStatePensionDate, getStatePensionDateAsString} = require('get-state-pension-date'); | ||
|
||
// Write result to console | ||
console.log(`For a male born on 25 March 1990, their state Pension Date would be ${pensionDateString}`); | ||
``` | ||
|
||
Error Handling | ||
## 2) Server process | ||
After cloning the project from a repository, and running 'npm install', you can run the following to ensure the component is working correctly: | ||
|
||
```script | ||
npm test | ||
``` | ||
|
||
then you can start a simple server by executing... | ||
// Date: 2058-03-25T00:00:00.000Z | ||
const SPADate = getStatePensionDate('1990-03-25', 'male'); | ||
|
||
```script | ||
npm start | ||
// String: 2058-03-25 | ||
const SPAString = getStatePensionDateAsString('1990-03-25', 'female'); | ||
``` | ||
|
||
** the service will start on port 5000 by default. To set a different port configure an environment variable SPA_PORT | ||
|
||
e.g. SPA_PORT=4001 | ||
Both functions will throw if the date of birth is not a `YYYY-MM-DD` formatted | ||
string or if the gender is not a string of `male` or `female`. | ||
|
||
Once running, the service will accept requests that supply a date of birth and a | ||
gender, and will return a simple piece of content showing the state pension | ||
date. | ||
|
||
The RESTfull interface provides 2 endpoints: | ||
|
||
##### 1) Get state pension date which provides the state pension age for a given birthday and sex; this is called as per the below query. | ||
|
||
Example query... | ||
|
||
```html | ||
http://localhost/1990-03-10/M | ||
``` | ||
|
||
Would return... | ||
|
||
```json | ||
{ | ||
"statePensionDate": "2058-03-10T00:00:00.000Z" | ||
} | ||
``` | ||
|
||
If the input provided is invalid the rest service will return 400 http status code and, for example, the json | ||
|
||
```json | ||
{ | ||
"error":"The client input was invalid: Date of birth: '1990-03-10', Gender: 'G'" | ||
} | ||
``` | ||
|
||
If an error is thrown while processing the rest service will return 500 http status code and, for example, the json | ||
|
||
|
||
```json | ||
{ | ||
"error":"Unexpected error occurred for input: Date of birth: '1990-03-10', Gender: 'F'" | ||
} | ||
``` | ||
|
||
|
||
##### 2) Ping health which provides a check point for health monitors to call into to ensure the service is up; this is called as per the below query. | ||
|
||
Example query... | ||
|
||
```html | ||
http://localhost/ping | ||
``` | ||
|
||
Would return... | ||
|
||
```html | ||
pong | ||
``` | ||
|
||
|
||
# Caveat | ||
## Caveat | ||
|
||
The dates produced by this package are based on legislation in place at the point of publishing (November 2018). | ||
Dates that fall beyond the current legislation (i.e. after 5/4/1977) are calculated on a best endeavours basis only. | ||
|
||
see below link for fuller details | ||
```html | ||
https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/310231/spa-timetable.pdf | ||
``` | ||
E&OE | ||
[Further information about State Pension age timetables](https://assets.publishing.service.gov.uk/government/uploads/system/uploads/attachment_data/file/310231/spa-timetable.pdf). |
Oops, something went wrong.