From fe9739a2cd7b3a81b810fd62e5883b95782e4d21 Mon Sep 17 00:00:00 2001
From: "alec.schmidt" <alec.schmidt@etu.hesge.ch>
Date: Tue, 20 Jun 2023 12:40:43 +0200
Subject: [PATCH] postman

---
 API/db/app.db                                 | Bin 36864 -> 36864 bytes
 API/src/routes/BaseRoutes.ts                  |   4 +-
 .../TP-ArchiWeb.postman_collection.json       | 534 ++++++++++++++++++
 3 files changed, 537 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/TP-ArchiWeb.postman_collection.json

diff --git a/API/db/app.db b/API/db/app.db
index 7680fd1877fc4b7fcf94bea21b4a1d6b2bfed5da..79e49ef675b59fddc8dfe076dbb54df0c8b860aa 100644
GIT binary patch
delta 1657
zcmZozz|^pSX@WGP)<hX+My-trOZd5%`Oh-&f8>9_e|EE=z<z!eL1tD4Sy7Jg#FEsa
zwEPM~BV!YOCRPSXQ4Z&fqWs)ckig`R^1@uq{0|uT-||1;|FKz6;1a(c53?*IOcyg3
zvm_%#Jrg^#C}(0$YBDeX3kGKXGYtG+`Oom*-Yh7vkKcoriCLa8ur#%}Br`v+n4O!M
zS(?!?uedz5s92JLfq|D3CdbLhEY28OoLW@O%*+3XfsHSSfqxHw6~7GME54<CL7N2y
z?D*;f*;yGHMP&m^6Z29OO7j#767!N1vr`pH@^h0?6;cxOiWPDa74lLu(^C}^%M$ZS
z6mn7(j13i14zEm3%}pvw)ltaLQ%K1yQLu8#&r=9a%`0|hV_~S4bxBnyEKSYHNmWSB
zFU?6UEmAnVvLrDRtUoy;wJb45At@)ZJ}+4zB~`&Mu^>O^@XGu=1$&Ro;*$K#qErJ`
z7KTvSK!_1}`6a0e$*BqjMfq8&B?`HRR~BWKr0SOFX67i^!|aV=VP$AkRrWu;Qz5mu
zM4>pdr1bDgkn24XOG{D}4tFN!=cIyc3rMUiPE1cN%1qU%SMbbBKfE$8GqtoRGgTqA
zM8UBrIU}<qHMyj;C{@AU{qV~C^rFOqjLcLAW)_A*MUaEQ#^<CeW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<;x;+&zysYS&gjg0({82BGS%nabvkYQwD(3N#gP0mzEEiO?g%~L2zEiUoM
zEH25<EK22KU|?Y6f5X842BKktFpDs=F6ZPA@gf{d{7)J9zwkeW$OLdrewr`O!NmWB
zf&U5r7pNeo20ybhqx<2N`RPT81sR#COx(<}oG{Zt&SB#Jz`*~5{{uwB1W^GtCRPT1
NPEI2>Mi9+m2ml-qROSEx

diff --git a/API/src/routes/BaseRoutes.ts b/API/src/routes/BaseRoutes.ts
index 1479e16..93703d5 100644
--- a/API/src/routes/BaseRoutes.ts
+++ b/API/src/routes/BaseRoutes.ts
@@ -91,7 +91,6 @@ router.patch(ROUTE+'/user/:id', (req: express.Request, res: express.Response) =>
     const a = req.body as User_t;
     const token = req.headers['authorization'] && req.headers['authorization'].split(' ')[1]
     const id: number = +req.params.id;
-
     
     if (a.admin && !isAdmin(token)) {
         return res.status(StatusCodes.UNAUTHORIZED).end();
@@ -109,6 +108,9 @@ router.patch(ROUTE+'/user/:id', (req: express.Request, res: express.Response) =>
         if (!isAdmin(token))
             user = tokenDecode(req);    
 
+        if (user === undefined)
+            return res.status(StatusCodes.BAD_REQUEST).end();
+
         if (a.username !== user.username)
             DBHandler.verifyUsernameExistence(a.username)
             .then(exists => {
diff --git a/Documentation/TP-ArchiWeb.postman_collection.json b/Documentation/TP-ArchiWeb.postman_collection.json
new file mode 100644
index 0000000..3e1c027
--- /dev/null
+++ b/Documentation/TP-ArchiWeb.postman_collection.json
@@ -0,0 +1,534 @@
+{
+	"info": {
+		"_postman_id": "4ce300c2-2a5c-4124-93ce-5c4c46a378e9",
+		"name": "TP-ArchiWeb",
+		"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
+	},
+	"item": [
+		{
+			"name": "get all users",
+			"request": {
+				"auth": {
+					"type": "bearer",
+					"bearer": [
+						{
+							"key": "token",
+							"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFsZWMiLCJwYXNzd29yZCI6IjA5ODc2NTQzIiwidHlwZSI6ImFkbWluIiwiaWF0IjoxNjg0OTQ2NDA2fQ.GqEzXzEyf4wz9FZNjEuNgwoECnXDNR6IVjf00jQY3HE",
+							"type": "string"
+						}
+					]
+				},
+				"method": "GET",
+				"header": [],
+				"url": {
+					"raw": "http://0.0.0.0:30992/API/v1/user",
+					"protocol": "http",
+					"host": [
+						"0",
+						"0",
+						"0",
+						"0"
+					],
+					"port": "30992",
+					"path": [
+						"API",
+						"v1",
+						"user"
+					]
+				}
+			},
+			"response": []
+		},
+		{
+			"name": "create user",
+			"request": {
+				"auth": {
+					"type": "bearer",
+					"bearer": [
+						{
+							"key": "token",
+							"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFsZWMiLCJhZG1pbiI6MSwiaWF0IjoxNjg2MTU0NDMwfQ.kVrq-EiY1CHZqjVUux8C_YEvbMHlyO24Uq8HNcwH5iA",
+							"type": "string"
+						}
+					]
+				},
+				"method": "POST",
+				"header": [],
+				"body": {
+					"mode": "raw",
+					"raw": "{\n    \"username\": \"usertest\",\n    \"password\": \"test\",\n    \"admin\": true\n}",
+					"options": {
+						"raw": {
+							"language": "json"
+						}
+					}
+				},
+				"url": {
+					"raw": "http://0.0.0.0:30992/API/v1/user",
+					"protocol": "http",
+					"host": [
+						"0",
+						"0",
+						"0",
+						"0"
+					],
+					"port": "30992",
+					"path": [
+						"API",
+						"v1",
+						"user"
+					]
+				}
+			},
+			"response": []
+		},
+		{
+			"name": "create user admin",
+			"request": {
+				"auth": {
+					"type": "bearer",
+					"bearer": [
+						{
+							"key": "token",
+							"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFsZWMiLCJhZG1pbiI6MSwiaWF0IjoxNjg2MTU0NDMwfQ.kVrq-EiY1CHZqjVUux8C_YEvbMHlyO24Uq8HNcwH5iA",
+							"type": "string"
+						}
+					]
+				},
+				"method": "POST",
+				"header": [],
+				"body": {
+					"mode": "raw",
+					"raw": "{\n    \"username\": \"vincent\",\n    \"password\": \"test\",\n    \"admin\": true\n}",
+					"options": {
+						"raw": {
+							"language": "json"
+						}
+					}
+				},
+				"url": {
+					"raw": "http://0.0.0.0:30992/API/v1/user",
+					"protocol": "http",
+					"host": [
+						"0",
+						"0",
+						"0",
+						"0"
+					],
+					"port": "30992",
+					"path": [
+						"API",
+						"v1",
+						"user"
+					]
+				}
+			},
+			"response": []
+		},
+		{
+			"name": "update user",
+			"request": {
+				"method": "PATCH",
+				"header": [],
+				"body": {
+					"mode": "raw",
+					"raw": "{\n    \"username\": \"updated\",\n    \"admin\": false\n}",
+					"options": {
+						"raw": {
+							"language": "json"
+						}
+					}
+				},
+				"url": {
+					"raw": "http://0.0.0.0:30992/API/v1/user/5",
+					"protocol": "http",
+					"host": [
+						"0",
+						"0",
+						"0",
+						"0"
+					],
+					"port": "30992",
+					"path": [
+						"API",
+						"v1",
+						"user",
+						"5"
+					]
+				}
+			},
+			"response": []
+		},
+		{
+			"name": "delete user",
+			"request": {
+				"method": "DELETE",
+				"header": [],
+				"body": {
+					"mode": "raw",
+					"raw": "",
+					"options": {
+						"raw": {
+							"language": "json"
+						}
+					}
+				},
+				"url": {
+					"raw": "http://0.0.0.0:30992/API/v1/user/7",
+					"protocol": "http",
+					"host": [
+						"0",
+						"0",
+						"0",
+						"0"
+					],
+					"port": "30992",
+					"path": [
+						"API",
+						"v1",
+						"user",
+						"7"
+					]
+				}
+			},
+			"response": []
+		},
+		{
+			"name": "get questions",
+			"protocolProfileBehavior": {
+				"disableBodyPruning": true
+			},
+			"request": {
+				"method": "GET",
+				"header": [],
+				"body": {
+					"mode": "raw",
+					"raw": "",
+					"options": {
+						"raw": {
+							"language": "json"
+						}
+					}
+				},
+				"url": {
+					"raw": "http://0.0.0.0:30992/API/v1/question/2",
+					"protocol": "http",
+					"host": [
+						"0",
+						"0",
+						"0",
+						"0"
+					],
+					"port": "30992",
+					"path": [
+						"API",
+						"v1",
+						"question",
+						"2"
+					]
+				}
+			},
+			"response": []
+		},
+		{
+			"name": "create question",
+			"request": {
+				"auth": {
+					"type": "bearer"
+				},
+				"method": "POST",
+				"header": [],
+				"body": {
+					"mode": "raw",
+					"raw": "{\n    \"question\": \"Quelle est cette question de test ? - 4\",\n    \"category\": \"Histoire\"\n}",
+					"options": {
+						"raw": {
+							"language": "json"
+						}
+					}
+				},
+				"url": {
+					"raw": "http://0.0.0.0:30992/API/v1/question",
+					"protocol": "http",
+					"host": [
+						"0",
+						"0",
+						"0",
+						"0"
+					],
+					"port": "30992",
+					"path": [
+						"API",
+						"v1",
+						"question"
+					]
+				}
+			},
+			"response": []
+		},
+		{
+			"name": "create question Copy",
+			"request": {
+				"auth": {
+					"type": "bearer"
+				},
+				"method": "PATCH",
+				"header": [],
+				"body": {
+					"mode": "raw",
+					"raw": "{\n    \"question\": \"Quelle est cette question modifiée ? - 4\",\n    \"category\": \"Histoire\"\n}",
+					"options": {
+						"raw": {
+							"language": "json"
+						}
+					}
+				},
+				"url": {
+					"raw": "http://0.0.0.0:30992/API/v1/question/2",
+					"protocol": "http",
+					"host": [
+						"0",
+						"0",
+						"0",
+						"0"
+					],
+					"port": "30992",
+					"path": [
+						"API",
+						"v1",
+						"question",
+						"2"
+					]
+				}
+			},
+			"response": []
+		},
+		{
+			"name": "delete question",
+			"request": {
+				"auth": {
+					"type": "bearer"
+				},
+				"method": "DELETE",
+				"header": [],
+				"body": {
+					"mode": "raw",
+					"raw": "{\n    \"question\": \"Quelle est cette question de test ? - 4\",\n    \"category\": \"Histoire\"\n}",
+					"options": {
+						"raw": {
+							"language": "json"
+						}
+					}
+				},
+				"url": {
+					"raw": "http://0.0.0.0:30992/API/v1/question/2",
+					"protocol": "http",
+					"host": [
+						"0",
+						"0",
+						"0",
+						"0"
+					],
+					"port": "30992",
+					"path": [
+						"API",
+						"v1",
+						"question",
+						"2"
+					]
+				}
+			},
+			"response": []
+		},
+		{
+			"name": "get answers",
+			"protocolProfileBehavior": {
+				"disableBodyPruning": true
+			},
+			"request": {
+				"method": "GET",
+				"header": [],
+				"body": {
+					"mode": "raw",
+					"raw": "",
+					"options": {
+						"raw": {
+							"language": "json"
+						}
+					}
+				},
+				"url": {
+					"raw": "http://0.0.0.0:30992/API/v1/answer",
+					"protocol": "http",
+					"host": [
+						"0",
+						"0",
+						"0",
+						"0"
+					],
+					"port": "30992",
+					"path": [
+						"API",
+						"v1",
+						"answer"
+					]
+				}
+			},
+			"response": []
+		},
+		{
+			"name": "create answer",
+			"request": {
+				"method": "POST",
+				"header": [],
+				"body": {
+					"mode": "raw",
+					"raw": "{\n    \"text_answer\": \"bonsoir\",\n    \"id_question\": 1,\n    \"correct\": true\n}",
+					"options": {
+						"raw": {
+							"language": "json"
+						}
+					}
+				},
+				"url": {
+					"raw": "http://0.0.0.0:30992/API/v1/answer",
+					"protocol": "http",
+					"host": [
+						"0",
+						"0",
+						"0",
+						"0"
+					],
+					"port": "30992",
+					"path": [
+						"API",
+						"v1",
+						"answer"
+					]
+				}
+			},
+			"response": []
+		},
+		{
+			"name": "update answer",
+			"request": {
+				"auth": {
+					"type": "bearer",
+					"bearer": [
+						{
+							"key": "token",
+							"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFsZWMiLCJhZG1pbiI6MSwiaWF0IjoxNjg2MTU0NDMwfQ.kVrq-EiY1CHZqjVUux8C_YEvbMHlyO24Uq8HNcwH5iA",
+							"type": "string"
+						}
+					]
+				},
+				"method": "PATCH",
+				"header": [],
+				"body": {
+					"mode": "raw",
+					"raw": "{\n    \"id\": 1,\n    \"text_answer\": \"modified\",\n    \"id_question\": 1,\n    \"correct\": 0\n}",
+					"options": {
+						"raw": {
+							"language": "json"
+						}
+					}
+				},
+				"url": {
+					"raw": "http://0.0.0.0:30992/API/v1/answer/1",
+					"protocol": "http",
+					"host": [
+						"0",
+						"0",
+						"0",
+						"0"
+					],
+					"port": "30992",
+					"path": [
+						"API",
+						"v1",
+						"answer",
+						"1"
+					]
+				}
+			},
+			"response": []
+		},
+		{
+			"name": "delete answer",
+			"request": {
+				"auth": {
+					"type": "bearer",
+					"bearer": [
+						{
+							"key": "token",
+							"value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImFsZWMiLCJhZG1pbiI6MSwiaWF0IjoxNjg2MTU0NDMwfQ.kVrq-EiY1CHZqjVUux8C_YEvbMHlyO24Uq8HNcwH5iA",
+							"type": "string"
+						}
+					]
+				},
+				"method": "DELETE",
+				"header": [],
+				"body": {
+					"mode": "raw",
+					"raw": "",
+					"options": {
+						"raw": {
+							"language": "json"
+						}
+					}
+				},
+				"url": {
+					"raw": "http://0.0.0.0:30992/API/v1/answer/1",
+					"protocol": "http",
+					"host": [
+						"0",
+						"0",
+						"0",
+						"0"
+					],
+					"port": "30992",
+					"path": [
+						"API",
+						"v1",
+						"answer",
+						"1"
+					]
+				}
+			},
+			"response": []
+		},
+		{
+			"name": "login",
+			"request": {
+				"method": "POST",
+				"header": [],
+				"body": {
+					"mode": "raw",
+					"raw": "{\n    \"username\": \"alec\",\n    \"password\": \"alec\"\n}",
+					"options": {
+						"raw": {
+							"language": "json"
+						}
+					}
+				},
+				"url": {
+					"raw": "http://0.0.0.0:30992/API/v1/login",
+					"protocol": "http",
+					"host": [
+						"0",
+						"0",
+						"0",
+						"0"
+					],
+					"port": "30992",
+					"path": [
+						"API",
+						"v1",
+						"login"
+					]
+				}
+			},
+			"response": []
+		}
+	]
+}
\ No newline at end of file
-- 
GitLab