/attendance-rules-api

A REST API to manage attendance rules

Primary LanguageJavaScriptMIT LicenseMIT

attendance-rules-api

This is a simple REST API to manage attendance rules for a clinic.

Instructions

This API can be used through its main Endpoint /attendance-rules in the following way:

POST

This method is used to save a new Attendance Rule. It must be sent in the body of the Request as a raw JSON object with the following structure:
{
    day: DAY_STRING
    intervals: [{start: TIME1, end: TIME2 }]
}
  • DAY_STRING: The Date or period in which the Attendance Rule applies. Values accepted are:
    • "daily": Attendance occurs every day, including weekends
    • "sundays", "mondays", "tuesdays", "wednesdays", "thursdays", "fridays" or "saturdays": Attendance occurs weekly in the corresponding day
    • "dd-MM-yyyy": Attendance occurs in the specified date only
  • TIME1 and TIME2: The time of day in which Attendance occurs. Both must be in the format "HH:mm" and TIME1 must be lesser than or equals TIME2

The "intervals" Array may contain any number of Time Range objects as necessary, as long as they meet the structure with exactly the "start" and "end" properties.

If the JSON structure is correct, a Response with status code 201 will be sent with the header "Location" presenting the location and ID of the saved Attendance Rule. Any extra properties included in the JSON will be ignored.

If the JSON structure is incorrect, a Response with status code 400 will be sent.

if there is any conflict with the time intervals within the Array itself or with other saved Attendance Rules, a Response with status code 409 will be sent.

GET

If used without URL query params, this method recovers all Attendance Rules saved and returns them as a JSON Array in the body of the Response with the status code 200. If there isn't any saved Attendance Rules the Response body will be empty and the status code will be 204.

If used exactly with the query params "start-date" and "end-date", this method will recover a JSON Array containing all the available attendance dates and times within that range, including both start and end dates. If there isn't any saved Attendance Rules, the Response body will be empty and the status code will be 204.

"start-date" and "end-date" must be in the format "dd-MM-yyyy"

URL and Response example:

URL: HOST/attendance-rules?start-date=04-12-2020&end-date=08-12-2020
[{
    "day": "04-12-2020",
    "intervals": [{ "start": "08:00", "end": "08:30" },
                  { "start": "08:30", "end": "09:00" },
                  { "start": "09:00", "end": "09:30" },
                  { "start": "09:30", "end": "10:00" },
                  { "start": "13:00", "end": "14:00" },
                  { "start": "14:00", "end": "15:00" }]
},
{
    "day": "05-12-2020",
    "intervals": [{ "start": "08:00", "end": "08:30" },
                  { "start": "08:30", "end": "09:00" },
                  { "start": "09:00", "end": "09:30" },
                  { "start": "09:30", "end": "10:00" }]
},
{
    "day": "06-12-2020",
    "intervals": [{ "start": "08:00", "end": "08:30" },
                  { "start": "08:30", "end": "09:00" },
                  { "start": "09:00", "end": "09:30" },
                  { "start": "09:30", "end": "10:00" }]
},
{
    "day": "07-12-2020",
    "intervals": [{ "start": "08:00", "end": "08:30" },
                  { "start": "08:30", "end": "09:00" },
                  { "start": "09:00", "end": "09:30" },
                  { "start": "09:30", "end": "10:00" }]
},
{
    "day": "08-12-2020",
    "intervals": [{ "start": "08:00", "end": "08:30" },
                  { "start": "08:30", "end": "09:00" },
                  { "start": "09:00", "end": "09:30" },
                  { "start": "09:30", "end": "10:00" },
                  { "start": "18:00", "end": "19:00" }]
}]

DELETE

This method is used to delete a saved Attendance Rule. It's endpoint is /attendance-rules/ID, where ID is the string received in the "Location" header of the Response after saving a new Attendance Rule.

If the Attendance Rule is deleted successfully, a Response with status code 200 will be sent.

If no Attendance Rule can be found with the given ID, a Response with status code 404 will be sent.

Request Examples

A Postman collection of sample URL's can be found here in JSON format. In case it isn't working properly, the same URL's are listed bellow with HTTP Method, Endpoint and Request Body if present.

POST localhost:3000/attendance-rules

{
    "day": "21-12-2020",
    "intervals": [{"start": "18:00", "end": "19:00"}]
}

POST localhost:3000/attendance-rules

{
    "day": "fridays",
    "intervals": [{"start": "13:00", "end": "14:00"},
                    {"start": "14:00", "end": "15:00"}]
}

POST localhost:3000/attendance-rules

{
    "day": "daily",
    "intervals": [{"start": "08:00", "end": "08:30"}, 
                    {"start": "08:30", "end": "09:00"},
                    {"start": "09:00", "end": "09:30"},
                    {"start": "09:30", "end": "10:00"}]
}

GET localhost:3000/attendance-rules

GET localhost:3000/attendance-rules?start-date=04-12-2020&end-date=08-12-2020

DELETE localhost:3000/attendance-rules/ID (ID can be found in the Location header after POSTing a new Attendance Rule)