Update auth endpoints
This commit is contained in:
1 parent
4b35811897
commit
d2ab33492a
3 files changed
+104
-81
No files matched your search
@@ -49,23 +49,6 @@ const registerController = async (req, res, next) => {
|
|||||||
next(error);
|
next(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Can there be more than one admin?
|
|
||||||
// // Check if an admin user exists, if so, error
|
|
||||||
// try {
|
|
||||||
// const admin = await req.db.checkAdmin(req, res);
|
|
||||||
// console.log(admin);
|
|
||||||
// if (admin === true) {
|
|
||||||
// throw new Error(errorMessages.AUTH_ADMIN_EXISTS);
|
|
||||||
// }
|
|
||||||
// } catch (error) {
|
|
||||||
// console.log("WEEEEEEE", error.message);
|
|
||||||
// error.service = SERVICE_NAME;
|
|
||||||
// error.status = 403;
|
|
||||||
// next(error);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Create a new user
|
// Create a new user
|
||||||
try {
|
try {
|
||||||
const newUser = await req.db.insertUser({ ...req.body }, req.file);
|
const newUser = await req.db.insertUser({ ...req.body }, req.file);
|
||||||
|
|||||||
+11
-1
@@ -1,3 +1,7 @@
|
|||||||
|
const path = require("path");
|
||||||
|
const fs = require("fs");
|
||||||
|
const swaggerUi = require("swagger-ui-express");
|
||||||
|
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
const helmet = require("helmet");
|
const helmet = require("helmet");
|
||||||
const cors = require("cors");
|
const cors = require("cors");
|
||||||
@@ -21,8 +25,11 @@ const NetworkService = require("./service/networkService");
|
|||||||
const EmailService = require("./service/emailService");
|
const EmailService = require("./service/emailService");
|
||||||
const PageSpeedService = require("./service/pageSpeedService");
|
const PageSpeedService = require("./service/pageSpeedService");
|
||||||
const SERVICE_NAME = "Server";
|
const SERVICE_NAME = "Server";
|
||||||
let cleaningUp = false;
|
|
||||||
|
|
||||||
|
let cleaningUp = false;
|
||||||
|
const openApiSpec = JSON.parse(
|
||||||
|
fs.readFileSync(path.join(__dirname, "openapi.json"), "utf8")
|
||||||
|
);
|
||||||
// Need to wrap server setup in a function to handle async nature of JobQueue
|
// Need to wrap server setup in a function to handle async nature of JobQueue
|
||||||
const startApp = async () => {
|
const startApp = async () => {
|
||||||
// **************************
|
// **************************
|
||||||
@@ -70,6 +77,9 @@ const startApp = async () => {
|
|||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Swagger UI
|
||||||
|
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(openApiSpec));
|
||||||
|
|
||||||
//routes
|
//routes
|
||||||
app.use("/api/v1/auth", authRouter);
|
app.use("/api/v1/auth", authRouter);
|
||||||
app.use("/api/v1/invite", inviteRouter);
|
app.use("/api/v1/invite", inviteRouter);
|
||||||
|
|||||||
+93
-63
@@ -81,7 +81,14 @@
|
|||||||
"application/json": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": ["firstName", "lastName", "email", "password", "role", "teamId"],
|
"required": [
|
||||||
|
"firstName",
|
||||||
|
"lastName",
|
||||||
|
"email",
|
||||||
|
"password",
|
||||||
|
"role",
|
||||||
|
"teamId"
|
||||||
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"firstName": {
|
"firstName": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@@ -103,7 +110,7 @@
|
|||||||
},
|
},
|
||||||
"role": {
|
"role": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"enum": [["user"], ["admin"], ["superadmin"]],
|
"enum": [["user"], ["admin"], ["superadmin"], ["Demo"]],
|
||||||
"default": ["superadmin"]
|
"default": ["superadmin"]
|
||||||
},
|
},
|
||||||
"teamId": {
|
"teamId": {
|
||||||
@@ -207,78 +214,54 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/auth/user/:userId": {
|
"/auth/user/{userId}": {
|
||||||
"put": {
|
"put": {
|
||||||
"tags": ["auth"],
|
"tags": ["auth"],
|
||||||
"description": "Change user informations",
|
"description": "Change user information",
|
||||||
"responses": {
|
"parameters": [
|
||||||
"200": {
|
{
|
||||||
"description": "OK",
|
"name": "userId",
|
||||||
"content": {
|
"in": "path",
|
||||||
"application/json": {
|
"required": true,
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/components/schemas/UserSuccessResponse"
|
"type": "string"
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"422": {
|
],
|
||||||
"description": "Unprocessable Content",
|
"requestBody": {
|
||||||
"content": {
|
"required": true,
|
||||||
"application/json": {
|
"content": {
|
||||||
"schema": {
|
"application/json": {
|
||||||
"$ref": "#/components/schemas/ErrorResponse"
|
"schema": {
|
||||||
}
|
"$ref": "#/components/schemas/UserUpdateRequest"
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"500": {
|
|
||||||
"description": "Internal Server Error",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/components/schemas/ErrorResponse"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"bearerAuth": []
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"delete": {
|
"delete": {
|
||||||
"tags": ["auth"],
|
"tags": ["auth"],
|
||||||
"description": "Delete user",
|
"description": "Delete user",
|
||||||
"responses": {
|
"parameters": [
|
||||||
"200": {
|
{
|
||||||
"description": "OK",
|
"name": "userId",
|
||||||
"content": {
|
"in": "path",
|
||||||
"application/json": {
|
"required": true,
|
||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/components/schemas/UserSuccessResponse"
|
"type": "string"
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"422": {
|
|
||||||
"description": "Unprocessable Content",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/components/schemas/ErrorResponse"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"500": {
|
|
||||||
"description": "Internal Server Error",
|
|
||||||
"content": {
|
|
||||||
"application/json": {
|
|
||||||
"schema": {
|
|
||||||
"$ref": "#/components/schemas/ErrorResponse"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
],
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"bearerAuth": []
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/auth/users/admin": {
|
"/auth/users/admin": {
|
||||||
@@ -587,12 +570,20 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"components": {
|
"components": {
|
||||||
|
"securitySchemes": {
|
||||||
|
"bearerAuth": {
|
||||||
|
"type": "http",
|
||||||
|
"scheme": "bearer",
|
||||||
|
"bearerFormat": "JWT"
|
||||||
|
}
|
||||||
|
},
|
||||||
"schemas": {
|
"schemas": {
|
||||||
"ErrorResponse": {
|
"ErrorResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"success": {
|
"success": {
|
||||||
"type": "boolean"
|
"type": "boolean",
|
||||||
|
"default": false
|
||||||
},
|
},
|
||||||
"msg": {
|
"msg": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@@ -613,6 +604,45 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"UserUpdateRequest": {
|
||||||
|
"type": "object",
|
||||||
|
"required": [
|
||||||
|
"firstName",
|
||||||
|
"lastName",
|
||||||
|
"email",
|
||||||
|
"password",
|
||||||
|
"role",
|
||||||
|
"teamId"
|
||||||
|
],
|
||||||
|
"properties": {
|
||||||
|
"firstName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"lastName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"password": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "password"
|
||||||
|
},
|
||||||
|
"newPassword": {
|
||||||
|
"type": "string",
|
||||||
|
"format": "password"
|
||||||
|
},
|
||||||
|
"profileImage": {
|
||||||
|
"type": "file",
|
||||||
|
"format": "file"
|
||||||
|
},
|
||||||
|
"role": {
|
||||||
|
"type": "array",
|
||||||
|
"enum": [["user"], ["admin"], ["superadmin"], ["Demo"]],
|
||||||
|
"default": ["superadmin"]
|
||||||
|
},
|
||||||
|
"deleteProfileImage": {
|
||||||
|
"type": "boolean"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"UserSuccessResponse": {
|
"UserSuccessResponse": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|||||||
Reference in new issue
Block a user