Sfoglia il codice sorgente

Create documentation for user.

Lee Morgan 1 anno fa
parent
commit
9f50d466bd
5 ha cambiato i file con 294 aggiunte e 0 eliminazioni
  1. 1 0
      controllers/user.js
  2. 66 0
      documentation/data.js
  3. 88 0
      documentation/index.css
  4. 14 0
      documentation/index.html
  5. 125 0
      documentation/index.js

+ 1 - 0
controllers/user.js

@@ -43,6 +43,7 @@ const hashPass = async (password)=>{
  */
 const responseUser = (user)=>{
     return {
+        id: user._id,
         name: user.name,
         email: user.email,
         workouts: user.workouts

+ 66 - 0
documentation/data.js

@@ -0,0 +1,66 @@
+window.data = [
+    {
+        type: "object",
+        title: "User",
+        id: "user",
+        auth: false,
+        description: "User object",
+        properties: [
+            {
+                name: "id",
+                type: "String",
+                desc: "Unique user ID"
+            },
+            {
+                name: "name",
+                type: "String",
+                desc: "User name"
+            },
+            {
+                name: "workouts",
+                type: [Object],
+                desc: "List of workouts. Includes name of the workout and list of exercises"
+            },
+            {
+                name: "workouts.name",
+                type: "String",
+                desc: "Name of the workout"
+            },
+            {
+                name: "workouts.exercises",
+                type: "[String]",
+                desc: "List of strings, each one being the name of an exercise"
+            }
+        ]
+    },
+    {
+        type: "route",
+        id: "createUser",
+        title: "Create",
+        url: "POST /user",
+        auth: false,
+        description: "Create a new user",
+        requestBody: [
+            {
+                name: "name",
+                type: "String",
+                desc: "User name"
+            },
+            {
+                name: "email",
+                type: "String",
+                desc: "User email address"
+            },
+            {
+                name: "pass",
+                type: "String",
+                desc: "User password"
+            },
+            {
+                name: "confirmPass",
+                type: "String",
+                desc: "Confirmation password"
+            }
+        ]
+    }
+]

+ 88 - 0
documentation/index.css

@@ -0,0 +1,88 @@
+*{margin:0;padding:0;box-sizing:border-box;}
+
+body{
+    display: flex;
+    height: 100vh;
+    width: 100vw;
+    overflow-y: hidden;
+}
+
+header{
+    display: flex;
+    flex-direction: column;
+    flex-basis: 350px;
+    background: black;
+    color: white;
+    height: 100%;
+    padding: 35px;
+}
+
+header a{
+    color: rgb(200, 200, 200);
+    text-decoration: none;
+}
+
+.headMain{
+    font-size: 22px;
+    font-weight: bold;
+}
+
+.headSub{
+    padding-left: 15px;
+}
+
+.container, #container{
+    flex-grow: 1;
+    height: 100%;
+    overflow-y: auto;
+    background: rgb(200, 200, 200);
+    padding: 35px;
+}
+
+article{
+    border-bottom: 2px solid black;
+    margin-bottom: 35px;
+}
+
+.prop{
+    padding: 15px 25px;
+    border-top: 1px solid black;
+}
+
+.name, .type{
+    display: inline-block;
+}
+
+.name{
+    font-weight: bold;
+}
+
+.type{
+    margin-left: 15px;
+    font-size: 12px;
+}
+
+.url{
+    font-size: 18px;
+}
+
+ul{
+    display: inline-block;
+    border: 1px solid black;
+    padding: 5px 10px;
+    margin: 10px 0 0 15px;
+    position: relative;
+}
+
+.ulTitle{
+    position: absolute;
+    top: -7px;
+    left: -7px;
+    font-size: 12px;
+    background: rgb(200, 200, 200);
+    list-style-type: none;
+}
+
+li{
+    margin-left: 20px;
+}

+ 14 - 0
documentation/index.html

@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="utf-8">
+    <title>API Documentation | MORGAN BET</title>
+    <link rel="stylesheet" href="./index.css";
+</head>
+<body>
+    <header></header>
+    <div id="container"></div>
+    <script src="./data.js"></script>
+    <script src="./index.js"></script>
+</body>
+</html>

+ 125 - 0
documentation/index.js

@@ -0,0 +1,125 @@
+const header = document.querySelector("header");
+const container = document.getElementById("container");
+
+const createHeaderItem =(type, title, id)=>{
+    const anc = document.createElement("a");
+    anc.href = `#${id}`;
+    anc.textContent = title;
+    switch(type){
+        case "object": anc.classList.add("headMain"); break;
+        case "route": anc.classList.add("headSub"); break;
+    }
+    return anc;
+}
+
+const createItem = (data)=>{
+    const article = document.createElement("article");
+    article.id = data.id;
+
+    const title = document.createElement("h1");
+    title.textContent = data.title;
+    article.appendChild(title);
+
+    if(data.type === "route"){
+        const route = document.createElement("p");
+        route.classList.add("url");
+        route.textContent = data.url;
+        article.appendChild(route);
+    }
+
+    if(data.auth){
+        const auth = document.createElement("p");
+        auth.textContent = "Auth required";
+        article.appendChild(auth);
+    }
+
+    const description = document.createElement("p");
+    description.classList.add("description");
+    description.textContent = data.description;
+    article.appendChild(description);
+
+    if(data.properties){
+        const subTitle = document.createElement("h3");
+        subTitle.textContent = "Properties";
+        article.appendChild(subTitle);
+
+        for(let i = 0; i < data.properties.length; i++){
+            article.appendChild(createProp(data.properties[i]));
+        }
+    }
+
+    if(data.requestBody){
+        const subTitle = document.createElement("h3");
+        subTitle.textContent = "Request Body";
+        article.appendChild(subTitle);
+
+        for(let i = 0; i < data.requestBody.length; i++){
+            article.appendChild(createProp(data.requestBody[i]))
+        }
+    }
+
+    if(data.responseBody){
+        const subTitle = document.createElement("h3");
+        subTitle.textContent = "Response Body";
+        article.appendChild(subTitle);
+
+        for(let i = 0; i < data.responseBody.length; i++){
+            article.appendChild(createProp(data.responseBody[i]))
+        }
+    }
+
+    if(data.queries){
+        const subTitle = document.createElement("h3");
+        subTitle.textContent = "Query Parameters";
+        article.appendChild(subTitle);
+
+        for(let i = 0; i < data.queries.length; i++){
+            article.appendChild(createProp(data.queries[i]))
+        }
+    }
+
+    return article;
+}
+
+const createProp = (propData)=>{
+    const propContainer = document.createElement("div");
+    propContainer.classList.add("prop");
+
+    const name = document.createElement("p");
+    name.classList.add("name");
+    name.textContent = propData.name;
+    propContainer.appendChild(name);
+
+    const type = document.createElement("p");
+    type.classList.add("type");
+    type.textContent = propData.type;
+    propContainer.appendChild(type);
+
+    const desc = document.createElement("p");
+    desc.classList.add("propDesc");
+    desc.textContent = propData.desc;
+    propContainer.appendChild(desc);
+
+    if(propData.options){
+        const ul = document.createElement("ul");
+        propContainer.appendChild(ul);
+
+        const title = document.createElement("li");
+        title.textContent = "Options";
+        title.classList.add("ulTitle");
+        ul.appendChild(title)
+
+        for(let i = 0; i < propData.options.length; i++){
+            const li = document.createElement("li");
+            li.textContent = propData.options[i];
+            ul.appendChild(li);
+        }
+    }
+
+    return propContainer;
+}
+
+for(let i = 0; i < data.length; i++){
+    header.appendChild(createHeaderItem(data[i].type, data[i].title, data[i].id));
+    container.appendChild(createItem(data[i]));
+}